php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63535 zend_parse_parameters: error when signature is s|ssbs
Submitted: 2012-11-16 00:46 UTC Modified: 2012-11-16 23:18 UTC
From: lmpmbernardo at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.3.10 OS: Ubuntu 12.04 LTS 32 bits
Private report: No CVE-ID: None
 [2012-11-16 00:46 UTC] lmpmbernardo at gmail dot com
Description:
------------
zend_parse_parameters is having trouble parsing this signature: s|ssbs; the error happens with the last "bs" arguments. the signature "ssbs" works well.

~$ php -v
PHP 5.3.10-1ubuntu3.4 with Suhosin-Patch (cli) (built: Sep 12 2012 19:00:43) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies


Test script:
---------------
PHP_FUNCTION(test_parse_parameters) {
  char *p_str1 = "";
  int p_str1_len;
  char *p_str2 = "";
  int p_str2_len;
  char *p_str3 = "";
  int p_str3_len;
  zend_bool b = 0;

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ssbs", &p_str1, &p_str1_len, &p_str2,
      &p_str2_len, &b, &p_str3, &p_str3_len) == FAILURE) {
    return;
  }

  zend_error(E_WARNING, "First parameter: len[%d] value[%s]", p_str1_len, p_str1);
  zend_error(E_WARNING, "Second parameter: len[%d] value[%s]", p_str2_len, p_str2);
  zend_error(E_WARNING, "Third parameter: '%s'", b ? "TRUE" : "FALSE");
  zend_error(E_WARNING, "Fourth parameter: len[%d] value[%s]", p_str3_len, p_str3);

  char returnValue[256];
  char* result;
  sprintf(returnValue, "%d#%s", 0, "houston, we have a problem!");
  result = estrdup(returnValue);
  RETURN_STRING(result, 0);
}


Expected result:
----------------
lbernardo@sousel:~$ php -r 'echo test_parse_parameters("first", "second", FALSE, "fourth");'
PHP Warning:  First parameter: len[5] value[first] in Command line code on line 1
PHP Warning:  Second parameter: len[6] value[second] in Command line code on line 1
PHP Warning:  Third parameter: 'FALSE' in Command line code on line 1
PHP Warning:  Fourth parameter: len[6] value[fourth] in Command line code on line 1
0#houston, we have a problem!


Actual result:
--------------
lbernardo@sousel:~$ php -r 'echo test_parse_parameters("first", "second", FALSE, "fourth");'
PHP Warning:  First parameter: len[5] value[first] in Command line code on line 1
PHP Warning:  Second parameter: len[6] value[second] in Command line code on line 1
PHP Warning:  Third parameter: 'TRUE' in Command line code on line 1
PHP Warning:  Fourth parameter: len[769] value[(null)] in Command line code on line 1
0#houston, we have a problem!


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-16 00:47 UTC] lmpmbernardo at gmail dot com
-PHP Version: 5.3.18 +PHP Version: 5.3.10
 [2012-11-16 00:47 UTC] lmpmbernardo at gmail dot com
updated version; 5.3.10 is the most recent version in Ubuntu.
 [2012-11-16 01:28 UTC] felipe@php.net
-Status: Open +Status: Not a bug
 [2012-11-16 01:28 UTC] felipe@php.net
You are specifying "s|ssbs", but it's passing args for "s|sbs".
 [2012-11-16 13:34 UTC] lmpmbernardo at gmail dot com
sorry, I checked many times that I was not missing something and I don't 
understand your statement. can you please clarify? I am passing ssbs. my 
understanding is that s|ssbs means the function takes ssbs as arguments and returs 
s.
 [2012-11-16 22:14 UTC] nikic@php.net
s|ssbs means the functions takes a string as the required first argument and string string bool string as optional arguments. The | just delimits required arguments from optional arguments. zend_parse_parameters does not specify the return value type (actually the return value type isn't specified anywhere, you just return it.)
 [2012-11-16 23:18 UTC] lmpmbernardo at gmail dot com
thank you for the clarification. I had been induced in error by JNI where the 
return type needs to be specified.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 23:01:30 2024 UTC