Skip to content

Commit 5785ff7

Browse files
committed
exp/pgsql: insert/update query string build possible UB fix.
From PQescapeIdentifier() docs ``` A terminating zero byte is not required, and should not be counted in length ```
1 parent c4084bb commit 5785ff7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ PHP NEWS
2828
. Fixed bug GH-20882 (buildFromIterator breaks with missing base directory).
2929
(ndossche)
3030

31+
- PGSQL:
32+
. Fixed INSERT/UPDATE queries building with PQescapeIdentifier() and possible
33+
UB. (David Carlier)
34+
3135
- Readline:
3236
. Fixed bug GH-18139 (Memory leak when overriding some settings
3337
via readline_info()). (ndossche)

ext/pgsql/pgsql.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5632,7 +5632,7 @@ PHP_PGSQL_API zend_result php_pgsql_insert(PGconn *pg_link, const zend_string *t
56325632
goto cleanup;
56335633
}
56345634
if (opt & PGSQL_DML_ESCAPE) {
5635-
tmp = PQescapeIdentifier(pg_link, ZSTR_VAL(fld), ZSTR_LEN(fld) + 1);
5635+
tmp = PQescapeIdentifier(pg_link, ZSTR_VAL(fld), ZSTR_LEN(fld));
56365636
if (tmp == NULL) {
56375637
php_error_docref(NULL, E_NOTICE, "Failed to escape field '%s'", ZSTR_VAL(fld));
56385638
goto cleanup;
@@ -5817,7 +5817,7 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr,
58175817
return -1;
58185818
}
58195819
if (opt & PGSQL_DML_ESCAPE) {
5820-
char *tmp = PQescapeIdentifier(pg_link, ZSTR_VAL(fld), ZSTR_LEN(fld) + 1);
5820+
char *tmp = PQescapeIdentifier(pg_link, ZSTR_VAL(fld), ZSTR_LEN(fld));
58215821
if (tmp == NULL) {
58225822
php_error_docref(NULL, E_NOTICE, "Failed to escape field '%s'", ZSTR_VAL(fld));
58235823
return -1;

0 commit comments

Comments
 (0)