Merge in yaffsfs.c changes
authorCharles Manning <cdhmanning@gmail.com>
Thu, 14 Jun 2012 04:04:23 +0000 (16:04 +1200)
committerCharles Manning <cdhmanning@gmail.com>
Tue, 19 Jun 2012 02:34:58 +0000 (14:34 +1200)
Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/basic-test/yaffs_osglue.c
direct/timothy_tests/quick_tests/quick_tests.h
direct/yaffs_osglue.h
direct/yaffsfs.c

index 4a149e277588dd9bc4387bcfe02c57eb3a495186..4c2e442033f8cc03be314a90295798f70148613f 100644 (file)
@@ -37,6 +37,13 @@ int yaffsfs_GetLastError(void)
        return yaffsfs_lastError;
 }
 
        return yaffsfs_lastError;
 }
 
+int yaffsfs_CheckMemRegion(const void *addr, size_t size, int writeable)
+{
+       if(!addr)
+               return -1;
+       return 0;
+}
+
 
 #ifdef CONFIG_YAFFS_USE_PTHREADS
 #include <pthread.h>
 
 #ifdef CONFIG_YAFFS_USE_PTHREADS
 #include <pthread.h>
index ed0d336dcbac30a19d8b4786c521f38a0256b011..99675634fe4bf5d9efee96e6f666de833dad0a7e 100644 (file)
@@ -329,7 +329,7 @@ test_template test_list[]={
 
        {test_yaffs_write,test_yaffs_write_clean,"test_yaffs_write"},
        {test_yaffs_write_EBADF,test_yaffs_write_EBADF_clean,"test_yaffs_write_EBADF"},
 
        {test_yaffs_write,test_yaffs_write_clean,"test_yaffs_write"},
        {test_yaffs_write_EBADF,test_yaffs_write_EBADF_clean,"test_yaffs_write_EBADF"},
-       {test_yaffs_write_big_file,test_yaffs_write_big_file_clean,"test_yaffs_write_big_file"},
+//     {test_yaffs_write_big_file,test_yaffs_write_big_file_clean,"test_yaffs_write_big_file"},
        {test_yaffs_write_EROFS,test_yaffs_write_EROFS_clean,"test_yaffs_write_EROFS"},
 
        {test_yaffs_read,test_yaffs_read_clean,"test_yaffs_read"},
        {test_yaffs_write_EROFS,test_yaffs_write_EROFS_clean,"test_yaffs_write_EROFS"},
 
        {test_yaffs_read,test_yaffs_read_clean,"test_yaffs_read"},
index bb008f9a8ced71c5113a3901aa9494b5d17dcd9c..7fe0bf4fc294f4e5f6c0baae3fe4faeecc9fda03 100644 (file)
@@ -35,6 +35,8 @@ void yaffsfs_SetError(int err);
 void *yaffsfs_malloc(size_t size);
 void yaffsfs_free(void *ptr);
 
 void *yaffsfs_malloc(size_t size);
 void yaffsfs_free(void *ptr);
 
+int yaffsfs_CheckMemRegion(const void *addr, size_t size, int writeable);
+
 void yaffsfs_OSInitialisation(void);
 
 
 void yaffsfs_OSInitialisation(void);
 
 
index d208e25df0b4fdf002bae73547caddcbc7892107..829881f356959232a0495de54664995bf7173587 100644 (file)
@@ -793,7 +793,7 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
        int notDir = 0;
        int loop = 0;
 
        int notDir = 0;
        int loop = 0;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0)< 0) {
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -1077,7 +1077,7 @@ static int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte,
        Y_LOFF_T maxRead;
        u8 *buf = (u8 *) vbuf;
 
        Y_LOFF_T maxRead;
        u8 *buf = (u8 *) vbuf;
 
-       if (!vbuf) {
+       if(yaffsfs_CheckMemRegion(vbuf, nbyte, 1) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -1199,7 +1199,7 @@ static int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte,
        int nToWrite = 0;
        const u8 *buf = (const u8 *)vbuf;
 
        int nToWrite = 0;
        const u8 *buf = (const u8 *)vbuf;
 
-       if (!vbuf) {
+       if(yaffsfs_CheckMemRegion(vbuf, nbyte, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -1310,7 +1310,7 @@ int yaffs_truncate(const YCHAR *path, Y_LOFF_T new_size)
        int notDir = 0;
        int loop = 0;
 
        int notDir = 0;
        int loop = 0;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -1425,7 +1425,7 @@ static int yaffsfs_DoUnlink(const YCHAR *path, int isDirectory)
        int notDir = 0;
        int loop = 0;
 
        int notDir = 0;
        int loop = 0;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -1494,7 +1494,8 @@ int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
 
        YCHAR *alt_newpath = NULL;
 
 
        YCHAR *alt_newpath = NULL;
 
-       if (!oldPath || !newPath) {
+       if(yaffsfs_CheckMemRegion(oldPath, 0, 0) < 0 || 
+          yaffsfs_CheckMemRegion(newPath, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -1633,7 +1634,8 @@ static int yaffsfs_DoStatOrLStat(const YCHAR *path,
        int notDir = 0;
        int loop = 0;
 
        int notDir = 0;
        int loop = 0;
 
-       if (!path || !buf) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
+          yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -1681,7 +1683,7 @@ int yaffs_fstat(int fd, struct yaffs_stat *buf)
 
        int retVal = -1;
 
 
        int retVal = -1;
 
-       if (!buf) {
+       if(yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -1802,7 +1804,9 @@ static int yaffs_do_setxattr(const YCHAR *path, const char *name,
 
        int retVal = -1;
 
 
        int retVal = -1;
 
-       if (!path || !name || !data) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
+          yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
+          yaffsfs_CheckMemRegion(data, size, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -1858,7 +1862,8 @@ int yaffs_fsetxattr(int fd, const char *name,
 
        int retVal = -1;
 
 
        int retVal = -1;
 
-       if (!name || !data) {
+       if(yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
+          yaffsfs_CheckMemRegion(data, size, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -1890,7 +1895,9 @@ static int yaffs_do_getxattr(const YCHAR *path, const char *name,
        int notDir = 0;
        int loop = 0;
 
        int notDir = 0;
        int loop = 0;
 
-       if (!path || !name || !data) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
+          yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
+          yaffsfs_CheckMemRegion(data, size, 1) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -1942,7 +1949,8 @@ int yaffs_fgetxattr(int fd, const char *name, void *data, int size)
 
        int retVal = -1;
 
 
        int retVal = -1;
 
-       if (!name || !data) {
+       if(yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
+          yaffsfs_CheckMemRegion(data, size, 1) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -1974,7 +1982,8 @@ static int yaffs_do_listxattr(const YCHAR *path, char *data,
        int notDir = 0;
        int loop = 0;
 
        int notDir = 0;
        int loop = 0;
 
-       if (!path || !data) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
+          yaffsfs_CheckMemRegion(data, size, 1) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2027,7 +2036,7 @@ int yaffs_flistxattr(int fd, char *data, int size)
 
        int retVal = -1;
 
 
        int retVal = -1;
 
-       if (!data) {
+       if(yaffsfs_CheckMemRegion(data, size, 1) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2059,7 +2068,8 @@ static int yaffs_do_removexattr(const YCHAR *path, const char *name,
        int loop = 0;
        int retVal = -1;
 
        int loop = 0;
        int retVal = -1;
 
-       if (!path || !name) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
+          yaffsfs_CheckMemRegion(name, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2112,7 +2122,7 @@ int yaffs_fremovexattr(int fd, const char *name)
 
        int retVal = -1;
 
 
        int retVal = -1;
 
-       if (!name) {
+       if(yaffsfs_CheckMemRegion(name, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2236,7 +2246,7 @@ int yaffs_access(const YCHAR *path, int amode)
        int loop = 0;
        int retval = -1;
 
        int loop = 0;
        int retval = -1;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2294,7 +2304,7 @@ int yaffs_chmod(const YCHAR *path, mode_t mode)
        int notDir = 0;
        int loop = 0;
 
        int notDir = 0;
        int loop = 0;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2366,7 +2376,7 @@ int yaffs_mkdir(const YCHAR *path, mode_t mode)
        int notDir = 0;
        int loop = 0;
 
        int notDir = 0;
        int loop = 0;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2420,7 +2430,7 @@ int yaffs_rmdir(const YCHAR *path)
        int result;
        YCHAR *alt_path;
 
        int result;
        YCHAR *alt_path;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2457,7 +2467,7 @@ int yaffs_mount_common(const YCHAR *path, int read_only, int skip_checkpt)
        int result = YAFFS_FAIL;
        struct yaffs_dev *dev = NULL;
 
        int result = YAFFS_FAIL;
        struct yaffs_dev *dev = NULL;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2516,7 +2526,7 @@ int yaffs_sync(const YCHAR *path)
        struct yaffs_dev *dev = NULL;
        YCHAR *dummy;
 
        struct yaffs_dev *dev = NULL;
        YCHAR *dummy;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2565,7 +2575,7 @@ int yaffs_remount(const YCHAR *path, int force, int read_only)
        int retVal = -1;
        struct yaffs_dev *dev = NULL;
 
        int retVal = -1;
        struct yaffs_dev *dev = NULL;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2605,7 +2615,7 @@ int yaffs_unmount2(const YCHAR *path, int force)
        int retVal = -1;
        struct yaffs_dev *dev = NULL;
 
        int retVal = -1;
        struct yaffs_dev *dev = NULL;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2654,7 +2664,7 @@ Y_LOFF_T yaffs_freespace(const YCHAR *path)
        struct yaffs_dev *dev = NULL;
        YCHAR *dummy;
 
        struct yaffs_dev *dev = NULL;
        YCHAR *dummy;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2683,7 +2693,7 @@ Y_LOFF_T yaffs_totalspace(const YCHAR *path)
        struct yaffs_dev *dev = NULL;
        YCHAR *dummy;
 
        struct yaffs_dev *dev = NULL;
        YCHAR *dummy;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2714,7 +2724,7 @@ int yaffs_inodecount(const YCHAR *path)
        struct yaffs_dev *dev = NULL;
        YCHAR *dummy;
 
        struct yaffs_dev *dev = NULL;
        YCHAR *dummy;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2866,7 +2876,7 @@ yaffs_DIR *yaffs_opendir(const YCHAR *dirname)
        int notDir = 0;
        int loop = 0;
 
        int notDir = 0;
        int loop = 0;
 
-       if (!dirname) {
+       if(yaffsfs_CheckMemRegion(dirname, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return NULL;
        }
                yaffsfs_SetError(-EFAULT);
                return NULL;
        }
@@ -2960,6 +2970,9 @@ void yaffs_rewinddir(yaffs_DIR *dirp)
 
        dsc = (struct yaffsfs_DirSearchContxt *) dirp;
 
 
        dsc = (struct yaffsfs_DirSearchContxt *) dirp;
 
+       if(yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0)
+               return;
+
        yaffsfs_Lock();
 
        yaffsfs_SetDirRewound(dsc);
        yaffsfs_Lock();
 
        yaffsfs_SetDirRewound(dsc);
@@ -2973,7 +2986,7 @@ int yaffs_closedir(yaffs_DIR *dirp)
 
        dsc = (struct yaffsfs_DirSearchContxt *) dirp;
 
 
        dsc = (struct yaffsfs_DirSearchContxt *) dirp;
 
-       if (!dsc) {
+       if(yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -2997,7 +3010,8 @@ int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath)
        int notDir = 0;
        int loop = 0;
 
        int notDir = 0;
        int loop = 0;
 
-       if (!oldpath || !newpath) {
+       if(yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 ||
+          yaffsfs_CheckMemRegion(newpath, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -3044,7 +3058,8 @@ int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz)
        int notDir = 0;
        int loop = 0;
 
        int notDir = 0;
        int loop = 0;
 
-       if (!path || !buf) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
+          yaffsfs_CheckMemRegion(buf, bufsiz, 1) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -3085,7 +3100,8 @@ int yaffs_link(const YCHAR *oldpath, const YCHAR *linkpath)
        int lnkLoop = 0;
        YCHAR *newname;
 
        int lnkLoop = 0;
        YCHAR *newname;
 
-       if (!oldpath || !linkpath) {
+       if(yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 ||
+          yaffsfs_CheckMemRegion(linkpath, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
@@ -3157,7 +3173,7 @@ int yaffs_n_handles(const YCHAR *path)
 {
        struct yaffs_obj *obj;
 
 {
        struct yaffs_obj *obj;
 
-       if (!path) {
+       if(yaffsfs_CheckMemRegion(path, 0, 0) < 0){
                yaffsfs_SetError(-EFAULT);
                return -1;
        }
                yaffsfs_SetError(-EFAULT);
                return -1;
        }