Module Name:    src
Committed By:   kamil
Date:           Thu Jul 26 00:31:13 UTC 2018

Modified Files:
        src/crypto/external/bsd/netpgp/dist/src/netpgpverify: sha2.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
    src/crypto/external/bsd/netpgp/dist/src/netpgpverify/sha2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/external/bsd/netpgp/dist/src/netpgpverify/sha2.c
diff -u src/crypto/external/bsd/netpgp/dist/src/netpgpverify/sha2.c:1.2 src/crypto/external/bsd/netpgp/dist/src/netpgpverify/sha2.c:1.3
--- src/crypto/external/bsd/netpgp/dist/src/netpgpverify/sha2.c:1.2	Tue Jun 14 20:47:08 2016
+++ src/crypto/external/bsd/netpgp/dist/src/netpgpverify/sha2.c	Thu Jul 26 00:31:13 2018
@@ -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 @@ htobe32(uint32_t x)
 	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 @@ htobe64(uint64_t x)
 	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);
 }

Reply via email to