You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Signed integer overflow in ext/standard/scanf.c #15552
/php-src/ext/standard/scanf.c:364:21: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /php-src/ext/standard/scanf.c:364:21
Maybe we should assign objIndex only after having done the bounds checking, i.e. (maybe there are off-by-one errors; should be checked more thoroughly):
ext/standard/scanf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ext/standard/scanf.c b/ext/standard/scanf.c
index 78ecc1642c..408e5ede88 100644
--- a/ext/standard/scanf.c+++ b/ext/standard/scanf.c@@ -361,8 +361,7 @@ PHPAPI int ValidateFormat(char *format, int numVars, int *totalSubs)
if (gotSequential) {
goto mixedXPG;
}
- objIndex = value - 1;- if ((objIndex < 0) || (numVars && (objIndex >= numVars))) {+ if ((value < 1) || (numVars && (value > numVars))) {
goto badIndex;
} else if (numVars == 0) {
/*
@@ -382,6 +381,7 @@ PHPAPI int ValidateFormat(char *format, int numVars, int *totalSubs)
xpgSize = (xpgSize > value) ? xpgSize : value;
}
+ objIndex = value - 1;
goto xpgCheckDone;
}
Activity
cmb69 commentedon Aug 23, 2024
Simpler reproducer (which triggers a segfault for me; PHP 8.2+):
So this is apparently an issue with the argnum specifier, which is way to large. Quick fix (without much thinking and further checking):
devnexen commentedon Aug 23, 2024
That should work, or you can always check if the zend_ulong val fits the 0/INT_MAX boundaries before assigning to value otherwise but ...
cmb69 commentedon Aug 23, 2024
Maybe we should assign
objIndexonly after having done the bounds checking, i.e. (maybe there are off-by-one errors; should be checked more thoroughly):Fix phpGH-15552: Signed integer overflow in ext/standard/scanf.c
Merge branch 'PHP-8.2' into PHP-8.3
Merge branch 'PHP-8.3'
Fix GH-15552: Signed integer overflow in ext/standard/scanf.c