From owner-svn-src-stable@freebsd.org Tue Aug 21 01:17:29 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 723C11083A88; Tue, 21 Aug 2018 01:17:29 +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 1E2468BEE0; Tue, 21 Aug 2018 01:17:29 +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 F0C081D235; Tue, 21 Aug 2018 01:17:28 +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 w7L1HSk7056985; Tue, 21 Aug 2018 01:17:28 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7L1HSSu056983; Tue, 21 Aug 2018 01:17:28 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201808210117.w7L1HSSu056983@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Tue, 21 Aug 2018 01:17:28 +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: r338124 - in stable/11/lib/libc: gen inet X-SVN-Group: stable-11 X-SVN-Commit-Author: pfg X-SVN-Commit-Paths: in stable/11/lib/libc: gen inet X-SVN-Commit-Revision: 338124 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: Tue, 21 Aug 2018 01:17:29 -0000 Author: pfg Date: Tue Aug 21 01:17:28 2018 New Revision: 338124 URL: https://svnweb.freebsd.org/changeset/base/338124 Log: MFC r337422: libc: fix cases of undefined behavior. These were found by the Undefined Behavior GsoC project at NetBSD: Avoid undefined behavior in ftok(3) Do not change the signedness bit with a left shift operation. Cast to unsigned integer to prevent this. ftok.c:56:10, left shift of 123456789 by 24 places cannot be represented in type 'int' ftok.c:56:10, left shift of 4160 by 24 places cannot be represented in type 'int' Avoid undefined behavior in an inet_addr.c Do not change the signedness bit with a left shift operation. Cast to unsigned integer to prevent this. inet_addr.c:218:20, left shift of 131 by 24 places cannot be represented in type 'int' Detected with micro-UBSan in the user mode. Obtained from: NetBSD Modified: stable/11/lib/libc/gen/ftok.c stable/11/lib/libc/inet/inet_addr.c Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libc/gen/ftok.c ============================================================================== --- stable/11/lib/libc/gen/ftok.c Tue Aug 21 00:37:48 2018 (r338123) +++ stable/11/lib/libc/gen/ftok.c Tue Aug 21 01:17:28 2018 (r338124) @@ -40,5 +40,6 @@ ftok(const char *path, int id) if (stat(path, &st) < 0) return (key_t)-1; - return (key_t) (id << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff)); + return ((key_t)((unsigned int)id << 24 | (st.st_dev & 0xff) << 16 | + (st.st_ino & 0xffff))); } Modified: stable/11/lib/libc/inet/inet_addr.c ============================================================================== --- stable/11/lib/libc/inet/inet_addr.c Tue Aug 21 00:37:48 2018 (r338123) +++ stable/11/lib/libc/inet/inet_addr.c Tue Aug 21 01:17:28 2018 (r338124) @@ -182,19 +182,20 @@ inet_aton(const char *cp, struct in_addr *addr) { case 2: /*%< a.b -- 8.24 bits */ if (val > 0xffffffU) return (0); - val |= parts[0] << 24; + val |= (uint32_t)parts[0] << 24; break; case 3: /*%< a.b.c -- 8.8.16 bits */ if (val > 0xffffU) return (0); - val |= (parts[0] << 24) | (parts[1] << 16); + val |= ((uint32_t)parts[0] << 24) | (parts[1] << 16); break; case 4: /*%< a.b.c.d -- 8.8.8.8 bits */ if (val > 0xffU) return (0); - val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); + val |= ((uint32_t)parts[0] << 24) | (parts[1] << 16) | + (parts[2] << 8); break; } if (addr != NULL)