Skip to content

Commit fe1067a

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) (cherry picked from commit 8a4f389)
1 parent cee6078 commit fe1067a

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
@@ -290,7 +290,7 @@ static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sq
290290
static int firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, /* {{{ */
291291
char **quoted, size_t *quotedlen, enum pdo_param_type paramtype)
292292
{
293-
int qcount = 0;
293+
size_t qcount = 0;
294294
char const *co, *l, *r;
295295
char *c;
296296

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

308+
if (UNEXPECTED(unquotedlen + 2 > ZSTR_MAX_LEN - qcount)) {
309+
return 0;
310+
}
311+
308312
*quotedlen = unquotedlen + qcount + 2;
309313
*quoted = c = emalloc(*quotedlen+1);
310314
*c++ = '\'';

0 commit comments

Comments
 (0)