From 9ec68af7b61bf1ac88f20ae6ed6b1d45417195aa Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Thu, 16 Dec 2010 18:40:40 +0900 Subject: [PATCH] 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 --- misc/mke2fs.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/misc/mke2fs.c b/misc/mke2fs.c index fd3a780..a437816 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); -- 1.8.3.1