From: Antony Dovgal Date: Thu, 11 Jan 2007 16:45:27 +0000 (+0000) Subject: make sure the string is non-empty and use strlcpy() & strlcat() X-Git-Tag: RELEASE_1_0_0RC1~302 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8190ad466187906d4dfcd4cbda37355d97bcb371;p=php make sure the string is non-empty and use strlcpy() & strlcat() --- diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 06da2d85c7..4b1da70613 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -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);