From: Stephen Hemminger Date: Wed, 9 Mar 2011 18:41:44 +0000 (-0800) Subject: Fix snprintf with non format X-Git-Tag: v2.6.39~13^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8988b02ee1d04fdf07b913454b8d4e7b5e3092e5;p=thirdparty%2Fiproute2.git Fix snprintf with non format snprintf was being called with environment variable. If variable had format string (like %s) then program would crash. --- diff --git a/misc/rtacct.c b/misc/rtacct.c index a247dfd2c..ab8fdbb80 100644 --- a/misc/rtacct.c +++ b/misc/rtacct.c @@ -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,