Skip to content

Commit a51f54b

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-15552: Signed integer overflow in ext/standard/scanf.c
2 parents ac4039d + 08841bf commit a51f54b

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ PHP NEWS
2727
. Fixed bug GH-15432 (Heap corruption when querying a vector). (cmb,
2828
Kamil Tekiela)
2929

30+
- Standard:
31+
. Fixed bug GH-15552 (Signed integer overflow in ext/standard/scanf.c). (cmb)
32+
3033
- Streams:
3134
. Fixed bug GH-15628 (php_stream_memory_get_buffer() not zero-terminated).
3235
(cmb)

ext/standard/scanf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ PHPAPI int ValidateFormat(char *format, int numVars, int *totalSubs)
361361
if (gotSequential) {
362362
goto mixedXPG;
363363
}
364-
objIndex = value - 1;
365-
if ((objIndex < 0) || (numVars && (objIndex >= numVars))) {
364+
if ((value < 1) || (numVars && (value > numVars))) {
366365
goto badIndex;
367366
} else if (numVars == 0) {
368367
/*
@@ -382,6 +381,7 @@ PHPAPI int ValidateFormat(char *format, int numVars, int *totalSubs)
382381

383382
xpgSize = (xpgSize > value) ? xpgSize : value;
384383
}
384+
objIndex = value - 1;
385385
goto xpgCheckDone;
386386
}
387387

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Bug GH-15552 (Signed integer overflow in ext/standard/scanf.c)
3+
--FILE--
4+
<?php
5+
var_dump(sscanf('hello','%2147483648$s'));
6+
?>
7+
--EXPECTF--
8+
Fatal error: Uncaught ValueError: "%n$" argument index out of range in %s:%d
9+
Stack trace:%A

0 commit comments

Comments
 (0)