Skip to content

Commit 3bea6a2

Browse files
committed
ext/sockets: socket_strerror follow-up on GH-16267 fix.
boundaries should be INT_MIN <= val < INT_MAX in fact. close GH-16891
1 parent 3702f97 commit 3bea6a2

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
- SimpleXML:
1515
. Fixed bug GH-17040 (SimpleXML's unset can break DOM objects). (nielsdos)
1616

17+
- Sockets:
18+
. Fixed bug GH-16276 (socket_strerror overflow handling with INT_MIN).
19+
(David Carlier / cmb)
20+
1721
- Streams:
1822
. Fixed bug GH-17037 (UAF in user filter when adding existing filter name due
1923
to incorrect error handling). (nielsdos)

ext/sockets/sockets.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,11 @@ char *sockets_strerror(int error) /* {{{ */
354354

355355
#ifndef PHP_WIN32
356356
if (error < -10000) {
357-
error = -error - 10000;
357+
if (error == INT_MIN) {
358+
error = 2147473648;
359+
} else {
360+
error = -error - 10000;
361+
}
358362

359363
#ifdef HAVE_HSTRERROR
360364
buf = hstrerror(error);

ext/sockets/tests/gh16267.phpt

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@ GH-16267 - overflow on socket_strerror argument
33
--EXTENSIONS--
44
sockets
55
--SKIPIF--
6-
<?php if (PHP_INT_SIZE != 8) die('skip 64-bit only'); ?>
6+
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
77
--FILE--
88
<?php
9+
var_dump(socket_strerror(-2147483648));
910
try {
10-
socket_strerror(PHP_INT_MIN);
11-
} catch (\ValueError $e) {
12-
echo $e->getMessage() . PHP_EOL;
13-
}
14-
try {
15-
socket_strerror(PHP_INT_MAX);
11+
socket_strerror(2147483648);
1612
} catch (\ValueError $e) {
1713
echo $e->getMessage() . PHP_EOL;
1814
}
1915
?>
2016
--EXPECTF--
21-
socket_strerror(): Argument #1 ($error_code) must be between %s and %s
22-
socket_strerror(): Argument #1 ($error_code) must be between %s and %s
17+
string(%d) "%S"
18+
socket_strerror(): Argument #1 ($error_code) must be between %i and %d

0 commit comments

Comments
 (0)