Skip to content

Commit fffd63f

Browse files
authored
Applied mask to pdo quote for binary inputs (#1288)
1 parent 9eef0b9 commit fffd63f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

source/pdo_sqlsrv/pdo_dbh.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,17 @@ struct pdo_dbh_methods pdo_sqlsrv_dbh_methods = {
510510
pdo_sqlsrv_dbh_last_id,
511511
pdo_sqlsrv_dbh_return_error,
512512
pdo_sqlsrv_dbh_get_attr,
513-
NULL, // check liveness not implemented
513+
NULL, // check liveness not implemented
514514
pdo_sqlsrv_get_driver_methods,
515-
NULL, // request shutdown not implemented
516-
NULL // in transaction not implemented
515+
NULL, // request shutdown not implemented
516+
#if PHP_VERSION_ID < 80100
517+
NULL // in transaction not implemented
517518
};
518-
519+
#else
520+
NULL, // in transaction not implemented
521+
NULL // get_gc not implemented
522+
};
523+
#endif
519524

520525
// log a function entry point
521526
#define PDO_LOG_DBH_ENTRY \
@@ -1723,7 +1728,8 @@ zend_string* pdo_sqlsrv_dbh_quote(_Inout_ pdo_dbh_t* dbh, _In_ const zend_string
17231728
// On failure, a negative number is returned
17241729
// The generated string has a length of at most len - 1, so
17251730
// len is 3 (2 hex digits + 1)
1726-
int n = snprintf((char*)(*quoted + pos), 3, "%02X", unquoted[index]);
1731+
// Requires "& 0x000000FF", or snprintf will translate "0x90" to "0xFFFFFF90"
1732+
int n = snprintf((char*)(*quoted + pos), 3, "%02X", unquoted[index] & 0x000000FF);
17271733
if (n < 0) {
17281734
// Something went wrong, simply return 0 (failure)
17291735
return 0;

source/sqlsrv/conn.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct int_conn_str_func {
122122

123123
char temp_str[MAX_CONN_VALSTRING_LEN];
124124

125-
snprintf(temp_str, MAX_CONN_VALSTRING_LEN, "%s={%d};", option->odbc_name, Z_LVAL_P(value));
125+
snprintf(temp_str, MAX_CONN_VALSTRING_LEN, "%s={%ld};", option->odbc_name, Z_LVAL_P(value));
126126
conn_str += temp_str;
127127
}
128128
};

0 commit comments

Comments
 (0)