Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Apr 2022 17:46:15 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 11931e7aa835 - releng/13.1 - fix integer overflow bugs in *stosbt
Message-ID:  <202204061746.236HkFC1022860@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch releng/13.1 has been updated by imp:

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

commit 11931e7aa83515e5d33f04cf11e8a3913df61d60
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-04-06 03:35:27 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2022-04-06 17:46:08 +0000

    fix integer overflow bugs in *stosbt
    
    68f57679d660 Fixed another class of integer overflows, but introduced a
    boundary condition for 2-4s in ns conversion, 2-~4000s in us conversions
    and 2-~4,000,000s in ms conversions. This was because we bogusly used
    SBT_1S for the notion of 1 second, instead of the appropriate power of
    10. To fix, just use the appropriate power of 10, which avoids these
    overflows.
    
    This caused some sleeps in ZFS to be on the order of an hour.
    
    Approved by:            re@ (gjb)
    MFC:                    1 day
    PR:                     263073
    Sponsored by:           Netflix
    Reviewed by:            asomers
    Differential Revision:  https://reviews.freebsd.org/D34790
    
    (cherry picked from commit 4c30b9ecd47a2d92565731082a6a4f2bd1e6e051)
    (cherry picked from commit c43786cc37641cef02171a3c5be5a588d850e6ab)
---
 sys/sys/time.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sys/sys/time.h b/sys/sys/time.h
index 866a9e788cd0..f3a3bc99a0f2 100644
--- a/sys/sys/time.h
+++ b/sys/sys/time.h
@@ -207,7 +207,7 @@ nstosbt(int64_t _ns)
 #ifdef KASSERT
 	KASSERT(_ns >= 0, ("Negative values illegal for nstosbt: %jd", _ns));
 #endif
-	if (_ns >= SBT_1S) {
+	if (_ns >= 1000000000) {
 		sb = (_ns / 1000000000) * SBT_1S;
 		_ns = _ns % 1000000000;
 	}
@@ -231,7 +231,7 @@ ustosbt(int64_t _us)
 #ifdef KASSERT
 	KASSERT(_us >= 0, ("Negative values illegal for ustosbt: %jd", _us));
 #endif
-	if (_us >= SBT_1S) {
+	if (_us >= 1000000) {
 		sb = (_us / 1000000) * SBT_1S;
 		_us = _us % 1000000;
 	}
@@ -255,7 +255,7 @@ mstosbt(int64_t _ms)
 #ifdef KASSERT
 	KASSERT(_ms >= 0, ("Negative values illegal for mstosbt: %jd", _ms));
 #endif
-	if (_ms >= SBT_1S) {
+	if (_ms >= 1000) {
 		sb = (_ms / 1000) * SBT_1S;
 		_ms = _ms % 1000;
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202204061746.236HkFC1022860>