Bug #60725 [Com]: zend_parse_parameters(): Incorrect parsing of the first parameter

From: Date: Thu, 12 Jan 2012 13:04:28 +0000
Subject: Bug #60725 [Com]: zend_parse_parameters(): Incorrect parsing of the first parameter
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-166392@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60725&edit=1 ID: 60725 Comment by: idlesign at yandex dot ru Reported by: a dot dobkin at drweb dot com Summary: zend_parse_parameters(): Incorrect parsing of the first parameter Status: Bogus Type: Bug Package: Unknown/Other Function Operating System: fedora core 16 x64 PHP Version: 5.3.9 Block user comment: N Private report: N New Comment: @cataphract, Sorry, don't get you: from what do you deduce that that is a "platform specific undefined behavior"? This behaviour you can easily stumble upon after 5.3.6 if develop module. From what I've seen that is a regression as it is, and those guys having first param string alongside with, let's say long, wanting to rely on string lenght param are screwed up after 5.3.6 since they got bloody 0 instead of actual length. Previous Comments: ------------------------------------------------------------------------ [2012-01-12 12:45:54] cataphract@php.net As felipe as said "l" is for "long". This bug tracker is not the place to explain platform specific undefined behavior. ------------------------------------------------------------------------ [2012-01-12 11:11:55] a dot dobkin at drweb dot com Incorrect parsing first parameter when type_spec = "sls" (e.g.) zend_parse_parameter() return string length as 0, always. See example #1 and #2: PHP Warning: First parameter: 'first' and it len: 0 in Command line code on line 1 ------------------------------------------------------------------------ [2012-01-12 11:11:16] idlesign at yandex dot ru @felipe, do you read what subject says? Please elaborate on "'l' expects a 'long', not an 'int'" of yours and on how does it relate to the problem. This ticket is about string length param is set to 0 upon specified circumstances. ------------------------------------------------------------------------ [2012-01-12 10:59:59] felipe@php.net 'l' expects a 'long', not an 'int' ------------------------------------------------------------------------ [2012-01-12 10:57:56] a dot dobkin at drweb dot com Description: ------------ Incorrect parsing of the first parameter if it's has type of 'string' and one of next parameter has type of 'long'. Function zend_parse_parameters() always return string length as 0 of first parameter. Error is present in versions 5.3.7-5.3.9. In version 5.3.6 there is no error On php v 5.3.6 it's correctly works Example 1 (Error): PHP_FUNCTION(test_parse_parameters) { char *p_str1 = NULL; char *p_str2 = NULL; int p_long; int p_str1_len; int p_str2_len; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sls", &p_str1, &p_str1_len, &p_long, &p_str2, &p_str2_len)) { return; } zend_error(E_WARNING, "First parameter: '%s' and it len: %d", p_str1, p_str1_len); zend_error(E_WARNING, "Second parameter: '%d'", p_long); zend_error(E_WARNING, "Third parameter: '%s' and it len: %d", p_str2, p_str2_len); } Run: [antonio@antonio]# php -r 'test_parse_parameters("first", 123, "third");' Output: >>> PHP Warning: First parameter: 'first' and it len: 0 in Command line code on line 1 <<< PHP Warning: Second parameter: '123' in Command line code on line 1 PHP Warning: Third parameter: 'third' and it len: 5 in Command line code on line 1 Exemple 2 (Error): PHP_FUNCTION(test_parse_parameters) { char *p_str1 = NULL; char *p_str2 = NULL; int p_str1_len; int p_str2_len; int p_long; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl", &p_str1, &p_str1_len, &p_str2, &p_str2_len, &p_long)) { return; } zend_error(E_WARNING, "First parameter: '%s' and it len: %d", p_str1, p_str1_len); zend_error(E_WARNING, "Second parameter: '%s' and it len: %d", p_str2, p_str2_len); zend_error(E_WARNING, "Third parameter: '%d'", p_long); } Run: [antonio@antonio]# php -r 'dwavd_init("first", "second", 123);' Output: >>> PHP Warning: First parameter: 'first' and it len: 0 in Command line code on line 1 <<< PHP Warning: Second parameter: 'second' and it len: 6 in Command line code on line 1 PHP Warning: Third parameter: '123' in Command line code on line 1 Exemple 3 (OK): PHP_FUNCTION(test_parse_parameters) { char *p_str1 = NULL; char *p_str2 = NULL; int p_str1_len; int p_str2_len; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &p_str1, &p_str1_len, &p_str2, &p_str2_len)) { return; } zend_error(E_WARNING, "First parameter: '%s' and it len: %d", p_str1, p_str1_len); zend_error(E_WARNING, "Second parameter: '%s' and it len: %d", p_str2, p_str2_len); } Run: [antonio@antonio]# php -r 'test_parse_parameters("first", "second");' Output: PHP Warning: First parameter: 'first' and it len: 5 in Command line code on line 1 PHP Warning: Second parameter: 'second' and it len: 6 in Command line code on line 1 Exemple 4 (OK): PHP_FUNCTION(test_parse_parameters) { char *p_str1 = NULL; char *p_str2 = NULL; int p_str1_len; int p_str2_len; int p_long; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss", &p_long, &p_str1, &p_str1_len, &p_str2, &p_str2_len)) { return; } zend_error(E_WARNING, "First parameter: '%d'", p_long); zend_error(E_WARNING, "Second parameter: '%s' and it len: %d", p_str1, p_str1_len); zend_error(E_WARNING, "Third parameter: '%s' and it len: %d", p_str2, p_str2_len); } Run: [antonio@antonio]# php -r 'test_parse_parameters(123, "second", "third");' Output: PHP Warning: First parameter: '123' in Command line code on line 1 PHP Warning: Second parameter: 'second' and it len: 5 in Command line code on line 1 PHP Warning: Third parameter: 'third' and it len: 6 in Command line code on line 1 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60725&edit=1

« previous php.bugs (#166392) next »