Source-Changes-HG archive

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

[src/trunk]: src/lib/libcrypt Avoid undefined behavior in left shift



details:   https://anonhg.NetBSD.org/src/rev/8c9318caa72a
branches:  trunk
changeset: 1007525:8c9318caa72a
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sat Feb 22 10:29:17 2020 +0000

description:
Avoid undefined behavior in left shift

crypt.c:772:11, left shift of 1363235140 by 1 places cannot be represented
in type 'int32_t' (aka 'int')

diffstat:

 lib/libcrypt/crypt.c |  8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diffs (30 lines):

diff -r 592b90159584 -r 8c9318caa72a lib/libcrypt/crypt.c
--- a/lib/libcrypt/crypt.c      Sat Feb 22 10:22:32 2020 +0000
+++ b/lib/libcrypt/crypt.c      Sat Feb 22 10:29:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: crypt.c,v 1.37 2020/02/22 10:22:32 kamil Exp $ */
+/*     $NetBSD: crypt.c,v 1.38 2020/02/22 10:29:17 kamil Exp $ */
 
 /*
  * Copyright (c) 1989, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)crypt.c    8.1.1.1 (Berkeley) 8/18/93";
 #else
-__RCSID("$NetBSD: crypt.c,v 1.37 2020/02/22 10:22:32 kamil Exp $");
+__RCSID("$NetBSD: crypt.c,v 1.38 2020/02/22 10:29:17 kamil Exp $");
 #endif
 #endif /* not lint */
 
@@ -769,9 +769,9 @@
        LOADREG(R,R0,R1,L,L0,L1);
        L0 &= 0x55555555L;
        L1 &= 0x55555555L;
-       L0 = (L0 << 1) | L1;    /* L0 is the even-numbered input bits */
+       L0 = ((uint32_t)L0 << 1) | L1;  /* L0 is the even-numbered input bits */
        R0 &= 0xaaaaaaaaL;
-       R1 = (R1 >> 1) & 0x55555555L;
+       R1 = ((uint32_t)R1 >> 1) & 0x55555555L;
        L1 = R0 | R1;           /* L1 is the odd-numbered input bits */
        STORE(L,L0,L1,B);
        PERM3264(L,L0,L1,B.b,  (C_block *)IE3264);      /* even bits */



Home | Main Index | Thread Index | Old Index