s3/lib: don't write to buffer (which might be NULL) if bufsize <=0
authorNoel Power <noel.power@suse.com>
Tue, 21 May 2019 13:08:15 +0000 (13:08 +0000)
committerNoel Power <npower@samba.org>
Wed, 29 May 2019 10:10:23 +0000 (10:10 +0000)
commit5477b83db28c67743e25a638c93bc4117a8a7ced
tree727bc546b272bfbd311863350cd2fc32831fdb11
parent75afaeb749991925f17517ce50a96178d32d7922
s3/lib: don't write to buffer (which might be NULL) if bufsize <=0

Some code depends that tdb_pack[va] will return the bytes it would
write to 'buf' if the bufsize passed in is <=0, writing to the
buffer is protected by with lines like
   if (bufsize && bufsize >= len) {
      /* write to 'buf' */
   }

however in these instances the local pointer to the buffer is still
modified
   buf += len;

It's quite probable if bufsize == 0 that buf itself is NULL,
in this case we should protect against performing pointer arithmetic.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/lib/util_tdb.c