Whamcloud - gitweb
mke2fs: add some error checks into PRS()
authorNamhyung Kim <namhyung@gmail.com>
Thu, 16 Dec 2010 09:40:40 +0000 (18:40 +0900)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 22 Dec 2010 01:31:26 +0000 (20:31 -0500)
Check return value of some functions and exit if unhandled error occurred.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/mke2fs.c

index fd3a780..a437816 100644 (file)
@@ -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);