Skip to content

Commit

Permalink
Fix bug #67249: printf out-of-bounds read
Browse files Browse the repository at this point in the history
  • Loading branch information
smalyshev committed Jun 13, 2014
1 parent d400b74 commit d780c2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ext/standard/formatted_print.c
Expand Up @@ -379,6 +379,7 @@ php_formatted_print(int ht, int *len, int use_array, int format_offset TSRMLS_DC
int alignment, currarg, adjusting, argnum, width, precision;
char *format, *result, padding;
int always_sign;
int format_len;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) {
return NULL;
Expand Down Expand Up @@ -417,11 +418,12 @@ php_formatted_print(int ht, int *len, int use_array, int format_offset TSRMLS_DC

convert_to_string_ex(args[format_offset]);
format = Z_STRVAL_PP(args[format_offset]);
format_len = Z_STRLEN_PP(args[format_offset]);
result = emalloc(size);

currarg = 1;

while (inpos<Z_STRLEN_PP(args[format_offset])) {
while (inpos<format_len) {
int expprec = 0, multiuse = 0;
zval *tmp;

Expand Down Expand Up @@ -476,7 +478,7 @@ php_formatted_print(int ht, int *len, int use_array, int format_offset TSRMLS_DC
/* space padding, the default */
} else if (format[inpos] == '+') {
always_sign = 1;
} else if (format[inpos] == '\'') {
} else if (format[inpos] == '\'' && inpos+1<format_len) {
padding = format[++inpos];
} else {
PRINTF_DEBUG(("sprintf: end of modifiers\n"));
Expand Down
8 changes: 8 additions & 0 deletions ext/standard/tests/strings/bug67249.phpt
@@ -0,0 +1,8 @@
--TEST--
Bug #67249 (printf out-of-bounds read)
--FILE--
<?php
var_dump(sprintf("%'", "foo"));
?>
--EXPECT--
string(0) ""

0 comments on commit d780c2a

Please sign in to comment.