You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the ODBC specification and Microsoft's online documentation:
All buffers are allocated and freed by the application. If a buffer is not deferred, it need only exist for the duration of the call to a function.
SQLSetConnectAttrW is not one of the functions included in the table of functions which are allowed to use deferred buffers.
Expected
The implementation of SQLSetConnectAttrW creates its own copy of non-scalar values it will need to use after the function has returned, and the application can free the buffers for those values as soon as SQLSetConnectAttrW has returned.
Observed
An application using Microsoft's ODBC Driver 18 for SQL Server can crash unless it extends the lifetime of any buffers passed to SQLSetConnectAttrW until after the later call to SQLDriverConnectW has returned.
Repro
The script which can be used to reproduce this behavior is contained in the SQLAlchemy issue in which the problem was first reported.
Important
In order to bypass workarounds implemented to avoid this bug, it is necessary to test with a version of SQLAlchemy earlier than 2.0.48 and a version of pyodbc no later than 5.3.0.
Background
According to the ODBC specification and Microsoft's online documentation:
SQLSetConnectAttrWis not one of the functions included in the table of functions which are allowed to use deferred buffers.Expected
The implementation of
SQLSetConnectAttrWcreates its own copy of non-scalar values it will need to use after the function has returned, and the application can free the buffers for those values as soon asSQLSetConnectAttrWhas returned.Observed
An application using Microsoft's ODBC Driver 18 for SQL Server can crash unless it extends the lifetime of any buffers passed to
SQLSetConnectAttrWuntil after the later call toSQLDriverConnectWhas returned.Repro
The script which can be used to reproduce this behavior is contained in the SQLAlchemy issue in which the problem was first reported.
Important
In order to bypass workarounds implemented to avoid this bug, it is necessary to test with a version of SQLAlchemy earlier than 2.0.48 and a version of pyodbc no later than 5.3.0.
Environment