@@ -966,8 +966,30 @@ static char *_php_pgsql_escape_identifier(const char *field, size_t field_len)
966
966
field_escaped [j ] = '\0' ;
967
967
return field_escaped ;
968
968
}
969
+ /* }}} */
969
970
#endif
970
971
972
+ /* {{{ _php_pgsql_strndup, no strndup should be used */
973
+ static char * _php_pgsql_strndup (const char * s , size_t len )
974
+ {
975
+ char * new ;
976
+
977
+ if (NULL == s ) {
978
+ return (char * )NULL ;
979
+ }
980
+
981
+ new = (char * ) malloc (len + 1 );
982
+
983
+ if (NULL == new ) {
984
+ return (char * )NULL ;
985
+ }
986
+
987
+ new [len ] = '\0' ;
988
+
989
+ return memmove (new , s , len );
990
+ }
991
+ /* }}} */
992
+
971
993
/* {{{ PHP_INI
972
994
*/
973
995
PHP_INI_BEGIN ()
@@ -6007,7 +6029,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
6007
6029
size_t new_len , field_len = strlen (field );
6008
6030
6009
6031
if (_php_pgsql_detect_identifier_escape (field , field_len ) == SUCCESS ) {
6010
- escaped = strndup (field , field_len );
6032
+ escaped = _php_pgsql_strndup (field , field_len );
6011
6033
} else {
6012
6034
#if HAVE_PQESCAPELITERAL
6013
6035
escaped = PQescapeIdentifier (pg_link , field , field_len );
@@ -6101,7 +6123,7 @@ static inline void build_tablename(smart_str *querystr, PGconn *pg_link, const c
6101
6123
token = php_strtok_r (table_copy , "." , & tmp );
6102
6124
len = strlen (token );
6103
6125
if (_php_pgsql_detect_identifier_escape (token , len ) == SUCCESS ) {
6104
- escaped = strndup (token , len );
6126
+ escaped = _php_pgsql_strndup (token , len );
6105
6127
} else {
6106
6128
#if HAVE_PQESCAPELITERAL
6107
6129
escaped = PQescapeIdentifier (pg_link , token , len );
@@ -6115,7 +6137,7 @@ static inline void build_tablename(smart_str *querystr, PGconn *pg_link, const c
6115
6137
len = strlen (tmp );
6116
6138
/* "schema"."table" format */
6117
6139
if (_php_pgsql_detect_identifier_escape (tmp , len ) == SUCCESS ) {
6118
- escaped = strndup (tmp , len );
6140
+ escaped = _php_pgsql_strndup (tmp , len );
6119
6141
} else {
6120
6142
#if HAVE_PQESCAPELITERAL
6121
6143
escaped = PQescapeIdentifier (pg_link , tmp , len );
0 commit comments