s3/printing: cppcheck avoid 'nullPointerArithmetic:' error
authorNoel Power <noel.power@suse.com>
Tue, 21 May 2019 11:56:06 +0000 (12:56 +0100)
committerNoel Power <npower@samba.org>
Wed, 29 May 2019 10:10:23 +0000 (10:10 +0000)
source3/printing/notify.c:94: error: nullPointerArithmetic: Pointer addition with NULL pointer. <--[cppcheck]
/home/samba/samba-pidl/source3/printing/notify.c:96: error: nullPointerArithmetic: Pointer addition with NULL pointer. <--[cppcheck]
/home/samba/samba-pidl/source3/printing/notify.c:103: error: nullPointerArithmetic: Pointer addition with NULL pointer. <--[cppcheck]

flatten_message function depends on behaviour of tdb_pack which will
return the bytes that would be written (without actually writing to the
buffer) if the bufsize passed is <=0. What we need to avoid here is the
default modification of buf (when it is initially NULL)

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

index d2c5f72fff574f00bccd1120bdaa8c399f18a0d1..56747272394460962a0ada18a04f1c8a8585ca4c 100644 (file)
@@ -91,19 +91,23 @@ again:
 
        /* Pack header */
 
-       len += tdb_pack(buf + len, buflen - len, "f", msg->printer);
+       len += tdb_pack(buf ? buf + len : NULL,
+                       buf ? buflen - len : 0, "f", msg->printer);
 
-       len += tdb_pack(buf + len, buflen - len, "ddddddd",
+       len += tdb_pack(buf ? buf + len : NULL,
+                       buf ? buflen - len : 0, "ddddddd",
                        (uint32_t)q->tv.tv_sec, (uint32_t)q->tv.tv_usec,
                        msg->type, msg->field, msg->id, msg->len, msg->flags);
 
        /* Pack data */
 
        if (msg->len == 0)
-               len += tdb_pack(buf + len, buflen - len, "dd",
+               len += tdb_pack(buf ? buf + len : NULL,
+                               buf ? buflen - len : 0, "dd",
                                msg->notify.value[0], msg->notify.value[1]);
        else
-               len += tdb_pack(buf + len, buflen - len, "B",
+               len += tdb_pack(buf ? buf + len : NULL,
+                               buf ? buflen - len : 0, "B",
                                msg->len, msg->notify.data);
 
        if (buflen != len) {