-
Notifications
You must be signed in to change notification settings - Fork 27
FIX: Memory Leak and Security Risk with Static Token Buffer #264
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -173,16 +173,16 @@ SQLRETURN Connection::setAttribute(SQLINTEGER attribute, py::object value) { | |
| LOG("Setting SQL attribute"); | ||
| SQLPOINTER ptr = nullptr; | ||
| SQLINTEGER length = 0; | ||
| std::string buffer; // to hold sensitive data temporarily | ||
|
|
||
| if (py::isinstance<py::int_>(value)) { | ||
| int intValue = value.cast<int>(); | ||
| ptr = reinterpret_cast<SQLPOINTER>(static_cast<uintptr_t>(intValue)); | ||
| length = SQL_IS_INTEGER; | ||
| } else if (py::isinstance<py::bytes>(value) || py::isinstance<py::bytearray>(value)) { | ||
| static std::vector<std::string> buffers; | ||
| buffers.emplace_back(value.cast<std::string>()); | ||
|
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 line supports multiple string inside a vector. But new change is only for one string. Did we validate the impact for all scenario? |
||
| ptr = const_cast<char*>(buffers.back().c_str()); | ||
| length = static_cast<SQLINTEGER>(buffers.back().size()); | ||
| buffer = value.cast<std::string>(); // stack buffer | ||
| ptr = buffer.data(); | ||
| length = static_cast<SQLINTEGER>(buffer.size()); | ||
| } else { | ||
| LOG("Unsupported attribute value type"); | ||
| return SQL_ERROR; | ||
|
|
@@ -195,6 +195,11 @@ SQLRETURN Connection::setAttribute(SQLINTEGER attribute, py::object value) { | |
| else { | ||
| LOG("Set attribute successfully"); | ||
| } | ||
|
|
||
| // Zero out sensitive data if used | ||
| if (!buffer.empty()) { | ||
| std::fill(buffer.begin(), buffer.end(), static_cast<char>(0)); | ||
|
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. why fill? buffer is not allocated via "new". buffer is also a local variable. |
||
| } | ||
gargsaumya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return ret; | ||
| } | ||
|
|
||
|
|
||
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.
removing Static keyword and defining the vector outside the loop may solve the issue??