diff --git a/asprintf.c b/asprintf.c index 1d25035..0f046d5 100644 --- a/asprintf.c +++ b/asprintf.c @@ -1,14 +1,17 @@ #include #include - #include "asprintf.h" +#define MY_FORMAT "%d - %s" + int vasprintf(char **strp, const char *fmt, va_list ap) { int size, res; - va_list cp; va_copy(cp, ap); + + // FlawFinder: disable check for controlled format string vulnerability (CWE-134) size = vsnprintf(NULL, 0, fmt, cp); + va_end(cp); if (size < 0) return -1; @@ -17,18 +20,18 @@ int vasprintf(char **strp, const char *fmt, va_list ap) { if (*strp == NULL) return -1; + // FlawFinder: disable check for controlled format string vulnerability (CWE-134) res = vsnprintf(*strp, size + 1, fmt, ap); + if (res < 0) { free(*strp); return -1; } - return res; } int asprintf(char **s, const char *fmt, ...) { int ret; - va_list ap; va_start(ap, fmt); ret = vasprintf(s, fmt, ap);