]> granicus.if.org Git - php/commitdiff
Fixed bugs in pdo_mysql
authorXinchen Hui <laruence@php.net>
Thu, 8 May 2014 07:19:43 +0000 (15:19 +0800)
committerXinchen Hui <laruence@php.net>
Thu, 8 May 2014 07:19:43 +0000 (15:19 +0800)
ext/pdo/pdo_sql_parser.c
ext/pdo/pdo_sql_parser.re
ext/pdo/pdo_stmt.c
ext/pdo_mysql/mysql_statement.c

index 4420fcf97c3eb60821e8d89995e5969b970981d5..50b2b5d6ec6d5a63e1510945a3f82855729a08e7 100644 (file)
@@ -434,6 +434,10 @@ struct placeholder {
        struct placeholder *next;
 };
 
+static void free_param_name(zval *el) {
+       efree(Z_PTR_P(el));
+}
+
 PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, 
        char **outquery, int *outquery_len TSRMLS_DC)
 {
@@ -670,7 +674,7 @@ rewrite:
 
                if (stmt->bound_param_map == NULL) {
                        ALLOC_HASHTABLE(stmt->bound_param_map);
-                       zend_hash_init(stmt->bound_param_map, 13, NULL, NULL, 0);
+                       zend_hash_init(stmt->bound_param_map, 13, NULL, free_param_name, 0);
                }
 
                for (plc = placeholders; plc; plc = plc->next) {
@@ -711,12 +715,11 @@ rewrite:
        
                if (stmt->bound_param_map == NULL) {
                        ALLOC_HASHTABLE(stmt->bound_param_map);
-                       zend_hash_init(stmt->bound_param_map, 13, NULL, NULL, 0);
+                       zend_hash_init(stmt->bound_param_map, 13, NULL, free_param_name, 0);
                }
                
                for (plc = placeholders; plc; plc = plc->next) {
                        char *name;
-                       
                        name = estrndup(plc->pos, plc->len);
                        zend_hash_index_update_mem(stmt->bound_param_map, plc->bindno, name, plc->len + 1);
                        efree(name);
index 883a22c7ff02edf7a945269bf4e77e86ec27fb75..4a206c79f485c4a2ebad4f1d975a6072454925a0 100644 (file)
@@ -76,6 +76,10 @@ struct placeholder {
        struct placeholder *next;
 };
 
+static void free_param_name(zval *el) {
+       efree(Z_PTR_P(el));
+}
+
 PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, 
        char **outquery, int *outquery_len TSRMLS_DC)
 {
@@ -312,7 +316,7 @@ rewrite:
 
                if (stmt->bound_param_map == NULL) {
                        ALLOC_HASHTABLE(stmt->bound_param_map);
-                       zend_hash_init(stmt->bound_param_map, 13, NULL, NULL, 0);
+                       zend_hash_init(stmt->bound_param_map, 13, NULL, free_param_name, 0);
                }
 
                for (plc = placeholders; plc; plc = plc->next) {
@@ -353,12 +357,11 @@ rewrite:
        
                if (stmt->bound_param_map == NULL) {
                        ALLOC_HASHTABLE(stmt->bound_param_map);
-                       zend_hash_init(stmt->bound_param_map, 13, NULL, NULL, 0);
+                       zend_hash_init(stmt->bound_param_map, 13, NULL, free_param_name, 0);
                }
                
                for (plc = placeholders; plc; plc = plc->next) {
                        char *name;
-                       
                        name = estrndup(plc->pos, plc->len);
                        zend_hash_index_update_mem(stmt->bound_param_map, plc->bindno, name, plc->len + 1);
                        efree(name);
index bb8a95eaff4cb400e2213858d8d85387ed4e66b3..62db2c66369bb3c3937f6d71246bfecc773f20d8 100644 (file)
@@ -128,7 +128,7 @@ static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_pa
                 * we will raise an error, as we can't be sure that it is safe
                 * to bind multiple parameters onto the same zval in the underlying
                 * driver */
-               zval *name;
+               char *name;
                int position = 0;
 
                if (stmt->named_rewrite_template) {
@@ -137,16 +137,16 @@ static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_pa
                }
                if (!param->name) {
                        /* do the reverse; map the parameter number to the name */
-                       if ((name = zend_hash_index_find(stmt->bound_param_map, param->paramno)) != NULL) {
-                               param->name = STR_COPY(Z_STR_P(name));
+                       if ((name = zend_hash_index_find_ptr(stmt->bound_param_map, param->paramno)) != NULL) {
+                               param->name = STR_INIT(name, strlen(name), 0);
                                return 1;
                        }
                        pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined" TSRMLS_CC);
                        return 0;
                }
     
-               ZEND_HASH_FOREACH_VAL(stmt->bound_param_map, name) {
-                       if (strncmp(Z_STRVAL_P(name), param->name->val, param->name->len + 1)) {
+               ZEND_HASH_FOREACH_PTR(stmt->bound_param_map, name) {
+                       if (strncmp(name, param->name->val, param->name->len + 1)) {
                                position++;
                                continue;
                        }
@@ -460,7 +460,7 @@ static PHP_METHOD(PDOStatement, execute)
 
                        if (key) {
                                /* yes this is correct.  we don't want to count the null byte.  ask wez */
-                               param.name = STR_COPY(key);
+                               param.name = key;
                                param.paramno = -1;
                        } else {
                                /* we're okay to be zero based here */
index df3a3955c89642c6ccbcc2ca2c267a17a810ac8c..ac01102bba0361336d08e4a87e882424a7a6bcc5 100644 (file)
@@ -404,7 +404,8 @@ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
 /* ensure that we free any previous unfetched results */
 #ifndef PDO_USE_MYSQLND
        if (S->stmt) {
-               stmt->column_count = (int)mysql_num_fields(S->result);
+               //???? This line is very suspicious
+               //stmt->column_count = (int)mysql_num_fields(S->result);
                mysql_stmt_free_result(S->stmt);
        }
 #endif