1
0
mirror of https://github.com/php/php-src.git synced 2026-04-28 02:33:17 +02:00

make sure the string is non-empty and use strlcpy() & strlcat()

This commit is contained in:
Antony Dovgal
2007-01-11 16:45:27 +00:00
parent 8c64f4279b
commit 8190ad4661
+10 -8
View File
@@ -3469,10 +3469,11 @@ PHP_FUNCTION(pg_copy_from)
#if HAVE_PQPUTCOPYDATA
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pg_rows), (void **) &tmp, &pos) == SUCCESS) {
convert_to_string_ex(tmp);
query = (char *)emalloc(Z_STRLEN_PP(tmp) +2);
strcpy(query, Z_STRVAL_PP(tmp));
if(*(query+Z_STRLEN_PP(tmp)-1) != '\n')
strcat(query, "\n");
query = (char *)emalloc(Z_STRLEN_PP(tmp) + 2);
strlcpy(query, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp) + 2);
if(Z_STRLEN_PP(tmp) > 0 && *(query + Z_STRLEN_PP(tmp) - 1) != '\n') {
strlcat(query, "\n", Z_STRLEN_PP(tmp) + 2);
}
if (PQputCopyData(pgsql, query, strlen(query)) != 1) {
efree(query);
PHP_PQ_ERROR("copy failed: %s", pgsql);
@@ -3488,10 +3489,11 @@ PHP_FUNCTION(pg_copy_from)
#else
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pg_rows), (void **) &tmp, &pos) == SUCCESS) {
convert_to_string_ex(tmp);
query = (char *)emalloc(Z_STRLEN_PP(tmp) +2);
strcpy(query, Z_STRVAL_PP(tmp));
if(*(query+Z_STRLEN_PP(tmp)-1) != '\n')
strcat(query, "\n");
query = (char *)emalloc(Z_STRLEN_PP(tmp) + 2);
strlcpy(query, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp) + 2);
if(Z_STRLEN_PP(tmp) > 0 && *(query + Z_STRLEN_PP(tmp) - 1) != '\n') {
strlcat(query, "\n", Z_STRLEN_PP(tmp) + 2);
}
if (PQputline(pgsql, query)==EOF) {
efree(query);
PHP_PQ_ERROR("copy failed: %s", pgsql);