Fixed snprintf for binary encoding and EOLs (#1293)

This commit is contained in:
Jenny Tam 2021-09-07 11:04:53 -07:00 committed by GitHub
parent f66b2c3e8a
commit 610f54c5f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 118 additions and 117 deletions

View file

@ -1757,7 +1757,8 @@ zend_string* pdo_sqlsrv_dbh_quote(_Inout_ pdo_dbh_t* dbh, _In_ const zend_string
// On failure, a negative number is returned
// The generated string has a length of at most len - 1, so
// len is 3 (2 hex digits + 1)
int n = snprintf((char*)(p + pos), 3, "%02X", unquoted_str[index]);
// Requires "& 0x000000FF", or snprintf will translate "0x90" to "0xFFFFFF90"
int n = snprintf((char*)(p + pos), 3, "%02X", unquoted_str[index] & 0x000000FF);
if (n < 0) {
// Something went wrong, simply return NULL (failure)
return NULL;