From: Kern Sibbald Date: Sat, 10 Jul 2010 12:20:05 +0000 (+0200) Subject: Protect bsnprintf against NULL pointer X-Git-Tag: Release-5.2.1~1224 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b1ec56fe13ffa1e750c219a1ff1311f7352ccaae;p=bacula%2Fbacula Protect bsnprintf against NULL pointer --- 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);