summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Manning <cdhmanning@gmail.com>2010-11-30 13:16:13 +1300
committerCharles Manning <cdhmanning@gmail.com>2010-11-30 13:16:13 +1300
commit710ddf7a3cfce3e9d5f01afeecc41679a89b68f3 (patch)
tree3a6ef083dfb0db9037c440f66c595d30d11dcf1b
parent2d0acac2786382b29762a6042119c41ba3f2f92f (diff)
yaffs direct: Add some NULL pointer handling
Passing in NULL arguments causes -EFAULT. Signed-off-by: Charles Manning <cdhmanning@gmail.com>
-rw-r--r--direct/python/yaffs_error_converter.c2
-rw-r--r--direct/timothy_tests/quick_tests/test_yaffs_access_NULL.c2
-rw-r--r--direct/timothy_tests/quick_tests/test_yaffs_chmod_NULL.c2
-rw-r--r--direct/yaffsfs.c177
-rw-r--r--direct/yportenv.h4
5 files changed, 178 insertions, 9 deletions
diff --git a/direct/python/yaffs_error_converter.c b/direct/python/yaffs_error_converter.c
index 0d1601f..c7eb17c 100644
--- a/direct/python/yaffs_error_converter.c
+++ b/direct/python/yaffs_error_converter.c
@@ -38,7 +38,7 @@ static const struct error_entry error_list[] = {
{ EISDIR , "EISDIR"},
{ ENFILE, "ENFILE"},
{ EROFS, "EROFS"},
- { ELOOP, "ELOOP"},
+ { EFAULT, "EFAULT"},
{ 0, NULL }
};
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_access_NULL.c b/direct/timothy_tests/quick_tests/test_yaffs_access_NULL.c
index d9b2310..71e76d0 100644
--- a/direct/timothy_tests/quick_tests/test_yaffs_access_NULL.c
+++ b/direct/timothy_tests/quick_tests/test_yaffs_access_NULL.c
@@ -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);
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_chmod_NULL.c b/direct/timothy_tests/quick_tests/test_yaffs_chmod_NULL.c
index b0c1793..00da37b 100644
--- a/direct/timothy_tests/quick_tests/test_yaffs_chmod_NULL.c
+++ b/direct/timothy_tests/quick_tests/test_yaffs_chmod_NULL.c
@@ -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);
diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c
index 5194dd4..d6fd40e 100644
--- a/direct/yaffsfs.c
+++ b/direct/yaffsfs.c
@@ -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;
diff --git a/direct/yportenv.h b/direct/yportenv.h
index 7001150..543c129 100644
--- a/direct/yportenv.h
+++ b/direct/yportenv.h
@@ -187,6 +187,10 @@
#define ENOMEM 12
#endif
+#ifndef EFAULT
+#define EFAULT 14
+#endif
+
#ifndef EEXIST
#define EEXIST 17
#endif