Skip to content

Commit 2dbe142

Browse files
nielsdosbukka
authored andcommitted
Fix GHSA-5hqh-c84r-qjcv: Integer overflow in the firebird quoter causing OOB writes
1 parent 7742f79 commit 2dbe142

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
@@ -664,7 +664,7 @@ static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const zend_string *sql) /*
664664
/* called by the PDO SQL parser to add quotes to values that are copied into SQL */
665665
static zend_string* firebird_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquoted, enum pdo_param_type paramtype)
666666
{
667-
int qcount = 0;
667+
size_t qcount = 0;
668668
char const *co, *l, *r;
669669
char *c;
670670
size_t quotedlen;
@@ -678,6 +678,10 @@ static zend_string* firebird_handle_quoter(pdo_dbh_t *dbh, const zend_string *un
678678
/* count the number of ' characters */
679679
for (co = ZSTR_VAL(unquoted); (co = strchr(co,'\'')); qcount++, co++);
680680

681+
if (UNEXPECTED(ZSTR_LEN(unquoted) + 2 > ZSTR_MAX_LEN - qcount)) {
682+
return NULL;
683+
}
684+
681685
quotedlen = ZSTR_LEN(unquoted) + qcount + 2;
682686
quoted_str = zend_string_alloc(quotedlen, 0);
683687
c = ZSTR_VAL(quoted_str);

0 commit comments

Comments
 (0)