From: Stephen Hemminger Date: Sat, 26 Dec 2009 18:21:13 +0000 (-0800) Subject: Fix warning about sprintf() and NSTAT_HIST X-Git-Tag: v2.6.31~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=896ebd6c705651abe0a6eedc9c6158a5db6e38d3;p=thirdparty%2Fiproute2.git Fix warning about sprintf() and NSTAT_HIST The environment variable could contain format characters, causing problems. Better to just use it directly. --- diff --git a/misc/nstat.c b/misc/nstat.c index 2e44ed253..4f73c628d 100644 --- a/misc/nstat.c +++ b/misc/nstat.c @@ -445,7 +445,7 @@ static void usage(void) int main(int argc, char *argv[]) { - char hist_name[128]; + char *hist_name; struct sockaddr_un sun; FILE *hist_fp = NULL; int ch; @@ -526,10 +526,10 @@ int main(int argc, char *argv[]) patterns = argv; npatterns = argc; - if (getenv("NSTAT_HISTORY")) - snprintf(hist_name, sizeof(hist_name), getenv("NSTAT_HISTORY")); - else + if ((hist_name = getenv("NSTAT_HISTORY")) == NULL) { + hist_name = malloc(128); sprintf(hist_name, "/tmp/.nstat.u%d", getuid()); + } if (reset_history) unlink(hist_name);