From owner-svn-src-stable@freebsd.org Mon Jul 16 00:23:10 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C06A71031B08; Mon, 16 Jul 2018 00:23:10 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6D876770B2; Mon, 16 Jul 2018 00:23:10 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 349981534C; Mon, 16 Jul 2018 00:23:10 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6G0N9lI002822; Mon, 16 Jul 2018 00:23:09 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6G0N91L002821; Mon, 16 Jul 2018 00:23:09 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201807160023.w6G0N91L002821@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Mon, 16 Jul 2018 00:23:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r336323 - stable/11/usr.bin/gzip X-SVN-Group: stable-11 X-SVN-Commit-Author: pfg X-SVN-Commit-Paths: stable/11/usr.bin/gzip X-SVN-Commit-Revision: 336323 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Jul 2018 00:23:11 -0000 Author: pfg Date: Mon Jul 16 00:23:09 2018 New Revision: 336323 URL: https://svnweb.freebsd.org/changeset/base/336323 Log: MFC r336113: gzip: fix for undefined behavior. Unportable left shift reported with MKSANITIZER=yes USE_SANITIZER=undefined: # progress -zf ./games.tgz tar -xp -C "./" -f - /public/src.git/usr.bin/gzip/gzip.c:2126:33: runtime error: left shift of 251 by 24 places cannot be represented in type 'int' 100% |****************************************************************************************************************| 44500 KiB 119.69 MiB/s 00:00 ETA Refactor the following code into something that is more clear and fix signed integer shift, by casting all buf[] elements to (unsigned int): unsigned char buf[8]; uint32_t usize; [...] else { usize = buf[4] | buf[5] << 8 | buf[6] << 16 | buf[7] << 24; [...] New version: usize = buf[4]; usize |= (unsigned int)buf[5] << 8; usize |= (unsigned int)buf[6] << 16; usize |= (unsigned int)buf[7] << 24; Only the "<< 24" part needs explicit cast, but for consistency make the integer promotion explicit and clear to a code reader. Sponsored by Obtained from: NetBSD (CVS rev. 1.113) Modified: stable/11/usr.bin/gzip/gzip.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.bin/gzip/gzip.c ============================================================================== --- stable/11/usr.bin/gzip/gzip.c Mon Jul 16 00:20:18 2018 (r336322) +++ stable/11/usr.bin/gzip/gzip.c Mon Jul 16 00:23:09 2018 (r336323) @@ -1,4 +1,4 @@ -/* $NetBSD: gzip.c,v 1.112 2017/08/23 13:04:17 christos Exp $ */ +/* $NetBSD: gzip.c,v 1.113 2018/06/12 00:42:17 kamil Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-NetBSD @@ -2170,12 +2170,16 @@ print_list(int fd, off_t out, const char *outfile, tim maybe_warnx("read of uncompressed size"); else { - usize = buf[4] | buf[5] << 8 | - buf[6] << 16 | buf[7] << 24; + usize = buf[4]; + usize |= (unsigned int)buf[5] << 8; + usize |= (unsigned int)buf[6] << 16; + usize |= (unsigned int)buf[7] << 24; in = (off_t)usize; #ifndef SMALL - crc = buf[0] | buf[1] << 8 | - buf[2] << 16 | buf[3] << 24; + crc = buf[0]; + crc |= (unsigned int)buf[1] << 8; + crc |= (unsigned int)buf[2] << 16; + crc |= (unsigned int)buf[3] << 24; #endif } }