Skip to content

Commit 30a5f3d

Browse files
committed
printf: Report error if missing padding character
1 parent 0b99017 commit 30a5f3d

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

ext/standard/formatted_print.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,16 @@ php_formatted_print(char *format, size_t format_len, zval *args, int argc, int n
470470
/* space padding, the default */
471471
} else if (*format == '+') {
472472
always_sign = 1;
473-
} else if (*format == '\'' && format_len > 1) {
474-
format++;
475-
format_len--;
476-
padding = *format;
473+
} else if (*format == '\'') {
474+
if (format_len > 1) {
475+
format++;
476+
format_len--;
477+
padding = *format;
478+
} else {
479+
zend_value_error("Missing padding character");
480+
zend_string_efree(result);
481+
return NULL;
482+
}
477483
} else {
478484
PRINTF_DEBUG(("sprintf: end of modifiers\n"));
479485
break;

ext/standard/tests/strings/bug67249.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
Bug #67249 (printf out-of-bounds read)
33
--FILE--
44
<?php
5-
var_dump(sprintf("%'", "foo"));
5+
try {
6+
var_dump(sprintf("%'", "foo"));
7+
} catch (ValueError $e) {
8+
echo $e->getMessage(), "\n";
9+
}
610
?>
711
--EXPECT--
8-
string(0) ""
12+
Missing padding character

0 commit comments

Comments
 (0)