yaffs direct: Add some NULL pointer handling
authorCharles Manning <cdhmanning@gmail.com>
Tue, 30 Nov 2010 00:16:13 +0000 (13:16 +1300)
committerCharles Manning <cdhmanning@gmail.com>
Tue, 30 Nov 2010 00:16:13 +0000 (13:16 +1300)
Passing in NULL arguments causes -EFAULT.

Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/python/yaffs_error_converter.c
direct/timothy_tests/quick_tests/test_yaffs_access_NULL.c
direct/timothy_tests/quick_tests/test_yaffs_chmod_NULL.c
direct/yaffsfs.c
direct/yportenv.h

index 0d1601f75923f05a3133b8aff8d7647d46fcf430..c7eb17ca8e904eb9130e6971391a1c59c3448667 100644 (file)
@@ -38,7 +38,7 @@ static const struct error_entry error_list[] = {
        { EISDIR , "EISDIR"},
        { ENFILE, "ENFILE"},
        { EROFS, "EROFS"},
-       { ELOOP, "ELOOP"},
+       { EFAULT, "EFAULT"},
        { 0, NULL }
 };
 
index d9b2310b1b8cc7812f015b60b0d11418edefd26b..71e76d033776d321df295099b198276ab8481168 100644 (file)
@@ -24,7 +24,7 @@ int test_yaffs_access_NULL(void)
        output= yaffs_access(NULL,0);
        if (output<0){
                error=yaffs_get_error();
-               if ( abs(error)== ELOOP){
+               if ( abs(error)== EFAULT){
                        return 1;
                } else {
                        print_message("error does not match expected error\n",2);
index b0c1793554c2bb124fcc3571e4d2af7032fdb857..00da37b9237e692029c49bb55bc1a8bb890c66ae 100644 (file)
@@ -22,7 +22,7 @@ int test_yaffs_chmod_NULL(void)
 
        if (output<0){
                error=yaffs_get_error();
-               if (abs(error)==EINVAL){
+               if (abs(error)==EFAULT){
                        return 1;
                } else {
                        print_message("different error than expected\n",2);
index 5194dd483f0c25e9568ce1913da20c9af1e86164..d6fd40e1bddafb401ffb1e7a0a256a4a41ef7233 100644 (file)
@@ -635,6 +635,10 @@ static struct yaffs_obj *yaffsfs_FindObject(struct yaffs_obj *relDir,
 }
 
 
+/*************************************************************************
+ *     Start of yaffsfs visible functions. 
+ *************************************************************************/
+
 int yaffs_dup(int fd)
 {
        int newHandle = -1;
@@ -649,17 +653,17 @@ int yaffs_dup(int fd)
        if(newHandle >= 0)
                newPtr = yaffsfs_GetHandlePointer(newHandle);
 
-       if(newPtr){
+       if(newPtr)
                *newPtr = *oldPtr;
-               return newHandle;
-       }
+
+       yaffsfs_Unlock();
 
        if(!oldPtr)
                yaffsfs_SetError(-EBADF);
-       else
+       else if (!newPtr)
                yaffsfs_SetError(-ENOMEM);
 
-       return -1;
+       return newHandle;
 
 }
 
@@ -687,6 +691,11 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
        int notDir = 0;
        int loop = 0;
 
+       if(!path) {
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -967,6 +976,11 @@ int yaffsfs_do_read(int fd, void *vbuf, unsigned int nbyte, int isPread, int off
        unsigned int maxRead;
        u8 *buf = (u8 *)vbuf;
 
+       if(!vbuf){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        yaffsfs_Lock();
        h = yaffsfs_GetHandlePointer(fd);
        obj = yaffsfs_GetHandleObject(fd);
@@ -1084,6 +1098,11 @@ int yaffsfs_do_write(int fd, const void *vbuf, unsigned int nbyte, int isPwrite,
        int nToWrite = 0;
        const u8 *buf = (const u8 *)vbuf;
 
+       if(!vbuf){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        yaffsfs_Lock();
        h = yaffsfs_GetHandlePointer(fd);
        obj = yaffsfs_GetHandleObject(fd);
@@ -1189,6 +1208,11 @@ int yaffs_truncate(const YCHAR *path,off_t new_size)
        int notDir = 0;
        int loop = 0;
 
+       if(!path){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -1300,6 +1324,11 @@ int yaffsfs_DoUnlink(const YCHAR *path,int isDirectory)
        int notDir = 0;
        int loop = 0;
 
+       if(!path){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -1363,6 +1392,11 @@ int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
 
        YCHAR *alt_newpath=NULL;
 
+       if(!oldPath || !newPath){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(newPath) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -1495,6 +1529,11 @@ static int yaffsfs_DoStatOrLStat(const YCHAR *path, struct yaffs_stat *buf,int d
        int notDir = 0;
        int loop = 0;
 
+       if(!path || !buf){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -1538,6 +1577,11 @@ int yaffs_fstat(int fd, struct yaffs_stat *buf)
 
        int retVal = -1;
 
+       if(!buf){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        yaffsfs_Lock();
        obj = yaffsfs_GetHandleObject(fd);
 
@@ -1556,7 +1600,8 @@ int yaffs_fstat(int fd, struct yaffs_stat *buf)
 /* xattrib functions */
 
 
-static int yaffs_do_setxattr(const YCHAR *path, const char *name, const void *data, int size, int flags, int follow)
+static int yaffs_do_setxattr(const YCHAR *path, const char *name,
+                       const void *data, int size, int flags, int follow)
 {
        struct yaffs_obj *obj;
        struct yaffs_obj *dir;
@@ -1565,6 +1610,11 @@ static int yaffs_do_setxattr(const YCHAR *path, const char *name, const void *da
 
        int retVal = -1;
 
+       if(!path || !name || !data){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -1615,6 +1665,11 @@ int yaffs_fsetxattr(int fd, const char *name, const void *data, int size, int fl
 
        int retVal = -1;
 
+       if(!name || !data){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        yaffsfs_Lock();
        obj = yaffsfs_GetHandleObject(fd);
 
@@ -1641,6 +1696,11 @@ static int yaffs_do_getxattr(const YCHAR *path, const char *name, void *data, in
        int notDir = 0;
        int loop = 0;
 
+       if(!path || !name || !data ){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -1689,6 +1749,11 @@ int yaffs_fgetxattr(int fd, const char *name, void *data, int size)
 
        int retVal = -1;
 
+       if(!name || !data ){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        yaffsfs_Lock();
        obj = yaffsfs_GetHandleObject(fd);
 
@@ -1715,6 +1780,11 @@ static int yaffs_do_listxattr(const YCHAR *path, char *data, int size, int follo
        int notDir = 0;
        int loop = 0;
 
+       if(!path || !data ){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -1763,6 +1833,11 @@ int yaffs_flistxattr(int fd, char *data, int size)
 
        int retVal = -1;
 
+       if(!data ){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        yaffsfs_Lock();
        obj = yaffsfs_GetHandleObject(fd);
 
@@ -1789,6 +1864,11 @@ static int yaffs_do_removexattr(const YCHAR *path, const char *name, int follow)
        int loop = 0;
        int retVal = -1;
 
+       if(!path || !name){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -1837,6 +1917,11 @@ int yaffs_fremovexattr(int fd, const char *name)
 
        int retVal = -1;
 
+       if(!name){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        yaffsfs_Lock();
        obj = yaffsfs_GetHandleObject(fd);
 
@@ -1960,6 +2045,11 @@ int yaffs_access(const YCHAR *path, int amode)
        int loop = 0;
        int retval = -1;
 
+       if(!path){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -2014,6 +2104,11 @@ int yaffs_chmod(const YCHAR *path, mode_t mode)
        int notDir = 0;
        int loop = 0;
 
+       if(!path){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -2082,6 +2177,11 @@ int yaffs_mkdir(const YCHAR *path, mode_t mode)
        int notDir = 0;
        int loop = 0;
 
+       if(!path){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -2130,6 +2230,11 @@ int yaffs_rmdir(const YCHAR *path)
        int result;
        YCHAR *alt_path;
 
+       if(!path){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -2162,6 +2267,11 @@ int yaffs_mount2(const YCHAR *path,int read_only)
        int result=YAFFS_FAIL;
        struct yaffs_dev *dev=NULL;
 
+       if(!path){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        T(YAFFS_TRACE_MOUNT,(TSTR("yaffs: Mounting %s" TENDSTR),path));
 
        if(yaffsfs_CheckPath(path) < 0){
@@ -2204,6 +2314,11 @@ int yaffs_sync(const YCHAR *path)
         struct yaffs_dev *dev=NULL;
         YCHAR *dummy;
 
+       if(!path){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -2237,6 +2352,11 @@ int yaffs_remount(const YCHAR *path, int force, int read_only)
        struct yaffs_dev *dev=NULL;
        yaffsfs_Handle *yh;
 
+       if(!path){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -2283,6 +2403,11 @@ int yaffs_unmount2(const YCHAR *path, int force)
         int retVal=-1;
        struct yaffs_dev *dev=NULL;
 
+       if(!path){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -2335,6 +2460,11 @@ loff_t yaffs_freespace(const YCHAR *path)
        struct yaffs_dev *dev=NULL;
        YCHAR *dummy;
 
+       if(!path){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -2385,6 +2515,11 @@ int yaffs_inodecount(const YCHAR *path)
        struct yaffs_dev *dev=NULL;
        YCHAR *dummy;
 
+       if(!path){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -2522,6 +2657,11 @@ yaffs_DIR *yaffs_opendir(const YCHAR *dirname)
        int notDir = 0;
        int loop = 0;
 
+       if(!dirname){
+               yaffsfs_SetError(-EFAULT);
+               return NULL;
+       }
+
        if(yaffsfs_CheckPath(dirname) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return NULL;
@@ -2615,6 +2755,11 @@ int yaffs_closedir(yaffs_DIR *dirp)
 {
        yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp;
 
+       if(!dsc){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
         yaffsfs_Lock();
         dsc->magic = 0;
         list_del(&dsc->others); /* unhook from list */
@@ -2636,6 +2781,11 @@ int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath)
        int notDir = 0;
        int loop = 0;
 
+       if(!oldpath || !newpath){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(newpath) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -2674,6 +2824,11 @@ int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz)
        int notDir = 0;
        int loop = 0;
 
+       if(!path || !buf){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        yaffsfs_Lock();
 
        obj = yaffsfs_FindObject(NULL,path,0,1, &dir,&notDir,&loop);
@@ -2710,6 +2865,11 @@ int yaffs_link(const YCHAR *oldpath, const YCHAR *linkpath)
        int lnkLoop = 0;
        YCHAR *newname;
 
+       if(!oldpath || !linkpath){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(linkpath) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
@@ -2774,6 +2934,11 @@ int yaffs_n_handles(const YCHAR *path)
 {
        struct yaffs_obj *obj;
 
+       if(!path){
+               yaffsfs_SetError(-EFAULT);
+               return -1;
+       }
+
        if(yaffsfs_CheckPath(path) < 0){
                yaffsfs_SetError(-ENAMETOOLONG);
                return -1;
index 700115007a26bf8b2762eb18772292dfdc7d8cba..543c129735b2c7c99b81f6a526b868e79d870958 100644 (file)
 #define ENOMEM 12
 #endif
 
+#ifndef EFAULT
+#define EFAULT 14
+#endif
+
 #ifndef EEXIST
 #define EEXIST 17
 #endif