-
Notifications
You must be signed in to change notification settings - Fork 50
FIX: Store deferred connect-attribute values in member buffers (#594) #596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
63ab3b0
2f8db0b
031c717
809bc0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| #include <memory> | ||
| #include <string> | ||
| #include <mutex> | ||
| #include <unordered_map> | ||
|
|
||
| // Represents a single ODBC database connection. | ||
| // Manages connection handles. | ||
|
|
@@ -68,8 +69,13 @@ class Connection { | |
| bool _autocommit = true; | ||
| SqlHandlePtr _dbcHandle; | ||
| std::chrono::steady_clock::time_point _lastUsed; | ||
| std::u16string wstrStringBuffer; // UTF-16 buffer for wide ODBC attributes | ||
| std::string strBytesBuffer; // string buffer for byte attributes setting | ||
| // Per-attribute owned buffers for connect attributes whose pointer the | ||
| // driver may dereference *after* SQLSetConnectAttr returns (deferred | ||
| // attributes, e.g. SQL_COPT_SS_ACCESS_TOKEN). Keyed by attribute ID so | ||
| // that setting a second deferred attribute does not invalidate the | ||
| // pointer the driver stashed for the first. See issue #594. | ||
| std::unordered_map<SQLINTEGER, std::u16string> _attrStringBuffers; | ||
| std::unordered_map<SQLINTEGER, std::string> _attrBytesBuffers; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a bug but good to have - The fix will work perfectly fine because of following reasons - If we want to make it bulletproof, then probably we can define the containers as below - |
||
|
|
||
| // Track child statement handles to mark them as implicitly freed when connection closes | ||
| // Uses weak_ptr to avoid circular references and allow normal cleanup | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This casting may cause data corruption or misaligned input on non-Windows environments.
unixODBC / Linux / macOS (problematic) as char16_t is 2 bytes and encoding is UTF16 while SQLWCHAR is 4 bytes and encoding UTF-32 ( via wchar_t).
reinterpret_cast works only if the memory layout matches exactly.Since SQLWCHAR is platform-dependent, this makes the code non-portable and prone to undefined behavior.