chiark / gitweb /
common: Avoid undefined behavior.
authorJustus Winter <justus@g10code.com>
Thu, 30 Mar 2017 13:44:35 +0000 (15:44 +0200)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Mon, 18 Sep 2017 20:41:12 +0000 (21:41 +0100)
* common/iobuf.c (iobuf_read_line): Do not consider 'length' if
'buffer' is NULL.

Signed-off-by: Justus Winter <justus@g10code.com>
(cherry picked from commit 214fa9012296d796b78f1a3106d656639cf50aef)

Gbp-Pq: Name 0058-common-Avoid-undefined-behavior.patch

common/iobuf.c

index d346027e40a61dcfaadc518cfd6e39d5fc9b84bf..b8baf7ff7d5ff8beb8786ad142f85435e2fcccaa 100644 (file)
@@ -2552,7 +2552,7 @@ iobuf_read_line (iobuf_t a, byte ** addr_of_buffer,
      NUL character in the buffer.  This requires at least 2 bytes.  We
      don't complicate the code by handling the stupid corner case, but
      simply assert that it can't happen.  */
-  assert (length >= 2 || maxlen >= 2);
+  assert (!buffer || length >= 2 || maxlen >= 2);
 
   if (!buffer || length <= 1)
     /* must allocate a new buffer */