Skip to content

Commit b256b65

Browse files
nielsdosSakiTakamachi
authored andcommitted
Fix GHSA-5hqh-c84r-qjcv: Integer overflow in the firebird quoter causing OOB writes
1 parent ed01e51 commit b256b65

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
@@ -790,7 +790,7 @@ static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const zend_string *sql) /*
790790
/* called by the PDO SQL parser to add quotes to values that are copied into SQL */
791791
static zend_string* firebird_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquoted, enum pdo_param_type paramtype)
792792
{
793-
int qcount = 0;
793+
size_t qcount = 0;
794794
char const *co, *l, *r;
795795
char *c;
796796
size_t quotedlen;
@@ -804,6 +804,10 @@ static zend_string* firebird_handle_quoter(pdo_dbh_t *dbh, const zend_string *un
804804
/* count the number of ' characters */
805805
for (co = ZSTR_VAL(unquoted); (co = strchr(co,'\'')); qcount++, co++);
806806

807+
if (UNEXPECTED(ZSTR_LEN(unquoted) + 2 > ZSTR_MAX_LEN - qcount)) {
808+
return NULL;
809+
}
810+
807811
quotedlen = ZSTR_LEN(unquoted) + qcount + 2;
808812
quoted_str = zend_string_alloc(quotedlen, 0);
809813
c = ZSTR_VAL(quoted_str);

0 commit comments

Comments
 (0)