From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Cc: Jeffrey Walton <noloader@gmail.com>
Subject: Re: undefined behaviour findings
Date: Sat, 09 Mar 2019 22:22:13 +0100 [thread overview]
Message-ID: <3705286.UUHsogPFhs@omega> (raw)
In-Reply-To: <1931657.LsgtlLSD0p@omega>
> 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 <bruno@clisp.org>
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;
prev parent reply other threads:[~2019-03-09 21:22 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-09 19:33 undefined behaviour findings Bruno Haible
2019-03-09 19:37 ` undefined behaviour findings in bitset Bruno Haible
2019-03-16 16:38 ` Akim Demaille
2019-03-16 16:42 ` Akim Demaille
2019-03-16 19:53 ` Bruno Haible
2019-03-17 7:39 ` Akim Demaille
2019-03-17 18:36 ` Akim Demaille
2019-03-17 18:56 ` Paul Eggert
2019-03-17 19:27 ` Bruno Haible
2019-03-18 8:16 ` Akim Demaille
2019-03-18 21:03 ` Bruno Haible
2019-03-19 6:07 ` Akim Demaille
2019-03-22 16:00 ` Akim Demaille
2019-03-23 18:54 ` Bruno Haible
2019-03-20 3:39 ` Bruno Haible
2019-03-20 17:04 ` Akim Demaille
2019-03-09 21:22 ` Bruno Haible [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3705286.UUHsogPFhs@omega \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
--cc=noloader@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).