Cast the unsigned char to unsigned int before shifting left
authorTomas Mraz <tmraz@fedoraproject.org>
Tue, 19 May 2020 08:51:19 +0000 (10:51 +0200)
committerTomas Mraz <tmraz@fedoraproject.org>
Wed, 20 May 2020 15:31:43 +0000 (17:31 +0200)
This is needed to avoid automatic promotion to signed int.

Fixes #11853

[extended tests]

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/11857)

crypto/pem/pvkfmt.c

index e2f570288086e0f58e5b34d4ade6075dd450e7ce..6d85a8a4e19d4ddea9c44c2ada1edf5ec54418d3 100644 (file)
@@ -36,10 +36,10 @@ static unsigned int read_ledword(const unsigned char **in)
 {
     const unsigned char *p = *in;
     unsigned int ret;
-    ret = *p++;
-    ret |= (*p++ << 8);
-    ret |= (*p++ << 16);
-    ret |= (*p++ << 24);
+    ret = (unsigned int)*p++;
+    ret |= (unsigned int)*p++ << 8;
+    ret |= (unsigned int)*p++ << 16;
+    ret |= (unsigned int)*p++ << 24;
     *in = p;
     return ret;
 }