svn commit: r338124 - in stable/11/lib/libc: gen inet
Pedro F. Giffuni
pfg at FreeBSD.org
Tue Aug 21 01:17:29 UTC 2018
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)
More information about the svn-src-all
mailing list