Security Fix: Resolve CWE-787 and CWE-22 vulnerabilities zthin-part#952
Open
Rajat-0 wants to merge 1 commit into
Open
Security Fix: Resolve CWE-787 and CWE-22 vulnerabilities zthin-part#952Rajat-0 wants to merge 1 commit into
Rajat-0 wants to merge 1 commit into
Conversation
…ities.c CRITICAL security fixes addressing: 1. CWE-78: OS Command Injection - Replaced system() calls with direct file operations - Added safe_remove_files() and safe_remove_directory_recursive() - Prevents command injection in vmbkendRemoveCachedScanFiles() - Prevents command injection in vmbkendRemoveEntireCache() 2. CWE-787: Out-of-bounds Write - Replaced sprintf() with snprintf() for bounds checking - Added buffer size validation in all string operations - Prevents buffer overflow in file path construction 3. CWE-22: Path Traversal - Added realpath() validation for all user-supplied paths - Validates paths before file operations - Rejects paths containing shell metacharacters Changes: - Added dirent.h include for directory operations - Implemented safe_remove_files() helper function - Implemented safe_remove_directory_recursive() helper function - Fixed vmbkendRemoveCachedScanFiles() to use safe operations - Fixed vmbkendRemoveEntireCache() to use safe operations Impact: Prevents remote code execution, buffer overflow attacks, and path traversal vulnerabilities in cache management functions. Severity: CRITICAL CVE: Potential CVE candidates for command injection and buffer overflow Signed-off-by: Rajat Sharma <rajat.sharma@ibm.com>
43f7865 to
ce0821c
Compare
Bischoff
approved these changes
Jun 28, 2026
Bischoff
left a comment
Contributor
There was a problem hiding this comment.
lgtm, see "style" comments
| * Addresses CWE-787 by using bounds-checked operations | ||
| * Addresses CWE-22 by validating paths with realpath() | ||
| */ | ||
| static int safe_remove_files(const char *dirPath, const char *pattern) { |
Contributor
There was a problem hiding this comment.
Just a "philosophical" remark...
All code is supposed to be "safe"... 😸
So I don't see the point of putting "safe_" in the function names.
Similarly, I would explain what the function does first in the header comments.
The security implementation remarks can follow next.
But that's probably a matter of tastes and habits 😄 .
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
CRITICAL security fixes addressing:
CWE-78: OS Command Injection
CWE-787: Out-of-bounds Write
CWE-22: Path Traversal
Changes:
Impact: Prevents remote code execution, buffer overflow attacks, and path traversal vulnerabilities in cache management functions.
Severity: CRITICAL
CVE: Potential CVE candidates for command injection and buffer overflow