aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2020-03-04 12:24:49 +0000
committerPádraig Brady <P@draigBrady.com>2020-03-04 12:38:27 +0000
commit0ea65e29dc346e9fe39db663b2ed43d7981ed266 (patch)
tree6b7434f8e8ba79abdf81e7beceebf47f122ab353
parenttests: avoid a false failure on OpenIndiana 11 (diff)
downloadcoreutils-0ea65e29dc346e9fe39db663b2ed43d7981ed266.tar.gz
coreutils-0ea65e29dc346e9fe39db663b2ed43d7981ed266.zip
basenc: avoid undefined behaviour in z85 processing
* src/basenc.c (z85_decode_ctx_init): Ensure we're working with unsigned, as otherwise ubsan triggers with: src/basenc.c:767:18: runtime error: signed integer overflow: 43 * 52200625 cannot be represented in type 'int' (z85_encode): Likewise to avoid the usban error: src/basenc.c:630:26: runtime error: left shift of 134 by 24 places cannot be represented in type 'int'
-rw-r--r--src/basenc.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/basenc.c b/src/basenc.c
index 9fb2ab955..13c37f904 100644
--- a/src/basenc.c
+++ b/src/basenc.c
@@ -627,7 +627,10 @@ z85_encode (const char *restrict in, size_t inlen,
/* Got a quad, encode it */
if (i == 4)
{
- val = (quad[0] << 24) + (quad[1] << 16) + (quad[2] << 8) + quad[3];
+ val = ((uint32_t) quad[0] << 24)
+ + ((uint32_t) quad[1] << 16)
+ + ((uint32_t) quad[2] << 8)
+ + quad[3];
for (int j = 4; j>=0; --j)
{
@@ -665,7 +668,7 @@ z85_decode_ctx_init (struct base_decode_context *ctx)
# define Z85_HI_CTX_TO_32BIT_VAL(ctx) \
- ((ctx)->ctx.z85.octets[0] * 85 * 85 * 85 * 85 )
+ ((uint32_t)(ctx)->ctx.z85.octets[0] * 85 * 85 * 85 * 85 )
/*
0 - 9: 0 1 2 3 4 5 6 7 8 9