Skip to content

Commit 8a4f389

Browse files
nielsdosremicollet
authored andcommitted
Fix GHSA-5hqh-c84r-qjcv: Integer overflow in the firebird quoter causing OOB writes
(cherry picked from commit 69c5f68fdc3deed9ebce2cc44b4bf5e0c47cd28f) (cherry picked from commit b4f73be) (cherry picked from commit 0530cbf) (cherry picked from commit 72d4c4e)
1 parent c6ee9a7 commit 8a4f389

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ext/pdo_firebird/firebird_driver.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sq
243243
static int firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, /* {{{ */
244244
char **quoted, size_t *quotedlen, enum pdo_param_type paramtype)
245245
{
246-
int qcount = 0;
246+
size_t qcount = 0;
247247
char const *co, *l, *r;
248248
char *c;
249249

@@ -258,6 +258,10 @@ static int firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t u
258258
/* count the number of ' characters */
259259
for (co = unquoted; (co = strchr(co,'\'')); qcount++, co++);
260260

261+
if (UNEXPECTED(unquotedlen + 2 > ZSTR_MAX_LEN - qcount)) {
262+
return 0;
263+
}
264+
261265
*quotedlen = unquotedlen + qcount + 2;
262266
*quoted = c = emalloc(*quotedlen+1);
263267
*c++ = '\'';

0 commit comments

Comments
 (0)