Skip to content

Commit 69c5f68

Browse files
nielsdosbukka
authored andcommitted
Fix GHSA-5hqh-c84r-qjcv: Integer overflow in the firebird quoter causing OOB writes
1 parent d9baa9f commit 69c5f68

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

679+
if (UNEXPECTED(ZSTR_LEN(unquoted) + 2 > ZSTR_MAX_LEN - qcount)) {
680+
return NULL;
681+
}
682+
679683
quotedlen = ZSTR_LEN(unquoted) + qcount + 2;
680684
quoted_str = zend_string_alloc(quotedlen, 0);
681685
c = ZSTR_VAL(quoted_str);

0 commit comments

Comments
 (0)