diff options
author | Jeremy Allison <jra@samba.org> | 2010-09-10 11:56:26 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2010-09-10 11:56:26 -0700 |
commit | e8509589287ea04c6290dd127d3ef0c3e0b3f49d (patch) | |
tree | 473fdc4173437e0d14ac53ab2c5161e027a2abc6 /source3/modules | |
parent | 55598c4746f51f4a607c7b11e43ad56dcee22d87 (diff) | |
download | samba-e8509589287ea04c6290dd127d3ef0c3e0b3f49d.tar.gz samba-e8509589287ea04c6290dd127d3ef0c3e0b3f49d.tar.bz2 samba-e8509589287ea04c6290dd127d3ef0c3e0b3f49d.zip |
Check all SMB_MALLOC returns correctly. Found by Andreas Moroder <andreas.moroder@gmx.net>.
Jeremy
Diffstat (limited to 'source3/modules')
-rw-r--r-- | source3/modules/vfs_dirsort.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/source3/modules/vfs_dirsort.c b/source3/modules/vfs_dirsort.c index d96aca0cb1..4869bc05a0 100644 --- a/source3/modules/vfs_dirsort.c +++ b/source3/modules/vfs_dirsort.c @@ -43,14 +43,15 @@ static void free_dirsort_privates(void **datap) { return; } -static void open_and_sort_dir (vfs_handle_struct *handle) +static bool open_and_sort_dir (vfs_handle_struct *handle) { SMB_STRUCT_DIRENT *dp; struct stat dir_stat; long current_pos; struct dirsort_privates *data = NULL; - SMB_VFS_HANDLE_GET_DATA(handle, data, struct dirsort_privates, return); + SMB_VFS_HANDLE_GET_DATA(handle, data, struct dirsort_privates, + return false); data->number_of_entries = 0; @@ -71,6 +72,9 @@ static void open_and_sort_dir (vfs_handle_struct *handle) SAFE_FREE(data->directory_list); /* destroy previous cache if needed */ data->directory_list = (SMB_STRUCT_DIRENT *)SMB_MALLOC( data->number_of_entries * sizeof(SMB_STRUCT_DIRENT)); + if (!data->directory_list) { + return false; + } current_pos = data->pos; data->pos = 0; while ((dp = SMB_VFS_NEXT_READDIR(handle, data->source_directory, @@ -81,6 +85,7 @@ static void open_and_sort_dir (vfs_handle_struct *handle) /* Sort the directory entries by name */ data->pos = current_pos; TYPESAFE_QSORT(data->directory_list, data->number_of_entries, compare_dirent); + return true; } static SMB_STRUCT_DIR *dirsort_opendir(vfs_handle_struct *handle, @@ -93,6 +98,10 @@ static SMB_STRUCT_DIR *dirsort_opendir(vfs_handle_struct *handle, data = (struct dirsort_privates *)SMB_MALLOC( sizeof(struct dirsort_privates)); + if (!data) { + return NULL; + } + data->directory_list = NULL; data->pos = 0; @@ -105,7 +114,10 @@ static SMB_STRUCT_DIR *dirsort_opendir(vfs_handle_struct *handle, SMB_VFS_HANDLE_SET_DATA(handle, data, free_dirsort_privates, struct dirsort_privates, return NULL); - open_and_sort_dir(handle); + if (!open_and_sort_dir(handle)) { + SMB_VFS_NEXT_CLOSEDIR(handle,data->source_directory); + return NULL; + } return data->source_directory; } |