Skip to content

Commit cc545f3

Browse files
authored
ext/standard: Reject NUL bytes in openlog() (#22366)
When the value of the parameter of openlog() contains NUL byte(s), throw a ValueError instead of silently truncates it.
1 parent 4d559ca commit cc545f3

4 files changed

Lines changed: 21 additions & 1 deletion

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ PHP NEWS
257257
contains null bytes. (Weilin Du)
258258
. dl() now raises a ValueError when the $extension_filename argument
259259
contains null bytes. (Weilin Du)
260+
. openlog() now raises a ValueError when the $prefix argument contains
261+
null bytes. (Weilin Du)
260262
. parse_str() now raises a ValueError when the $string argument contains
261263
null bytes. (Weilin Du)
262264
. proc_open() now raises a ValueError when the $cwd argument contains

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ PHP 8.6 UPGRADE NOTES
153153
contains null bytes.
154154
. dl() now raises a ValueError when the $extension_filename argument
155155
contains null bytes.
156+
. openlog() now raises a ValueError when the $prefix argument contains
157+
null bytes.
156158
. parse_str() now raises a ValueError when the $string argument contains
157159
null bytes.
158160
. linkinfo() now raises a ValueError when the $path argument is empty.

ext/standard/syslog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ PHP_FUNCTION(openlog)
6161
size_t ident_len;
6262

6363
ZEND_PARSE_PARAMETERS_START(3, 3)
64-
Z_PARAM_STRING(ident, ident_len)
64+
Z_PARAM_PATH(ident, ident_len)
6565
Z_PARAM_LONG(option)
6666
Z_PARAM_LONG(facility)
6767
ZEND_PARSE_PARAMETERS_END();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
openlog() rejects null bytes in prefix
3+
--SKIPIF--
4+
<?php
5+
if (!function_exists("openlog")) die("skip openlog() is not available");
6+
?>
7+
--FILE--
8+
<?php
9+
try {
10+
openlog("foo\0bar", LOG_NDELAY, LOG_USER);
11+
} catch (ValueError $e) {
12+
echo $e->getMessage(), "\n";
13+
}
14+
?>
15+
--EXPECT--
16+
openlog(): Argument #1 ($prefix) must not contain any null bytes

0 commit comments

Comments
 (0)