-
Notifications
You must be signed in to change notification settings - Fork 30
Fix security vulnerabilities across codebase #355
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |||||||||
| #include <vector> | ||||||||||
| #include <cstring> | ||||||||||
| #include <iomanip> | ||||||||||
| #include <algorithm> | ||||||||||
|
|
||||||||||
| #include <fcntl.h> | ||||||||||
| #include <sys/ioctl.h> | ||||||||||
|
|
@@ -22,11 +23,16 @@ using namespace realsense::utils; | |||||||||
|
|
||||||||||
| #pragma pack(push, 1) | ||||||||||
| struct HWMC { | ||||||||||
| HWMC(const vector<int32_t> &inParams):header(0x14), magic_word(0xCDAB) { | ||||||||||
| opcode = inParams[0]; | ||||||||||
| HWMC(const vector<int32_t> &inParams):header(0x14), magic_word(0xCDAB), opcode(0) { | ||||||||||
| memset(params, 0, sizeof(params)); | ||||||||||
| for (size_t i = 1; i < inParams.size(); i++) | ||||||||||
| params[i-1] = inParams[i]; | ||||||||||
| if (inParams.empty()) { | ||||||||||
| cerr << "Error: HWMC requires at least an opcode" << endl; | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
Comment on lines
+28
to
+31
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. Constructor emits ad-hoc stderr output and returns early when inParams is empty; avoid leaving console diagnostic output and surprising early-return behavior in a constructor. Details✨ AI Reasoning 🔧 How do I fix it? Reply Show FixRemediation - low confidence
Suggested change
|
||||||||||
| opcode = inParams[0]; | ||||||||||
| size_t paramCount = std::min(inParams.size() - 1, sizeof(params)/sizeof(params[0])); | ||||||||||
| for (size_t i = 0; i < paramCount; i++) | ||||||||||
| params[i] = inParams[i + 1]; | ||||||||||
| } | ||||||||||
| uint16_t header = 0x14; | ||||||||||
| uint16_t magic_word = 0xCDAB; | ||||||||||
|
|
@@ -64,7 +70,7 @@ int main(int argc, char *argv[]) { | |||||||||
| if (!fd) | ||||||||||
| return -1; | ||||||||||
|
|
||||||||||
| uint8_t hwmcBuff[1028] {0}; | ||||||||||
| uint8_t hwmcBuff[1024 + sizeof(struct HWMC)] {0}; | ||||||||||
| memset(hwmcBuff, 0, sizeof(hwmcBuff)); | ||||||||||
|
|
||||||||||
| struct v4l2_ext_control ctrl {0}; | ||||||||||
|
|
@@ -84,9 +90,13 @@ int main(int argc, char *argv[]) { | |||||||||
| return -1; | ||||||||||
| } | ||||||||||
| if (hmc.opcode == *(hwmcBuff + sizeof(struct HWMC))) { | ||||||||||
| uint16_t outLen = hwmcBuff[1001 + sizeof(struct HWMC)] << 8; | ||||||||||
| uint16_t outLen = hwmcBuff[1001 + sizeof(struct HWMC)] << 8; | ||||||||||
| outLen |= hwmcBuff[1000 + sizeof(struct HWMC)]; | ||||||||||
| cout << "output length: "<< outLen << endl;; | ||||||||||
| // Bounds check: ensure we don't read past buffer | ||||||||||
| uint16_t maxLen = sizeof(hwmcBuff) - sizeof(struct HWMC) - 4; | ||||||||||
| if (outLen > maxLen) | ||||||||||
| outLen = maxLen; | ||||||||||
| for (int i = 0; i < outLen; ++i) { | ||||||||||
| if (i != 0 && 0 == (i % 16)) | ||||||||||
| cout << endl; | ||||||||||
|
|
||||||||||
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.
On allocation failure, the function returns after potentially having already allocated earlier buffers in the loop, leaving the object in a partially-initialized state and potentially leaking memory/resources. Before returning, release/clear any previously allocated buffers (or ensure rollback via a scoped guard) so a failed
start()doesn’t leave residual allocations.