-
Notifications
You must be signed in to change notification settings - Fork 27
FIX: S360 Resolve [CodeQL.SM02986] 'Cast from char* to wchar_t* #309
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
Open
gargsaumya
wants to merge
6
commits into
main
Choose a base branch
from
saumya/s360
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+13
−8
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
752f336
suppressing false warnings
gargsaumya 8d7d173
pushing the fix
gargsaumya 2114446
Merge branch 'main' into saumya/s360
gargsaumya 056d806
Merge branch 'main' into saumya/s360
gargsaumya f7565f3
Merge branch 'main' into saumya/s360
gargsaumya 1322bb1
Merge branch 'main' into saumya/s360
gargsaumya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| #include "connection/connection_pool.h" | ||
|
|
||
| #include <cstdint> | ||
| #include <cstring> // For std::memcpy | ||
| #include <iomanip> // std::setw, std::setfill | ||
| #include <iostream> | ||
| #include <utility> // std::forward | ||
|
|
@@ -2463,10 +2464,11 @@ static py::object FetchLobColumnData(SQLHSTMT hStmt, | |
| } else { | ||
| // Wide characters | ||
| size_t wcharSize = sizeof(SQLWCHAR); | ||
| if (bytesRead >= wcharSize) { | ||
| auto sqlwBuf = reinterpret_cast<const SQLWCHAR*>(chunk.data()); | ||
| if (bytesRead >= wcharSize && (bytesRead % wcharSize == 0)) { | ||
| size_t wcharCount = bytesRead / wcharSize; | ||
| while (wcharCount > 0 && sqlwBuf[wcharCount - 1] == 0) { | ||
| std::vector<SQLWCHAR> alignedBuf(wcharCount); | ||
| std::memcpy(alignedBuf.data(), chunk.data(), bytesRead); | ||
| while (wcharCount > 0 && alignedBuf[wcharCount - 1] == 0) { | ||
| --wcharCount; | ||
| bytesRead -= wcharSize; | ||
| } | ||
|
|
@@ -2495,14 +2497,18 @@ static py::object FetchLobColumnData(SQLHSTMT hStmt, | |
| } | ||
| if (isWideChar) { | ||
| #if defined(_WIN32) | ||
| std::wstring wstr(reinterpret_cast<const wchar_t*>(buffer.data()), buffer.size() / sizeof(wchar_t)); | ||
| size_t wcharCount = buffer.size() / sizeof(wchar_t); | ||
|
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. can we add some comments around the changes? also, can add a pointer referencing a small description of the s360 issue. |
||
| std::vector<wchar_t> alignedBuf(wcharCount); | ||
| std::memcpy(alignedBuf.data(), buffer.data(), buffer.size()); | ||
|
||
| std::wstring wstr(alignedBuf.data(), wcharCount); | ||
| std::string utf8str = WideToUTF8(wstr); | ||
| return py::str(utf8str); | ||
| #else | ||
| // Linux/macOS handling | ||
| size_t wcharCount = buffer.size() / sizeof(SQLWCHAR); | ||
| const SQLWCHAR* sqlwBuf = reinterpret_cast<const SQLWCHAR*>(buffer.data()); | ||
| std::wstring wstr = SQLWCHARToWString(sqlwBuf, wcharCount); | ||
| std::vector<SQLWCHAR> alignedBuf(wcharCount); | ||
| std::memcpy(alignedBuf.data(), buffer.data(), buffer.size()); | ||
|
||
| std::wstring wstr = SQLWCHARToWString(alignedBuf.data(), wcharCount); | ||
| std::string utf8str = WideToUTF8(wstr); | ||
| return py::str(utf8str); | ||
| #endif | ||
|
|
@@ -2623,8 +2629,7 @@ SQLRETURN SQLGetData_wrap(SqlHandlePtr StatementHandle, SQLUSMALLINT colCount, p | |
| uint64_t numCharsInData = dataLen / sizeof(SQLWCHAR); | ||
| if (numCharsInData < dataBuffer.size()) { | ||
| #if defined(__APPLE__) || defined(__linux__) | ||
| const SQLWCHAR* sqlwBuf = reinterpret_cast<const SQLWCHAR*>(dataBuffer.data()); | ||
| std::wstring wstr = SQLWCHARToWString(sqlwBuf, numCharsInData); | ||
| std::wstring wstr = SQLWCHARToWString(dataBuffer.data(), numCharsInData); | ||
| std::string utf8str = WideToUTF8(wstr); | ||
| row.append(py::str(utf8str)); | ||
| #else | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.