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
DBMS name/version:Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64)
ODBC connection string:
OS and Compiler:Windows 10, msvc
CMake settings:
Actual behavior
In nanodbc::result::result_impl::get_ref_impl<T,type> for SQL_C_DATE, SQL_C_TIME, SQL_C_TIMESTAMP std::setlocale is used incorrectly resulting in a memory access violation.
case SQL_C_DATE:
{
const date d = *ensure_pdata<date>(column);
....
char* old_lc_time = std::setlocale(LC_TIME, nullptr); <- this returns pointer to current locale
std::setlocale(LC_TIME, ""); <- subsequent call here deletes memory referenced by old_lc_time
....
std::setlocale(LC_TIME, old_lc_time); <- memory access violation due to invalid old_lc_time pointer
Expected behavior
Minimal Working Example
This can be fixed by taking a copy of string pointed to by old_lc_time before subsequent call to setlocale with "". This way it is a copy on the stack.
The text was updated successfully, but these errors were encountered:
- Replace char* with std::string to persist the memory content and avoid memory access violation when restoring old locale
- Second call to setlocale frees the old_lc_time pointer which causes the memory access violation during restore (3rd call)
* #276 Fix memory access violation when parsing datetime types
- Replace char* with std::string to persist the memory content and avoid memory access violation when restoring old locale
- Second call to setlocale frees the old_lc_time pointer which causes the memory access violation during restore (3rd call)
* Fix possibility of dereferencing nullptr when assigning C String to std::string
- C strings can be null
Environment
Actual behavior
In nanodbc::result::result_impl::get_ref_impl<T,type> for SQL_C_DATE, SQL_C_TIME, SQL_C_TIMESTAMP std::setlocale is used incorrectly resulting in a memory access violation.
....
char* old_lc_time = std::setlocale(LC_TIME, nullptr); <- this returns pointer to current locale
std::setlocale(LC_TIME, ""); <- subsequent call here deletes memory referenced by old_lc_time
....
std::setlocale(LC_TIME, old_lc_time); <- memory access violation due to invalid old_lc_time pointer
Expected behavior
Minimal Working Example
This can be fixed by taking a copy of string pointed to by old_lc_time before subsequent call to setlocale with "". This way it is a copy on the stack.
The text was updated successfully, but these errors were encountered: