From: Namhyung Kim Date: Thu, 16 Dec 2010 09:40:40 +0000 (+0900) Subject: mke2fs: add some error checks into PRS() X-Git-Tag: v1.42-WIP-0702~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ec68af7b61bf1ac88f20ae6ed6b1d45417195aa;p=thirdparty%2Fe2fsprogs.git mke2fs: add some error checks into PRS() Check return value of some functions and exit if unhandled error occurred. Signed-off-by: Namhyung Kim Signed-off-by: Theodore Ts'o --- diff --git a/misc/mke2fs.c b/misc/mke2fs.c index fd3a780a9..a43781615 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -1154,6 +1154,10 @@ static void PRS(int argc, char *argv[]) if (oldpath) pathlen += strlen(oldpath); newpath = malloc(pathlen); + if (!newpath) { + fprintf(stderr, _("Couldn't allocate memory for new PATH.\n")); + exit(1); + } strcpy(newpath, PATH_SET); /* Update our PATH to include /sbin */ @@ -1184,8 +1188,17 @@ static void PRS(int argc, char *argv[]) profile_set_syntax_err_cb(syntax_err_report); retval = profile_init(config_fn, &profile); if (retval == ENOENT) { - profile_init(default_files, &profile); - profile_set_default(profile, mke2fs_default_profile); + retval = profile_init(default_files, &profile); + if (retval) + goto profile_error; + retval = profile_set_default(profile, mke2fs_default_profile); + if (retval) + goto profile_error; + } else if (retval) { +profile_error: + fprintf(stderr, _("Couldn't init profile successfully" + " (error: %ld).\n"), retval); + exit(1); } setbuf(stdout, NULL);