]> granicus.if.org Git - php/commitdiff
Fix bug #70487
authorNikita Popov <nikic@php.net>
Mon, 14 Sep 2015 13:03:51 +0000 (15:03 +0200)
committerNikita Popov <nikic@php.net>
Mon, 14 Sep 2015 13:04:43 +0000 (15:04 +0200)
Switch to * instead of + in zpp.

NEWS
ext/standard/pack.c
ext/standard/tests/strings/bug70487.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 15caf3c102103626d3ed2c7415351780af696bcf..2dcb13ef07317ceba38121da8ae41f8b07b4bf45 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -41,6 +41,7 @@ PHP                                                                        NEWS
 - Standard:
   . Implemented the RFC `Random Functions Throwing Exceptions in PHP 7`.
     (Sammy Kaye Powers, Anthony)
+  . Fixed bug #70487 (pack('x') produces an error). (Nikita)
 
 - Streams:
   . Fixed bug #70361 (HTTP stream wrapper doesn't close keep-alive connections).
index 8b4103850e8393aa9c06d791cd01ae463244ab81..f044ab5ce28279dd697f353818ed8596aa8c7697 100644 (file)
@@ -112,7 +112,7 @@ static void php_pack(zval *val, size_t size, int *map, char *output)
 PHP_FUNCTION(pack)
 {
        zval *argv = NULL;
-       int num_args, i;
+       int num_args = 0, i;
        int currentarg;
        char *format;
        size_t formatlen;
@@ -122,7 +122,7 @@ PHP_FUNCTION(pack)
        int outputpos = 0, outputsize = 0;
        zend_string *output;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "s+", &format, &formatlen, &argv, &num_args) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "s*", &format, &formatlen, &argv, &num_args) == FAILURE) {
                return;
        }
 
diff --git a/ext/standard/tests/strings/bug70487.phpt b/ext/standard/tests/strings/bug70487.phpt
new file mode 100644 (file)
index 0000000..e4ca1ff
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Bug #70487: pack('x') produces an error
+--FILE--
+<?php
+
+var_dump(pack('x') === "\0");
+
+?>
+--EXPECT--
+bool(true)