From 12f91959993f0d2882592427c94f35f32436e03a Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 19 Mar 2007 08:36:45 -0400 Subject: [PATCH] [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" --- e2fsck/ChangeLog | 6 ++++++ e2fsck/profile.c | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 5abc2e6c..dd0524d4 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 e7768a22..8030680b 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)