From: Brian Behlendorf Date: Mon, 19 Mar 2007 12:36:45 +0000 (-0400) Subject: [COVERITY] Fix segfault bug if the profile directory is empty X-Git-Tag: E2FSPROGS-1_40~112 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12f91959993f0d2882592427c94f35f32436e03a;p=thirdparty%2Fe2fsprogs.git [COVERITY] Fix segfault bug if the profile directory is empty Coverity ID: 5: Forward NULL Signed-off-by: Brian Behlendorf Signed-off-by: "Theodore Ts'o" --- diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 5abc2e6cb..dd0524d49 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,3 +1,9 @@ +2007-03-19 Theodore Tso + + * 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 * unix.c (PRS, main): Use the new {add,remove}_error_table comerr diff --git a/e2fsck/profile.c b/e2fsck/profile.c index e7768a223..8030680bf 100644 --- a/e2fsck/profile.c +++ b/e2fsck/profile.c @@ -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)