chiark / gitweb /
Import gnupg2_2.1.18-8~deb9u1.debian.tar.bz2
[gnupg2.git] / patches / 0058-common-Avoid-undefined-behavior.patch
1 From: Justus Winter <justus@g10code.com>
2 Date: Thu, 30 Mar 2017 15:44:35 +0200
3 Subject: common: Avoid undefined behavior.
4
5 * common/iobuf.c (iobuf_read_line): Do not consider 'length' if
6 'buffer' is NULL.
7
8 Signed-off-by: Justus Winter <justus@g10code.com>
9 (cherry picked from commit 214fa9012296d796b78f1a3106d656639cf50aef)
10 ---
11  common/iobuf.c | 2 +-
12  1 file changed, 1 insertion(+), 1 deletion(-)
13
14 diff --git a/common/iobuf.c b/common/iobuf.c
15 index d346027..b8baf7f 100644
16 --- a/common/iobuf.c
17 +++ b/common/iobuf.c
18 @@ -2552,7 +2552,7 @@ iobuf_read_line (iobuf_t a, byte ** addr_of_buffer,
19       NUL character in the buffer.  This requires at least 2 bytes.  We
20       don't complicate the code by handling the stupid corner case, but
21       simply assert that it can't happen.  */
22 -  assert (length >= 2 || maxlen >= 2);
23 +  assert (!buffer || length >= 2 || maxlen >= 2);
24  
25    if (!buffer || length <= 1)
26      /* must allocate a new buffer */