]> granicus.if.org Git - php/commitdiff
Fixed bug #46206 (pg_query_params/pg_execute convert passed values to
authorIlia Alshanetsky <iliaa@php.net>
Wed, 1 Oct 2008 20:30:23 +0000 (20:30 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 1 Oct 2008 20:30:23 +0000 (20:30 +0000)
strings).

NEWS
ext/pgsql/pgsql.c

diff --git a/NEWS b/NEWS
index 401920ebe2f5f4d8fb3c056fc713bb4b979b1142..38470182ea194b6653583defed230c5a2235bfeb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ PHP                                                                        NEWS
 
 - Fixed bug causing the algorithm parameter of mhash() to be modified. (Scott)
 
+- Fixed bug #46206 (pg_query_params/pg_execute convert passed values to
+  strings). (Ilia) 
 - Fixed bug #46205 (Closure - Memory leaks when ReflectionException is thrown).
   (Dmitry)
 - Fixed bug #46194 (SIGSEGV when requested file is not found). (Greg)
index a1e4f2d4b6b74f2fa94f22607df9533c433f5641..1eacf467fe4ff158929ede0832012976f1bf68cc 100644 (file)
@@ -1721,6 +1721,10 @@ PHP_FUNCTION(pg_query)
 static void _php_pgsql_free_params(char **params, int num_params)
 {
        if (num_params > 0) {
+               int i;
+               for (i = 0; i < num_params; i++) {
+                       efree(params[i]);
+               }
                efree(params);
        }
 }
@@ -1739,7 +1743,6 @@ PHP_FUNCTION(pg_query_params)
        int leftover = 0;
        int num_params = 0;
        char **params = NULL;
-       unsigned char otype;
        PGconn *pgsql;
        PGresult *pgsql_result;
        ExecStatusType status;
@@ -1788,19 +1791,20 @@ PHP_FUNCTION(pg_query_params)
                                RETURN_FALSE;
                        }
 
-                       otype = (*tmp)->type;
-                       convert_to_string_ex(tmp);
-                       if (Z_TYPE_PP(tmp) != IS_STRING) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
-                               _php_pgsql_free_params(params, num_params);
-                               RETURN_FALSE;
-                       }
-
-                       if (otype == IS_NULL) {
+                       if (Z_TYPE_PP(tmp) == IS_NULL) {
                                params[i] = NULL;
-                       }
-                       else {
-                               params[i] = Z_STRVAL_PP(tmp);
+                       } else {
+                               zval tmp_val = **tmp;
+                               zval_copy_ctor(&tmp_val);
+                               convert_to_string(&tmp_val);
+                               if (Z_TYPE(tmp_val) != IS_STRING) {
+                                       php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
+                                       zval_dtor(&tmp_val);
+                                       _php_pgsql_free_params(params, num_params);
+                                       RETURN_FALSE;
+                               }
+                               params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val));
+                               zval_dtor(&tmp_val);
                        }
 
                        zend_hash_move_forward(Z_ARRVAL_P(pv_param_arr));
@@ -1946,7 +1950,6 @@ PHP_FUNCTION(pg_execute)
        int leftover = 0;
        int num_params = 0;
        char **params = NULL;
-       unsigned char otype;
        PGconn *pgsql;
        PGresult *pgsql_result;
        ExecStatusType status;
@@ -1995,19 +1998,20 @@ PHP_FUNCTION(pg_execute)
                                RETURN_FALSE;
                        }
 
-                       otype = (*tmp)->type;
-                       SEPARATE_ZVAL(tmp);
-                       convert_to_string_ex(tmp);
-                       if (Z_TYPE_PP(tmp) != IS_STRING) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
-                               _php_pgsql_free_params(params, num_params);
-                               RETURN_FALSE;
-                       }
-
-                       if (otype == IS_NULL) {
+                       if (Z_TYPE_PP(tmp) == IS_NULL) {
                                params[i] = NULL;
                        } else {
-                               params[i] = Z_STRVAL_PP(tmp);
+                               zval tmp_val = **tmp;
+                               zval_copy_ctor(&tmp_val);
+                               convert_to_string(&tmp_val);
+                               if (Z_TYPE(tmp_val) != IS_STRING) {
+                                       php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
+                                       zval_dtor(&tmp_val);
+                                       _php_pgsql_free_params(params, num_params);
+                                       RETURN_FALSE;
+                               }
+                               params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val));
+                               zval_dtor(&tmp_val);
                        }
 
                        zend_hash_move_forward(Z_ARRVAL_P(pv_param_arr));
@@ -4550,7 +4554,6 @@ PHP_FUNCTION(pg_send_query_params)
        zval *pgsql_link, *pv_param_arr, **tmp;
        int num_params = 0;
        char **params = NULL;
-       unsigned char otype;
        char *query;
        int query_len, id = -1;
        PGconn *pgsql;
@@ -4592,20 +4595,20 @@ PHP_FUNCTION(pg_send_query_params)
                                RETURN_FALSE;
                        }
 
-                       otype = (*tmp)->type;
-                       SEPARATE_ZVAL(tmp);
-                       convert_to_string_ex(tmp);
-                       if (Z_TYPE_PP(tmp) != IS_STRING) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
-                               _php_pgsql_free_params(params, num_params);
-                               RETURN_FALSE;
-                       }
-
-                       if (otype == IS_NULL) {
+                       if (Z_TYPE_PP(tmp) == IS_NULL) {
                                params[i] = NULL;
-                       }
-                       else {
-                               params[i] = Z_STRVAL_PP(tmp);
+                       } else {
+                               zval tmp_val = **tmp;
+                               zval_copy_ctor(&tmp_val);
+                               convert_to_string(&tmp_val);
+                               if (Z_TYPE(tmp_val) != IS_STRING) {
+                                       php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
+                                       zval_dtor(&tmp_val);
+                                       _php_pgsql_free_params(params, num_params);
+                                       RETURN_FALSE;
+                               }
+                               params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val));
+                               zval_dtor(&tmp_val);
                        }
 
                        zend_hash_move_forward(Z_ARRVAL_P(pv_param_arr));
@@ -4688,7 +4691,6 @@ PHP_FUNCTION(pg_send_execute)
        zval *pv_param_arr, **tmp;
        int num_params = 0;
        char **params = NULL;
-       unsigned char otype;
        char *stmtname;
        int stmtname_len, id = -1;
        PGconn *pgsql;
@@ -4730,19 +4732,20 @@ PHP_FUNCTION(pg_send_execute)
                                RETURN_FALSE;
                        }
 
-                       otype = (*tmp)->type;
-                       convert_to_string(*tmp);
-                       if (Z_TYPE_PP(tmp) != IS_STRING) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
-                               _php_pgsql_free_params(params, num_params);
-                               RETURN_FALSE;
-                       }
-
-                       if (otype == IS_NULL) {
+                       if (Z_TYPE_PP(tmp) == IS_NULL) {
                                params[i] = NULL;
-                       }
-                       else {
-                               params[i] = Z_STRVAL_PP(tmp);
+                       } else {
+                               zval tmp_val = **tmp;
+                               zval_copy_ctor(&tmp_val);
+                               convert_to_string(&tmp_val);
+                               if (Z_TYPE(tmp_val) != IS_STRING) {
+                                       php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
+                                       zval_dtor(&tmp_val);
+                                       _php_pgsql_free_params(params, num_params);
+                                       RETURN_FALSE;
+                               }
+                               params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val));
+                               zval_dtor(&tmp_val);
                        }
 
                        zend_hash_move_forward(Z_ARRVAL_P(pv_param_arr));