Skip to content

Security Fix: Resolve CWE-787 and CWE-22 vulnerabilities zthin-part#952

Open
Rajat-0 wants to merge 1 commit into
masterfrom
fix-cwe-787-cwe-22
Open

Security Fix: Resolve CWE-787 and CWE-22 vulnerabilities zthin-part#952
Rajat-0 wants to merge 1 commit into
masterfrom
fix-cwe-787-cwe-22

Conversation

@Rajat-0

@Rajat-0 Rajat-0 commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

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

…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>
@Rajat-0 Rajat-0 force-pushed the fix-cwe-787-cwe-22 branch from 43f7865 to ce0821c Compare June 15, 2026 17:18
@Rajat-0 Rajat-0 changed the title Security Fix: Resolve CWE-787 and CWE-22 vulnerabilities thin-part Security Fix: Resolve CWE-787 and CWE-22 vulnerabilities zthin-part Jun 16, 2026

@Bischoff Bischoff left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 😄 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants