[COVERITY] Fix segfault bug if the profile directory is empty

Coverity ID: 5: Forward NULL

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
bitmap-optimize
Brian Behlendorf 2007-03-19 08:36:45 -04:00 committed by Theodore Ts'o
parent e066150a70
commit 12f9195999
2 changed files with 12 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2007-03-19 Theodore Tso <tytso@mit.edu>
* profile.c (profile_init, get_dirlist): Fix bug where if a
profile directory is completely empty, the profile library
would segfault.
2006-12-22 Theodore Tso <tytso@mit.edu>
* unix.c (PRS, main): Use the new {add,remove}_error_table comerr

View File

@ -279,8 +279,10 @@ static errcode_t get_dirlist(const char *dirname, char***ret_array)
}
array[num++] = fn;
}
qsort(array, num, sizeof(char *), compstr);
array[num++] = 0;
if (array) {
qsort(array, num, sizeof(char *), compstr);
array[num++] = 0;
}
*ret_array = array;
closedir(dir);
return 0;
@ -311,6 +313,8 @@ profile_init(const char **files, profile_t *ret_profile)
for (fs = files; !PROFILE_LAST_FILESPEC(*fs); fs++) {
retval = get_dirlist(*fs, &array);
if (retval == 0) {
if (!array)
continue;
for (cpp = array; (cp = *cpp); cpp++) {
retval = profile_open_file(cp, &new_file);
if (retval == EACCES)