php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65542 zend_parse_parameters return string length == 0
Submitted: 2013-08-24 20:56 UTC Modified: 2013-08-24 23:22 UTC
From: Azq2 at ya dot ru Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.5.3 OS:
Private report: No CVE-ID: None
 [2013-08-24 20:56 UTC] Azq2 at ya dot ru
Description:
------------
I have this code in my extension: 

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssssl|bl", &addr, 
&addr_length, &user, &user_length, &password, &password_length, &db, &db_length, 
&port, &persistent, &flags) != SUCCESS)
		WRONG_PARAM_COUNT; 
	
and i call from php: 
$db -> connect("127.0.0.2", "root", "qwerty", "test", 1); 


But... addr_length and user_length equals as zero O_O But addr and user not empty 
and contains my values... o_O


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-24 20:59 UTC] felipe@php.net
-Status: Open +Status: Feedback
 [2013-08-24 20:59 UTC] felipe@php.net
What data type have you used for store the string length?
 [2013-08-24 21:02 UTC] azq2 at ya dot ru
String. 

$db -> connect("127.0.0.2", "root", "qwerty", "test", 1);
 [2013-08-24 21:04 UTC] felipe@php.net
I mean what data type have you used for addr_length and user_length in your C code.
 [2013-08-24 21:05 UTC] Azq2 at ya dot ru
-Status: Feedback +Status: Open
 [2013-08-24 21:05 UTC] Azq2 at ya dot ru
char *addr, *user, *password, *db, *connect_id = NULL, *socket = NULL, *host = 
NULL; 
uint addr_length, user_length, password_length, db_length, connect_id_length = 0;
 [2013-08-24 21:06 UTC] azq2 at ya dot ru
But... password and db - is ok.
 [2013-08-24 21:33 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2013-08-24 21:33 UTC] johannes@php.net
String lengths in PHP are int not uint.

Still 0 would be an unlikely result, but string length handling works in a few hundred other functions flawlessly so it's likely a bug in your code. As this is no support forum please take this somewhere else. (The pecl-dev list might be a good place if you share a bit more code)
 [2013-08-24 21:58 UTC] Azq2 at ya dot ru
NOT, ITS BUG. 


CODE: 
PHP_METHOD(Mysql, connect) {
	bool return_state = true; 
	bool persistent = false; 
	char *addr, *user, *password, *db, *connect_id = NULL, *socket = NULL, 
*host = NULL; 
	int addr_length=0, user_length, password_length, db_length, 
connect_id_length = 0; 
	uint socket_length = 0, host_length = 0; 
	unsigned short port = 0; 
	unsigned long flags = 0; 
	
	zval *object = getThis(); 
	php_mysql_object *obj = (php_mysql_object 
*)zend_object_store_get_object(object TSRMLS_CC); 
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssssl|bl", &addr, 
&addr_length, &user, &user_length, &password, &password_length, &db, &db_length, 
&port, &persistent, &flags) != SUCCESS)
		WRONG_PARAM_COUNT; 
	
	printf("addr(%d)     = %s\n", addr_length, addr); 
	printf("user(%d)     = %s\n", user_length, user); 
	printf("password(%d) = %s\n", password_length, password); 
	printf("db(%d)       = %s\n", db_length, db); 
	

php code: 
$db -> connect("127.0.0.2", "root", "qwerty", "test", 1); 


Returns: 
addr(0)     = 127.0.0.2
user(0)     = root
password(6) = qwerty
db(4)       = test
 [2013-08-24 22:31 UTC] azq2 at ya dot ru
But if use zval - length works
 [2013-08-24 23:22 UTC] johannes@php.net
Given that zend_parse_parameters work in about 3000 places in PHP and tons of other extensions it is unlikely that this is the cause of the issue. Have you run a memory checker (valgrind etc.)?

Unless there is compilable code which proves this is a PHP issue this is Not a Bug.

As said: For support writing PHP extensions please write the pecl-dev list (pecl-dev at lists.php.net), but that also requires compilable code for useful help.
 [2013-08-25 07:13 UTC] azq2 at ya dot ru
azq2@zhumarin:/var/www/zhumarin-test.ru/core/native$ valgrind --tool=memcheck --
num-callers=30 php scripts/test.php
==9991== Memcheck, a memory error detector
==9991== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==9991== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==9991== Command: php scripts/test.php
==9991== 
addr(9)     = 127.0.0.2
user(4)     = root
password(6) = qwerty
db(4)       = test

Warning: var_dump() expects at least 1 parameter, 0 given in /var/www/zhumarin-
test.ru/core/native/scripts/test.php on line 5
...
==9991== 
==9991== HEAP SUMMARY:
==9991==     in use at exit: 104,605 bytes in 2,642 blocks
==9991==   total heap usage: 25,435 allocs, 22,793 frees, 3,914,280 bytes 
allocated
==9991== 
==9991== LEAK SUMMARY:
==9991==    definitely lost: 248 bytes in 1 blocks
==9991==    indirectly lost: 10,604 bytes in 6 blocks
==9991==      possibly lost: 0 bytes in 0 blocks
==9991==    still reachable: 93,753 bytes in 2,635 blocks
==9991==         suppressed: 0 bytes in 0 blocks
==9991== Rerun with --leak-check=full to see details of leaked memory
==9991== 
==9991== For counts of detected and suppressed errors, rerun with: -v
==9991== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
 [2013-08-25 08:57 UTC] azq2 at ya dot ru
Problem solved. I noob :D
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 21:01:29 2024 UTC