]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/commitdiff
Fix snprintf with non format
authorStephen Hemminger <stephen.hemminger@vyatta.com>
Wed, 9 Mar 2011 18:41:44 +0000 (10:41 -0800)
committerStephen Hemminger <shemminger@vyatta.com>
Tue, 12 Apr 2011 21:23:27 +0000 (14:23 -0700)
snprintf was being called with environment variable.
If variable had format string (like %s) then program would crash.

misc/rtacct.c

index a247dfd2ca4556c73a6ff6f1305052cb01b30b46..ab8fdbb806c8a42c21b5dfba8a92f610c57808af 100644 (file)
@@ -535,7 +535,7 @@ int main(int argc, char *argv[])
        }
 
        if (getenv("RTACCT_HISTORY"))
-               snprintf(hist_name, sizeof(hist_name), getenv("RTACCT_HISTORY"));
+               snprintf(hist_name, sizeof(hist_name), "%s", getenv("RTACCT_HISTORY"));
        else
                sprintf(hist_name, "/tmp/.rtacct.u%d", getuid());
 
@@ -563,7 +563,10 @@ int main(int argc, char *argv[])
                        exit(-1);
                }
                if (stb.st_size != sizeof(*hist_db))
-                       write(fd, kern_db, sizeof(*hist_db));
+                       if (write(fd, kern_db, sizeof(*hist_db)) < 0) {
+                               perror("rtacct: write history file");
+                               exit(-1);
+                       }
 
                hist_db = mmap(NULL, sizeof(*hist_db),
                               PROT_READ|PROT_WRITE,