Skip to content

Fix GH-15552: Signed integer overflow in ext/standard/scanf.c #15581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/standard/scanf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
/*
Expand All @@ -382,6 +381,7 @@ PHPAPI int ValidateFormat(char *format, int numVars, int *totalSubs)

xpgSize = (xpgSize > value) ? xpgSize : value;
}
objIndex = value - 1;
goto xpgCheckDone;
}

Expand Down
9 changes: 9 additions & 0 deletions ext/standard/tests/strings/gh15552.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--TEST--
Bug GH-15552 (Signed integer overflow in ext/standard/scanf.c)
--FILE--
<?php
var_dump(sscanf('hello','%2147483648$s'));
?>
--EXPECTF--
Fatal error: Uncaught ValueError: "%n$" argument index out of range in %s:%d
Stack trace:%A
Loading