git: c78f449d85e0 - main - usr.bin/diff: fix UBSan error in readhash

Alex Richardson arichardson at FreeBSD.org
Tue Jul 6 13:29:27 UTC 2021


The branch main has been updated by arichardson:

URL: https://cgit.FreeBSD.org/src/commit/?id=c78f449d85e0b292fe5d942cca99f11c1cd430fa

commit c78f449d85e0b292fe5d942cca99f11c1cd430fa
Author:     Alex Richardson <arichardson at FreeBSD.org>
AuthorDate: 2021-07-06 11:16:40 +0000
Commit:     Alex Richardson <arichardson at FreeBSD.org>
CommitDate: 2021-07-06 11:16:40 +0000

    usr.bin/diff: fix UBSan error in readhash
    
    UBSan complains about the `sum = sum * 127 + chrtran(t);` line below since
    that can overflow an `int`. Use `unsigned int` instead to ensure that
    overflow is well-defined.
    
    Reviewed By:    imp
    MFC after:      1 week
    Differential Revision: https://reviews.freebsd.org/D31075
---
 usr.bin/diff/diffreg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index 1b28281024c6..651ec88df909 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -1345,7 +1345,7 @@ static int
 readhash(FILE *f, int flags)
 {
 	int i, t, space;
-	int sum;
+	unsigned sum;
 
 	sum = 1;
 	space = 0;


More information about the dev-commits-src-all mailing list