From: nekral-guest Date: Mon, 27 Apr 2009 20:07:59 +0000 (+0000) Subject: * libmisc/env.c: Added assertions on the snprintf results. X-Git-Tag: 4.1.4~66 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=988f7334ad8af267d00aa03443e58391e3d67f1c;p=shadow * libmisc/env.c: Added assertions on the snprintf results. --- diff --git a/ChangeLog b/ChangeLog index 0b9aa6bb..f4ea8dbf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-04-27 Nicolas François + + * libmisc/env.c: Added assertions on the snprintf results. + 2009-04-27 Nicolas François * NEWS, configure.in: Added configure option --enable-utmpx, diff --git a/libmisc/env.c b/libmisc/env.c index e2e42986..b46ca10c 100644 --- a/libmisc/env.c +++ b/libmisc/env.c @@ -34,6 +34,7 @@ #ident "$Id$" +#include #include #include #include @@ -92,8 +93,11 @@ void addenv (const char *string, /*@null@*/const char *value) size_t n; if (NULL != value) { - newstring = xmalloc (strlen (string) + strlen (value) + 2); - sprintf (newstring, "%s=%s", string, value); + size_t len = strlen (string) + strlen (value) + 2; + int wlen; + newstring = xmalloc (len); + wlen = snprintf (newstring, len, "%s=%s", string, value); + assert (wlen == (int) len -1); } else { newstring = xstrdup (string); } @@ -187,7 +191,10 @@ void set_env (int argc, char *const *argv) cp = strchr (*argv, '='); if (NULL == cp) { - snprintf (variable, sizeof variable, "L%d", noname++); + int wlen; + wlen = snprintf (variable, sizeof variable, "L%d", noname); + assert (wlen < (int) sizeof(variable)); + noname++; addenv (variable, *argv); } else { const char **p;