From: Pascal Cuoq <cuoq@trust-in-soft.com>
To: "musl@lists.openwall.com" <musl@lists.openwall.com>
Subject: Re: [musl] [PATCH] fix undefined behavior from large shifts
Date: Sat, 4 Jun 2022 18:04:15 +0000 [thread overview]
Message-ID: <E439568A-3754-4446-ABA2-DB7CC17B8491@trust-in-soft.com> (raw)
In-Reply-To: <20220604172550.uf7vboamzar4etk3@gen2.localdomain>
> On 4 Jun 2022, at 19:26, NRK <nrk@disroot.org> wrote:
>
> + uint32_t nw = (uint32_t)n[0]<<24 | (uint32_t)n[1]<<16 | n[2]<<8;
> + uint32_t hw = (uint32_t)h[0]<<24 | (uint32_t)h[1]<<16 | h[2]<<8;
If it were a goal to support 16-bit ints in musl, then your patch would still have UB by shifting a 1 into the sign bit with {h,n}[2]<<8, which in C is a form of signed arithmetic overflow (the C++ standard makes a special case for this situation but the C standard doesn't).
However, I do not think it is a goal to support narrower that 32-bit ints in musl, and the original code is free of UB in these conditions.
next prev parent reply other threads:[~2022-06-04 18:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-04 17:25 NRK
2022-06-04 18:04 ` Pascal Cuoq [this message]
2022-06-04 18:16 ` Rich Felker
2022-06-04 18:55 ` NRK
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E439568A-3754-4446-ABA2-DB7CC17B8491@trust-in-soft.com \
--to=cuoq@trust-in-soft.com \
--cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).