From: Andreas Schneider Date: Thu, 22 Nov 2018 12:33:11 +0000 (+0100) Subject: s3:lib: Fix undefined behavior in tdb_pack() X-Git-Tag: tdb-1.3.17~527 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86592673fbd3399b35832ca138681b06cb007b2c;p=thirdparty%2Fsamba.git s3:lib: Fix undefined behavior in tdb_pack() util_tdb.c:98:5: runtime error: null pointer passed as argument 2, which is declared to never be null This means the second argument of memcpy() can't be NULL. Signed-off-by: Andreas Schneider Reviewed-by: Gary Lockyer --- diff --git a/source3/lib/util_tdb.c b/source3/lib/util_tdb.c index 4f2450c5773..8a5d831225e 100644 --- a/source3/lib/util_tdb.c +++ b/source3/lib/util_tdb.c @@ -76,14 +76,11 @@ static size_t tdb_pack_va(uint8_t *buf, int bufsize, const char *fmt, va_list ap SIVAL(buf, 0, d); break; case 'P': /* null-terminated string */ - s = va_arg(ap,char *); - w = strlen(s); - len = w + 1; - if (bufsize && bufsize >= len) - memcpy(buf, s, len); - break; case 'f': /* null-terminated string */ s = va_arg(ap,char *); + if (s == NULL) { + smb_panic("Invalid argument"); + } w = strlen(s); len = w + 1; if (bufsize && bufsize >= len) @@ -95,7 +92,9 @@ static size_t tdb_pack_va(uint8_t *buf, int bufsize, const char *fmt, va_list ap len = 4+i; if (bufsize && bufsize >= len) { SIVAL(buf, 0, i); - memcpy(buf+4, s, i); + if (s != NULL) { + memcpy(buf+4, s, i); + } } break; default: