From b56d4d33be32c21ed99aa0547256b490e2a103dd Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 10 Jul 2010 14:20:05 +0200 Subject: [PATCH] Protect bsnprintf against NULL pointer --- bacula/src/lib/bsnprintf.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bacula/src/lib/bsnprintf.c b/bacula/src/lib/bsnprintf.c index dcd9923251..e55b749b79 100644 --- a/bacula/src/lib/bsnprintf.c +++ b/bacula/src/lib/bsnprintf.c @@ -348,10 +348,16 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args) case 's': if (cflags != DP_C_WCHAR) { strvalue = va_arg(args, char *); + if (!strvalue) { + strvalue = (char *)""; + } currlen = fmtstr(buffer, currlen, maxlen, strvalue, flags, min, max); } else { /* %ls means to edit wide characters */ wstrvalue = va_arg(args, wchar_t *); + if (!wstrvalue) { + wstrvalue = (wchar_t *)L""; + } currlen = fmtwstr(buffer, currlen, maxlen, wstrvalue, flags, min, max); } break; @@ -437,9 +443,6 @@ static int32_t fmtstr(char *buffer, int32_t currlen, int32_t maxlen, } else if (max < 0) { max = maxlen; } - if (!value) { - value = ""; - } strln = strlen(value); if (strln > max) { strln = max; /* truncate to max */ @@ -481,9 +484,6 @@ static int32_t fmtwstr(char *buffer, int32_t currlen, int32_t maxlen, } else if (max < 0) { max = maxlen; } - if (!value) { - value = L""; - } strln = wcslen(value); if (strln > max) { strln = max; /* truncate to max */ @@ -752,6 +752,7 @@ static int32_t fmtfp(char *buffer, int32_t currlen, int32_t maxlen, if (!result) { r_length = 0; + dummy[0] = 0; result = dummy; } else { r_length = strlen(result); -- 2.39.5