git: 8b1925f29c54 - main - kboot: Avoid UB in signed shift
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 11 Mar 2024 21:23:24 UTC
The branch main has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=8b1925f29c54f5791db3c8dcdf2b67541bb8ab32
commit 8b1925f29c54f5791db3c8dcdf2b67541bb8ab32
Author: Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-03-11 20:15:10 +0000
Commit: Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-03-11 21:21:51 +0000
kboot: Avoid UB in signed shift
offset is signed. Copy it to the unsigned res before shifting. This
avoids any possible undefined behavior for right shifting signed
numbers. No functional change intended (and the code generated is the
nearly same for aarch64).
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D44285
---
stand/kboot/kboot/hostfs.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/stand/kboot/kboot/hostfs.c b/stand/kboot/kboot/hostfs.c
index 02afa885d833..7c0600fc35a0 100644
--- a/stand/kboot/kboot/hostfs.c
+++ b/stand/kboot/kboot/hostfs.c
@@ -133,8 +133,9 @@ hostfs_seek(struct open_file *f, off_t offset, int whence)
* from V7 later ISO-C). Also assumes we have to support powerpc still,
* it's interface is weird for legacy reasons....
*/
- offl = offset & 0xffffffff;
- offh = (offset >> 32) & 0xffffffff;
+ res = (uint64_t)offset;
+ offl = res & 0xfffffffful;
+ offh = (res >> 32) & 0xfffffffful;
err = host_llseek(hf->hf_fd, offh, offl, &res, whence);
if (err < 0)
return (err);