worked around the buffer overrun in smprintf()
Ali H. Fardan raiz@firemail.cc
Sun, 28 Aug 2016 18:19:53 +0300
1 files changed,
5 insertions(+),
4 deletions(-)
jump to
M
slstatus.c
→
slstatus.c
@@ -78,14 +78,15 @@
static char * smprintf(const char *fmt, ...) { - /* FIXME: This code should have - bound checks, it is vulnerable to - buffer overflows */ va_list ap; + char tmp[120]; char *ret = NULL; va_start(ap, fmt); - if (vasprintf(&ret, fmt, ap) < 0) + vsnprintf(tmp, sizeof(tmp)-1, fmt, ap); + tmp[strlen(tmp)+1] = '\0'; + + if (asprintf(&ret, "%s", tmp) < 0) return NULL; va_end(ap);