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 bit shift operations



details:   https://anonhg.NetBSD.org/src/rev/573378fab560
branches:  trunk
changeset: 745064:573378fab560
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sat Feb 22 10:22:32 2020 +0000

description:
Avoid undefined behavior in bit shift operations

crypt.c:839:40, left shift of negative value -1197182952
crypt.c:840:40, left shift of negative value -264997776

diffstat:

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

diffs (29 lines):

diff -r 9fddaf87524e -r 573378fab560 lib/libcrypt/crypt.c
--- a/lib/libcrypt/crypt.c      Sat Feb 22 10:05:12 2020 +0000
+++ b/lib/libcrypt/crypt.c      Sat Feb 22 10:22:32 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: crypt.c,v 1.36 2019/10/21 02:36:48 jhigh Exp $ */
+/*     $NetBSD: crypt.c,v 1.37 2020/02/22 10:22:32 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.36 2019/10/21 02:36:48 jhigh Exp $");
+__RCSID("$NetBSD: crypt.c,v 1.37 2020/02/22 10:22:32 kamil Exp $");
 #endif
 #endif /* not lint */
 
@@ -836,8 +836,8 @@
        }
 
        /* store the encrypted (or decrypted) result */
-       L0 = ((L0 >> 3) & 0x0f0f0f0fL) | ((L1 << 1) & 0xf0f0f0f0L);
-       L1 = ((R0 >> 3) & 0x0f0f0f0fL) | ((R1 << 1) & 0xf0f0f0f0L);
+       L0 = (((uint32_t)L0 >> 3) & 0x0f0f0f0fL) | (((uint32_t)L1 << 1) & 0xf0f0f0f0L);
+       L1 = (((uint32_t)R0 >> 3) & 0x0f0f0f0fL) | (((uint32_t)R1 << 1) & 0xf0f0f0f0L);
        STORE(L,L0,L1,B);
        PERM6464(L,L0,L1,B.b, (C_block *)CF6464);
 #if defined(MUST_ALIGN)



Home | Main Index | Thread Index | Old Index