-
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 1 commit
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 | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,15 +1,24 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import subprocess | ||||||||||||||||||||||||||||||||||||||||||
| import pytest | ||||||||||||||||||||||||||||||||||||||||||
| import re | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def validate_video_device(device): | ||||||||||||||||||||||||||||||||||||||||||
| """Validate device is a safe video device path.""" | ||||||||||||||||||||||||||||||||||||||||||
| # Accept only video device numbers (0-99) | ||||||||||||||||||||||||||||||||||||||||||
| if not re.match(r'^[0-9]{1,2}$', str(device)): | ||||||||||||||||||||||||||||||||||||||||||
| raise ValueError(f"Invalid device: {device}. Expected video device number (0-99)") | ||||||||||||||||||||||||||||||||||||||||||
| return str(device) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @pytest.mark.d457 | ||||||||||||||||||||||||||||||||||||||||||
| @pytest.mark.parametrize("device", {'0'}) | ||||||||||||||||||||||||||||||||||||||||||
| def test_fw_version(device): | ||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||
| device = validate_video_device(device) | ||||||||||||||||||||||||||||||||||||||||||
| key = "fw_version" | ||||||||||||||||||||||||||||||||||||||||||
| result = subprocess.check_call(["v4l2-ctl", "-d"+device, "-C", key]) | ||||||||||||||||||||||||||||||||||||||||||
| result = subprocess.check_call(["v4l2-ctl", "-d", device, "-C", key]) | ||||||||||||||||||||||||||||||||||||||||||
| assert result == 0 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| std_output = subprocess.check_output(["v4l2-ctl", "-d"+device, "-C", key]) | ||||||||||||||||||||||||||||||||||||||||||
| std_output = subprocess.check_output(["v4l2-ctl", "-d", device, "-C", key]) | ||||||||||||||||||||||||||||||||||||||||||
| key += ": " | ||||||||||||||||||||||||||||||||||||||||||
| assert key in std_output.decode(), "Couldn't fetch FW version" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -26,8 +35,14 @@ def test_fw_version(device): | |||||||||||||||||||||||||||||||||||||||||
| dfu_device = subprocess.check_output(["ls", "/sys/class/d4xx-class/"]).decode() | ||||||||||||||||||||||||||||||||||||||||||
| assert "d4xx-dfu-" in dfu_device, "D4xx DFU device not found" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Validate DFU device name to prevent path traversal | ||||||||||||||||||||||||||||||||||||||||||
| dfu_device_name = dfu_device.strip() | ||||||||||||||||||||||||||||||||||||||||||
| if not re.match(r'^d4xx-dfu-[0-9]+$', dfu_device_name): | ||||||||||||||||||||||||||||||||||||||||||
| raise ValueError(f"Invalid DFU device name: {dfu_device_name}") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
| dfu_device = subprocess.check_output(["ls", "/sys/class/d4xx-class/"]).decode() | |
| assert "d4xx-dfu-" in dfu_device, "D4xx DFU device not found" | |
| # Validate DFU device name to prevent path traversal | |
| dfu_device_name = dfu_device.strip() | |
| if not re.match(r'^d4xx-dfu-[0-9]+$', dfu_device_name): | |
| raise ValueError(f"Invalid DFU device name: {dfu_device_name}") | |
| dfu_device_output = subprocess.check_output(["ls", "/sys/class/d4xx-class/"]).decode() | |
| # Parse ls output, which may contain multiple entries, and select a valid DFU device | |
| dfu_entries = [line.strip() for line in dfu_device_output.splitlines() if line.strip()] | |
| dfu_pattern = re.compile(r'^d4xx-dfu-[0-9]+$') | |
| dfu_device_name = None | |
| for entry in dfu_entries: | |
| if dfu_pattern.match(entry): | |
| dfu_device_name = entry | |
| break | |
| if dfu_device_name is None: | |
| raise AssertionError("D4xx DFU device not found") |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -232,7 +232,12 @@ int StreamView::start(uint32_t memoryType) { | |||||||||||
| break; | ||||||||||||
| case V4L2_MEMORY_USERPTR: | ||||||||||||
| for (int i = 0; i < mBuffersCount; i++) { | ||||||||||||
| mRsBuffers.emplace_back(malloc(bufferLength), bufferLength, i); | ||||||||||||
| void* ptr = malloc(bufferLength); | ||||||||||||
| if (ptr == nullptr) { | ||||||||||||
| RS_LOGE("Failed to allocate buffer %d of size %u", i, bufferLength); | ||||||||||||
| return -1; | ||||||||||||
| } | ||||||||||||
| mRsBuffers.emplace_back(ptr, bufferLength, i); | ||||||||||||
|
Comment on lines
+235
to
+247
|
||||||||||||
| } | ||||||||||||
| break; | ||||||||||||
| default: | ||||||||||||
|
|
@@ -281,7 +286,15 @@ void StreamView::processCaptureResult(uint32_t index) | |||||||||||
| uint32_t cnt = 0; | ||||||||||||
| char* left; | ||||||||||||
| char* right; | ||||||||||||
| char image[mFormat.calcBytesPerFrame()]; | ||||||||||||
| // Use heap allocation instead of VLA to prevent stack overflow | ||||||||||||
| uint32_t frameSize = mFormat.calcBytesPerFrame(); | ||||||||||||
| constexpr uint32_t MAX_FRAME_SIZE = 64 * 1024 * 1024; // 64MB max | ||||||||||||
| if (frameSize == 0 || frameSize > MAX_FRAME_SIZE) { | ||||||||||||
| RS_LOGE("Invalid frame size: %u", frameSize); | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
| std::vector<char> imageVec(frameSize); | ||||||||||||
|
||||||||||||
| std::vector<char> imageVec(frameSize); | |
| static std::vector<char> imageVec; | |
| if (imageVec.size() < frameSize) { | |
| imageVec.resize(frameSize); | |
| } |
| 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) { | ||||||||||||||||||||||||||
| HWMC(const vector<int32_t> &inParams):header(0x14), magic_word(0xCDAB), opcode(0) { | ||||||||||||||||||||||||||
| 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]; | ||||||||||||||||||||||||||
| memset(params, 0, sizeof(params)); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| if (inParams.empty()) { | |
| cerr << "Error: HWMC requires at least an opcode" << endl; | |
| return; | |
| } | |
| opcode = inParams[0]; | |
| memset(params, 0, sizeof(params)); | |
| memset(params, 0, sizeof(params)); | |
| if (inParams.empty()) { | |
| cerr << "Error: HWMC requires at least an opcode" << endl; | |
| return; | |
| } | |
| opcode = inParams[0]; |
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.
$TEGRA_KERNEL_OUTis still unquoted here. For consistency with the new hardening (and to avoid word-splitting/globbing issues), quote it:mkdir -p "$TEGRA_KERNEL_OUT".