Whamcloud - gitweb
Prevent i_dtime from being mistaken for an inode number post-2038 wraparound
[tools/e2fsprogs.git] / misc / fsck.c
index de5ae25..64d0e7c 100644 (file)
@@ -59,6 +59,7 @@
 #endif
 
 #include "../version.h"
+#include "support/devname.h"
 #include "support/nls-enable.h"
 #include "fsck.h"
 #include "blkid/blkid.h"
@@ -297,7 +298,7 @@ static int parse_fstab_line(char *line, struct fs_info **ret_fs)
        parse_escape(freq);
        parse_escape(passno);
 
-       dev = blkid_get_devname(cache, device, NULL);
+       dev = get_devname(cache, device, NULL);
        if (dev)
                device = dev;
 
@@ -408,8 +409,12 @@ static char *find_fsck(char *type)
   tpl = (strncmp(type, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s");
 
   for(s = strtok(p, ":"); s; s = strtok(NULL, ":")) {
-       sprintf(prog, tpl, s, type);
-       if (stat(prog, &st) == 0) break;
+         int len = snprintf(prog, sizeof(prog), tpl, s, type);
+
+         if ((len < 0) || (len >= (int) sizeof(prog)))
+                 continue;
+         if (stat(prog, &st) == 0)
+                 break;
   }
   free(p);
   return(s ? prog : NULL);
@@ -435,17 +440,20 @@ static int progress_active(NOARGS)
 static int execute(const char *type, const char *device, const char *mntpt,
                   int interactive)
 {
-       char *s, *argv[80], prog[80];
-       int  argc, i;
+       char *s, *argv[80], prog[256];
+       int  argc, i, len;
        struct fsck_instance *inst, *p;
        pid_t   pid;
 
+       len = snprintf(prog, sizeof(prog), "fsck.%s", type);
+       if ((len < 0) || (len >= (int) sizeof(prog)))
+               return EINVAL;
+
        inst = malloc(sizeof(struct fsck_instance));
        if (!inst)
                return ENOMEM;
        memset(inst, 0, sizeof(struct fsck_instance));
 
-       sprintf(prog, "fsck.%s", type);
        argv[0] = string_copy(prog);
        argc = 1;
 
@@ -539,6 +547,8 @@ static int kill_all(int signum)
        for (inst = instance_list; inst; inst = inst->next) {
                if (inst->flags & FLAG_DONE)
                        continue;
+               if (inst->pid <= 0)
+                       continue;
                kill(inst->pid, signum);
                n++;
        }
@@ -796,6 +806,7 @@ static void compile_fs_type(char *fs_type, struct fs_type_compile *cmp)
                        if ((negate && !cmp->negate) ||
                            (!negate && cmp->negate)) {
                                fputs(_(fs_type_syntax_error), stderr);
+                               free(list);
                                exit(EXIT_USAGE);
                        }
                }
@@ -1121,7 +1132,7 @@ static void PRS(int argc, char *argv[])
                                        progname);
                                exit(EXIT_ERROR);
                        }
-                       dev = blkid_get_devname(cache, arg, NULL);
+                       dev = get_devname(cache, arg, NULL);
                        if (!dev && strchr(arg, '=')) {
                                /*
                                 * Check to see if we failed because