php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60725 zend_parse_parameters(): Incorrect parsing of the first parameter
Submitted: 2012-01-12 10:57 UTC Modified: 2012-01-12 12:45 UTC
From: a dot dobkin at drweb dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.3.9 OS: fedora core 16 x64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: a dot dobkin at drweb dot com
New email:
PHP Version: OS:

 

 [2012-01-12 10:57 UTC] 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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-12 10:59 UTC] felipe@php.net
'l' expects a 'long', not an 'int'
 [2012-01-12 11:11 UTC] 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 11:11 UTC] 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 12:45 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2012-01-12 12:45 UTC] 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 13:04 UTC] idlesign at yandex dot ru
@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.
 [2012-01-12 14:33 UTC] anon at anon dot anon
@a.dobkin, @idlesign

x64 int is 4 bytes, long is 8 bytes. In the example zend_parse_parameters is being told to write 8 bytes into a 4 byte variable, and the address where the high 4 bytes would be if they existed happens to be (although this is platform specific and undefined) the address of the int string length. It's completely to be expected.

If you're telling zend_parse_parameters you're giving it a long (as in "sls") then actually give it one. I.e., "long p_long;".
 [2012-01-13 04:43 UTC] a dot dobkin at drweb dot com
Oh.. just missed it. thanks!
 [2012-01-13 05:07 UTC] idlesign at yandex dot ru
@anon,

Patient answer that was, thank you :) Crivens! Completely missed that "OS: fedora core 16 x64" thing. Sorry to bother.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 15:01:33 2024 UTC