Fix compiler warning.
authorTim Potter <tpot@samba.org>
Thu, 6 May 1999 23:52:00 +0000 (23:52 +0000)
committerTim Potter <tpot@samba.org>
Thu, 6 May 1999 23:52:00 +0000 (23:52 +0000)
Added checks to panic if VFS functions are passed NULL pointers.  This
may expose some bugs that have been lurking about.  Checks can be
easily removed later.
(This used to be commit c33c6330e3a2025f2fda0234635dfdd3acd04890)

source3/smbd/vfs-wrap.c

index 2e25a2540b042dfccb33deec9e50b2479148092a..3493c2317890abe6c6dbe267995359af1b0aa90e 100644 (file)
 
 #include "includes.h"
 
 
 #include "includes.h"
 
+/* Check for NULL pointer parameters in vfswrap_* functions */
+
+#define VFS_CHECK_NULL
+
 /* We don't want to have NULL function pointers lying around.  Someone
    is sure to try and execute them.  These stubs are used to prevent
    this possibility. */
 /* We don't want to have NULL function pointers lying around.  Someone
    is sure to try and execute them.  These stubs are used to prevent
    this possibility. */
 int vfswrap_dummy_connect(struct vfs_connection_struct *conn, char *service,
                          char *user)
 {
 int vfswrap_dummy_connect(struct vfs_connection_struct *conn, char *service,
                          char *user)
 {
-    /* Do nothing */
+    return 0;    /* Return >= 0 for success */
 }
 
 void vfswrap_dummy_disconnect(void)
 {
 }
 
 void vfswrap_dummy_disconnect(void)
 {
-    /* Do nothing a bit more */
 }
 
 /* Disk operations */
 }
 
 /* Disk operations */
