Skip to content

Commit 9d20289

Browse files
committed
Fix signed dbconvert() return stored into size_t in dblib lastInsertId
dblib_handle_last_id() stored the DBINT return of dbconvert() into a size_t len. dbconvert() returns -1 on conversion failure, which sign-extends to SIZE_MAX and is passed as the length to zend_string_init(), reading far past the 40-byte buffer and requesting a SIZE_MAX allocation. Hold the result in a DBINT and bail on a negative return, matching the failure-returns-NULL handling already used for dbresults()/dbnextrow()/dbdatlen() earlier in the function.
1 parent 19f595f commit 9d20289

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

ext/pdo_dblib/dblib_driver.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ zend_string *dblib_handle_last_id(pdo_dbh_t *dbh, const zend_string *name)
234234

235235
RETCODE ret;
236236
char *id = NULL;
237-
size_t len;
237+
DBINT len;
238238
zend_string *ret_id;
239239

240240
/*
@@ -271,6 +271,11 @@ zend_string *dblib_handle_last_id(pdo_dbh_t *dbh, const zend_string *name)
271271
len = dbconvert(NULL, (dbcoltype(H->link, 1)) , (dbdata(H->link, 1)) , (dbdatlen(H->link, 1)), SQLCHAR, (BYTE *)id, (DBINT)40);
272272
dbcancel(H->link);
273273

274+
if (len < 0) {
275+
efree(id);
276+
return NULL;
277+
}
278+
274279
ret_id = zend_string_init(id, len, 0);
275280
efree(id);
276281
return ret_id;

0 commit comments

Comments
 (0)