[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: undefined behaviour findings
From: |
Bruno Haible |
Subject: |
Re: undefined behaviour findings |
Date: |
Sat, 09 Mar 2019 22:22:13 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-141-generic; KDE/5.18.0; x86_64; ; ) |
> lib/des.c:552:3: runtime error: left shift of 255 by 24 places cannot be
> represented in type 'int'
> lib/des.c:437:3: runtime error: left shift of 242 by 24 places cannot be
> represented in type 'int'
> lib/des.c:625:3: runtime error: left shift of 254 by 24 places cannot be
> represented in type 'int'
This one is fixed by this commit:
2019-03-09 Bruno Haible <address@hidden>
crypto/des: Fix undefined behaviour.
* lib/des.c (READ_64BIT_DATA): Cast bytes to 'unsigned int', to avoid
shift operations on 'int'.
diff --git a/lib/des.c b/lib/des.c
index f357192..ba174f7 100644
--- a/lib/des.c
+++ b/lib/des.c
@@ -407,11 +407,17 @@ gl_des_is_weak_key (const char * key)
* Macros to convert 8 bytes from/to 32bit words.
*/
#define READ_64BIT_DATA(data, left, right) \
- left = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; \
- right = (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7];
+ left = ((uint32_t) data[0] << 24) \
+ | ((uint32_t) data[1] << 16) \
+ | ((uint32_t) data[2] << 8) \
+ | (uint32_t) data[3]; \
+ right = ((uint32_t) data[4] << 24) \
+ | ((uint32_t) data[5] << 16) \
+ | ((uint32_t) data[6] << 8) \
+ | (uint32_t) data[7];
#define WRITE_64BIT_DATA(data, left, right) \
- data[0] = (left >> 24) &0xff; data[1] = (left >> 16) &0xff; \
+ data[0] = (left >> 24) &0xff; data[1] = (left >> 16) &0xff; \
data[2] = (left >> 8) &0xff; data[3] = left &0xff; \
data[4] = (right >> 24) &0xff; data[5] = (right >> 16) &0xff; \
data[6] = (right >> 8) &0xff; data[7] = right &0xff;
- Re: undefined behaviour findings in bitset, (continued)
- Re: undefined behaviour findings in bitset, Akim Demaille, 2019/03/17
- Re: undefined behaviour findings in bitset, Paul Eggert, 2019/03/17
- Re: undefined behaviour findings in bitset, Bruno Haible, 2019/03/17
- Re: undefined behaviour findings in bitset, Akim Demaille, 2019/03/18
- Re: undefined behaviour findings in bitset, Bruno Haible, 2019/03/18
- Re: undefined behaviour findings in bitset, Akim Demaille, 2019/03/19
- Re: undefined behaviour findings in bitset, Akim Demaille, 2019/03/22
- Re: undefined behaviour findings in bitset, Bruno Haible, 2019/03/23
- Re: undefined behaviour findings in bitset, Bruno Haible, 2019/03/19
- Re: undefined behaviour findings in bitset, Akim Demaille, 2019/03/20
Re: undefined behaviour findings,
Bruno Haible <=