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/0a70b37a9002
branches: trunk
changeset: 991689:0a70b37a9002
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 cc60282393d5 -r 0a70b37a9002 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