@@ -43,6 +46,14 @@ SMB_BIG_UINT vfswrap_disk_free(char *path, SMB_BIG_UINT *bsize,
 {
     SMB_BIG_UINT result;
 
 {
     SMB_BIG_UINT result;
 
+#ifdef VFS_CHECK_NULL
+    if ((path == NULL) || (bsize == NULL) || (dfree == NULL) ||
+       (dsize == NULL)) {
+       
+       smb_panic("NULL pointer passed to vfswrap_disk_free() function\n");
+    }
+#endif
+
     result = sys_disk_free(path, bsize, dfree, dsize);
     return result;
 }
     result = sys_disk_free(path, bsize, dfree, dsize);
     return result;
 }
@@ -53,6 +64,12 @@ DIR *vfswrap_opendir(char *fname)
 {
     DIR *result;
 
 {
     DIR *result;
 
+#ifdef VFS_CHECK_NULL
+    if (fname == NULL) {
+       smb_panic("NULL pointer passed to vfswrap_opendir()\n");
+    }
+#endif
+
     result = opendir(fname);
     return result;
 }
     result = opendir(fname);
     return result;
 }
@@ -61,6 +78,12 @@ struct dirent *vfswrap_readdir(DIR *dirp)
 {
     struct dirent *result;
 
 {
     struct dirent *result;
 
+#ifdef VFS_CHECK_NULL
+    if (dirp == NULL) {
+       smb_panic("NULL pointer passed to vfswrap_readdir()\n");
+    }
+#endif
+
     result = readdir(dirp);
     return result;
 }
     result = readdir(dirp);
     return result;
 }
@@ -69,6 +92,12 @@ int vfswrap_mkdir(char *path, mode_t mode)
 {
     int result;
 
 {
     int result;
 
+#ifdef VFS_CHECK_NULL
+    if (path == NULL) {
+       smb_panic("NULL pointer passed to vfswrap_mkdir()\n");
+    }
+#endif
+
     result = mkdir(path, mode);
     return result;
 }
     result = mkdir(path, mode);
     return result;
 }
@@ -77,6 +106,12 @@ int vfswrap_rmdir(char *path)
 {
     int result;
 
 {
     int result;
 
+#ifdef VFS_CHECK_NULL
+    if (path == NULL) {
+       smb_panic("NULL pointer passed to vfswrap_rmdir()\n");
+    }
+#endif
+
     result = rmdir(path);
     return result;
 }
     result = rmdir(path);
     return result;
 }
@@ -84,7 +119,13 @@ int vfswrap_rmdir(char *path)
 int vfswrap_closedir(DIR *dirp)
 {
     int result;
 int vfswrap_closedir(DIR *dirp)
 {
     int result;
-    
+
+#ifdef VFS_CHECK_NULL
+    if (dirp == NULL) {
+       smb_panic("NULL pointer passed to vfswrap_closedir()\n");
+    }
+#endif
+
     result = closedir(dirp);
     return result;
 }
     result = closedir(dirp);
     return result;
 }
@@ -95,6 +136,12 @@ int vfswrap_open(char *fname, int flags, mode_t mode)
 {
     int result;
 
 {
     int result;
 
+#ifdef VFS_CHECK_NULL
+    if (fname == NULL) {
+       smb_panic("NULL pointer passed to vfswrap_open()\n");
+    }
+#endif
+
     result = sys_open(fname, flags, mode);
     return result;
 }
     result = sys_open(fname, flags, mode);
     return result;
 }
@@ -111,6 +158,12 @@ ssize_t vfswrap_read(int fd, char *data, size_t n)
 {
     ssize_t result;
 
 {
     ssize_t result;
 
+#ifdef VFS_CHECK_NULL
+    if (data == NULL) {
+       smb_panic("NULL pointer passed to vfswrap_read()\n");
+    }
+#endif
+
     result = read(fd, data, n);
     return result;
 }
     result = read(fd, data, n);
     return result;
 }
@@ -119,6 +172,12 @@ ssize_t vfswrap_write(int fd, char *data, size_t n)
 {
     ssize_t result;
 
 {
     ssize_t result;
 
+#ifdef VFS_CHECK_NULL
+    if (data == NULL) {
+       smb_panic("NULL pointer passed to vfswrap_write()\n");
+    }
+#endif
+
     result = write(fd, data, n);
     return result;
 }
     result = write(fd, data, n);
     return result;
 }
@@ -135,6 +194,12 @@ int vfswrap_rename(char *old, char *new)
 {
     int result;
 
 {
     int result;
 
+#ifdef VFS_CHECK_NULL
+    if ((old == NULL) || (new == NULL)) {
+       smb_panic("NULL pointer passed to vfswrap_rename()\n");
+    }
+#endif
+
     result = rename(old, new);
     return result;
 }
     result = rename(old, new);
     return result;
 }
@@ -148,6 +213,12 @@ int vfswrap_stat(char *fname, SMB_STRUCT_STAT *sbuf)
 {
     int result;
 
 {
     int result;
 
+#ifdef VFS_CHECK_NULL
+    if ((fname == NULL) || (sbuf == NULL)) {
+       smb_panic("NULL pointer passed to vfswrap_stat()\n");
+    }
+#endif
+
     result = sys_stat(fname, sbuf);
     return result;
 }
     result = sys_stat(fname, sbuf);
     return result;
 }
@@ -156,6 +227,12 @@ int vfswrap_fstat(int fd, SMB_STRUCT_STAT *sbuf)
 {
     int result;
 
 {
     int result;
 
+#ifdef VFS_CHECK_NULL
+    if (sbuf == NULL) {
+       smb_panic("NULL pointer passed to vfswrap_fstat()\n");
+    }
+#endif
+
     result = sys_fstat(fd, sbuf);
     return result;
 }
     result = sys_fstat(fd, sbuf);
     return result;
 }
@@ -165,6 +242,12 @@ int vfswrap_lstat(char *path,
 {
     int result;
 
 {
     int result;
 
+#ifdef VFS_CHECK_NULL
+    if ((path == NULL) || (sbuf == NULL)) {
+       smb_panic("NULL pointer passed to vfswrap_lstat()\n");
+    }
+#endif
+
     result = sys_lstat(path, sbuf);
     return result;
 }
     result = sys_lstat(path, sbuf);
     return result;
 }
@@ -182,6 +265,12 @@ int vfswrap_unlink(char *path)
 {
     int result;
 
 {
     int result;
 
+#ifdef VFS_CHECK_NULL
+    if (path == NULL) {
+       smb_panic("NULL pointer passed to vfswrap_unlink()\n");
+    }
+#endif
+
     result = unlink(path);
     return result;
 }
     result = unlink(path);
     return result;
 }
@@ -190,6 +279,12 @@ int vfswrap_chmod(char *path, mode_t mode)
 {
     int result;
 
 {
     int result;
 
+#ifdef VFS_CHECK_NULL
+    if (path == NULL) {
+       smb_panic("NULL pointer passed to vfswrap_chmod()\n");
+    }
+#endif
+
     result = chmod(path, mode);
     return result;
 }
     result = chmod(path, mode);
     return result;
 }
@@ -198,6 +293,12 @@ int vfswrap_utime(char *path, struct utimbuf *times)
 {
     int result;
 
 {
     int result;
 
+#ifdef VFS_CHECK_NULL
+    if ((path == NULL) || (times == NULL)) {
+       smb_panic("NULL pointer passed to vfswrap_utime()\n");
+    }
+#endif
+
     result = utime(path, times);
     return result;
 }
     result = utime(path, times);
     return result;
 }