Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/crypto/external/bsd/netpgp/dist/src/netpgpverify Avoid undef...



details:   https://anonhg.NetBSD.org/src/rev/47be1704f37f
branches:  trunk
changeset: 834071:47be1704f37f
user:      kamil <kamil%NetBSD.org@localhost>
date:      Thu Jul 26 00:31:13 2018 +0000

description:
Avoid undefined behavior in netpgpverify/sha2.c

Do not change the signedness bit with a left shift operation.
Cast to unsigned integer to prevent this.

sha2.c:79:16, left shift of 154 by 24 places cannot be represented in type 'int'

Detected with micro-UBSan in the user mode.

diffstat:

 crypto/external/bsd/netpgp/dist/src/netpgpverify/sha2.c |  8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diffs (29 lines):

diff -r 9b34b0e1bcc0 -r 47be1704f37f crypto/external/bsd/netpgp/dist/src/netpgpverify/sha2.c
--- a/crypto/external/bsd/netpgp/dist/src/netpgpverify/sha2.c   Thu Jul 26 00:26:45 2018 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/netpgpverify/sha2.c   Thu Jul 26 00:31:13 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sha2.c,v 1.2 2016/06/14 20:47:08 agc Exp $ */
+/* $NetBSD: sha2.c,v 1.3 2018/07/26 00:31:13 kamil Exp $ */
 /*     $KAME: sha2.c,v 1.9 2003/07/20 00:28:38 itojun Exp $    */
 
 /*
@@ -76,7 +76,7 @@
        uint8_t p[4];
        memcpy(p, &x, 4);
 
-       return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+       return (((uint32_t)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
 }
 
 static uint64_t
@@ -86,8 +86,8 @@
        uint32_t u, v;
        memcpy(p, &x, 8);
 
-       u = ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
-       v = ((p[4] << 24) | (p[5] << 16) | (p[6] << 8) | p[7]);
+       u = (((uint32_t)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+       v = (((uint32_t)p[4] << 24) | (p[5] << 16) | (p[6] << 8) | p[7]);
 
        return ((((uint64_t)u) << 32) | v);
 }



Home | Main Index | Thread Index | Old Index