com php-src: Merge branch 'PHP-5.6': ext/pgsql/pgsql.c

From: Date: Tue, 03 Feb 2015 06:40:59 +0000
Subject: com php-src: Merge branch 'PHP-5.6': ext/pgsql/pgsql.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-84585@lists.php.net to get a copy of this message
Commit: 30b4a32e09a0bc142ecd7002f0a6eba710a4e997 Author: Yasuo Ohgaki <yohgaki@php.net> Tue, 3 Feb 2015 15:40:59 +0900 Parents: 1aa6242dcf856f799cd2c48a993fa507fbd949e6 36f73412c12c1271bf686ba7309aee4169c2dc71 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=30b4a32e09a0bc142ecd7002f0a6eba710a4e997 Log: Merge branch 'PHP-5.6' * PHP-5.6: Fixed Bug #65199 pg_copy_from() modifies input array variable Conflicts: ext/pgsql/pgsql.c Bugs: https://bugs.php.net/65199 Changed paths: MM ext/pgsql/pgsql.c Diff: diff --cc ext/pgsql/pgsql.c index 225ff65,ed7bf0b..d414025a --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@@ -4151,11 -4159,12 +4151,11 @@@ PHP_FUNCTION(pg_copy_to PHP_FUNCTION(pg_copy_from) { zval *pgsql_link = NULL, *pg_rows; - zval *tmp; - zval **tmp; ++ zval *value; char *table_name, *pg_delim = NULL, *pg_null_as = NULL; - int table_name_len, pg_delim_len, pg_null_as_len; + size_t table_name_len, pg_delim_len, pg_null_as_len; int pg_null_as_free = 0; char *query; - HashPosition pos; int id = -1; PGconn *pgsql; PGresult *pgsql_result; @@@ -4199,40 -4208,59 +4199,50 @@@ if (pgsql_result) { int command_failed = 0; PQclear(pgsql_result); - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pg_rows), &pos); #if HAVE_PQPUTCOPYDATA - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pg_rows), tmp) { - convert_to_string_ex(tmp); - query = (char *)emalloc(Z_STRLEN_P(tmp) + 2); - strlcpy(query, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp) + 2); - if(Z_STRLEN_P(tmp) > 0 && *(query + Z_STRLEN_P(tmp) - 1) != '\n') { - strlcat(query, "\n", Z_STRLEN_P(tmp) + 2); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pg_rows), (void **) &tmp, &pos) == SUCCESS) { - zval *value; - ALLOC_ZVAL(value); - INIT_PZVAL_COPY(value, *tmp); - zval_copy_ctor(value); - convert_to_string_ex(&value); - query = (char *)emalloc(Z_STRLEN_P(value) + 2); - strlcpy(query, Z_STRVAL_P(value), Z_STRLEN_P(value) + 2); - if(Z_STRLEN_P(value) > 0 && *(query + Z_STRLEN_P(value) - 1) != '\n') { - strlcat(query, "\n", Z_STRLEN_P(value) + 2); ++ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pg_rows), value) { ++ zval tmp; ++ ZVAL_DUP(&tmp, value); ++ convert_to_string_ex(&tmp); ++ query = (char *)emalloc(Z_STRLEN(tmp) + 2); ++ strlcpy(query, Z_STRVAL(tmp), Z_STRLEN(tmp) + 2); ++ if(Z_STRLEN(tmp) > 0 && *(query + Z_STRLEN(tmp) - 1) != '\n') { ++ strlcat(query, "\n", Z_STRLEN(tmp) + 2); } - if (PQputCopyData(pgsql, query, strlen(query)) != 1) { + if (PQputCopyData(pgsql, query, (int)strlen(query)) != 1) { efree(query); - zval_dtor(value); - efree(value); ++ zval_dtor(&tmp); PHP_PQ_ERROR("copy failed: %s", pgsql); RETURN_FALSE; } efree(query); - zval_dtor(value); - efree(value); - zend_hash_move_forward_ex(Z_ARRVAL_P(pg_rows), &pos); - } ++ zval_dtor(&tmp); + } ZEND_HASH_FOREACH_END(); ++ if (PQputCopyEnd(pgsql, NULL) != 1) { PHP_PQ_ERROR("putcopyend failed: %s", pgsql); RETURN_FALSE; } #else - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pg_rows), tmp) { - convert_to_string_ex(tmp); - query = (char *)emalloc(Z_STRLEN_P(tmp) + 2); - strlcpy(query, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp) + 2); - if(Z_STRLEN_P(tmp) > 0 && *(query + Z_STRLEN_P(tmp) - 1) != '\n') { - strlcat(query, "\n", Z_STRLEN_P(tmp) + 2); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pg_rows), (void **) &tmp, &pos) == SUCCESS) { - zval *value; - ALLOC_ZVAL(value); - INIT_PZVAL_COPY(value, *tmp); - zval_copy_ctor(value); - convert_to_string_ex(&value); - query = (char *)emalloc(Z_STRLEN_P(value) + 2); - strlcpy(query, Z_STRVAL_P(value), Z_STRLEN_P(value) + 2); - if(Z_STRLEN_P(value) > 0 && *(query + Z_STRLEN_P(value) - 1) != '\n') { - strlcat(query, "\n", Z_STRLEN_P(value) + 2); ++ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pg_rows), value) { ++ zval tmp; ++ ZVAL_DUP(&tmp, value); ++ convert_to_string_ex(&tmp); ++ query = (char *)emalloc(Z_STRLEN(tmp) + 2); ++ strlcpy(query, Z_STRVAL(tmp), Z_STRLEN(tmp) + 2); ++ if(Z_STRLEN(tmp) > 0 && *(query + Z_STRLEN(tmp) - 1) != '\n') { ++ strlcat(query, "\n", Z_STRLEN(tmp) + 2); } if (PQputline(pgsql, query)==EOF) { efree(query); - zval_dtor(value); - efree(value); ++ zval_dtor(&tmp); PHP_PQ_ERROR("copy failed: %s", pgsql); RETURN_FALSE; } efree(query); - zval_dtor(value); - efree(value); - zend_hash_move_forward_ex(Z_ARRVAL_P(pg_rows), &pos); - } ++ zval_dtor(&tmp); + } ZEND_HASH_FOREACH_END(); ++ if (PQputline(pgsql, "\\.\n") == EOF) { PHP_PQ_ERROR("putline failed: %s", pgsql); RETURN_FALSE;

« previous php.cvs (#84585) next »