Fix snprintf with non format

snprintf was being called with environment variable.
If variable had format string (like %s) then program would crash.
This commit is contained in:
Stephen Hemminger 2011-03-09 10:41:44 -08:00 committed by Stephen Hemminger
parent 38c867d2a8
commit 8988b02ee1
1 changed files with 5 additions and 2 deletions

View 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,