From: Justus Winter Date: Thu, 30 Mar 2017 13:44:35 +0000 (+0200) Subject: common: Avoid undefined behavior. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=0d2bab1fb95601b821ff0ab79960ec50716c689a;p=gnupg2.git common: Avoid undefined behavior. * common/iobuf.c (iobuf_read_line): Do not consider 'length' if 'buffer' is NULL. Signed-off-by: Justus Winter (cherry picked from commit 214fa9012296d796b78f1a3106d656639cf50aef) Gbp-Pq: Name 0058-common-Avoid-undefined-behavior.patch --- diff --git a/common/iobuf.c b/common/iobuf.c index d346027..b8baf7f 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -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 */