@@ -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 ()
@@ -6008,7 +6030,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
6008
6030
size_t new_len , field_len = strlen (field );
6009
6031
6010
6032
if (_php_pgsql_detect_identifier_escape (field , field_len ) == SUCCESS ) {
6011
- escaped = strndup (field , field_len );
6033
+ escaped = _php_pgsql_strndup (field , field_len );
6012
6034
} else {
6013
6035
#if HAVE_PQESCAPELITERAL
6014
6036
escaped = PQescapeIdentifier (pg_link , field , field_len );
@@ -6102,7 +6124,7 @@ static inline void build_tablename(smart_str *querystr, PGconn *pg_link, const c
6102
6124
token = php_strtok_r (table_copy , "." , & tmp );
6103
6125
len = strlen (token );
6104
6126
if (_php_pgsql_detect_identifier_escape (token , len ) == SUCCESS ) {
6105
- escaped = strndup (token , len );
6127
+ escaped = _php_pgsql_strndup (token , len );
6106
6128
} else {
6107
6129
#if HAVE_PQESCAPELITERAL
6108
6130
escaped = PQescapeIdentifier (pg_link , token , len );
@@ -6116,7 +6138,7 @@ static inline void build_tablename(smart_str *querystr, PGconn *pg_link, const c
6116
6138
len = strlen (tmp );
6117
6139
/* "schema"."table" format */
6118
6140
if (_php_pgsql_detect_identifier_escape (tmp , len ) == SUCCESS ) {
6119
- escaped = strndup (tmp , len );
6141
+ escaped = _php_pgsql_strndup (tmp , len );
6120
6142
} else {
6121
6143
#if HAVE_PQESCAPELITERAL
6122
6144
escaped = PQescapeIdentifier (pg_link , tmp , len );
0 commit comments