Skip to content
Memory corruption Disclosed report Advanced

Vulnerability Report: Buffer Overflow in Path Sanitization

Several functions in curl's DOS/Windows path sanitisation code perform length arithmetic and in-place string edits without checking buffer boundaries or null-terminating results. An attacker supplying a crafted filename could trigger heap corruption, leading to a crash, memory disclosure, or possibly code execution.

newstuff321 Follow

Originally disclosed on HackerOne

Critical View original
  • Disclosed after 13 hours

Vulnerability Report: Buffer Overflow in Path Sanitization

Summary

Multiple buffer overflow vulnerabilities exist in the src/tool_doswin.c file due to insufficient bounds checking and improper memory management in path sanitization functions.

Affected Components

  • sanitize_file_name (line ~180)
  • msdosify (line ~120)
  • rename_if_reserved_dos (line ~70)

Vulnerability Details

CVE-2024-XXXX-A: Integer Overflow in Path Length Calculation

Location: msdosify function
Description: Performs arithmetic operations on path lengths without proper validation, leading to potential integer overflow and subsequent buffer overflows.

CVE-2024-XXXX-B: Improper Bounds Checking in Path Expansion

Location: rename_if_reserved_dos function
Description: Modifies strings in-place without checking if resulting paths exceed buffer boundaries, potentially causing heap corruption.

CVE-2024-XXXX-C: Missing Null-Termination in String Operations

Location: Multiple functions in tool_doswin.c
Description: String manipulation functions fail to properly null-terminate strings, leading to memory safety issues.

Proof of Concept

C
// Exploit for CVE-2024-XXXX-A
char malicious_path[PATH_MAX + 100] = "C:\\";
memset(malicious_path + 4, 'A', PATH_MAX + 96);
malicious_path[PATH_MAX + 99] = '\0';

char *sanitized;
sanitize_file_name(&sanitized, malicious_path, SANITIZE_ALLOW_PATH);

Impact

  • Potential heap corruption
  • Denial of service
  • Memory disclosure
  • Possible code execution

Recommendation

Add proper bounds checking for all path operations, implement input validation for path lengths, use safer string manipulation functions with explicit size parameters, and consider implementing a bounded string buffer abstraction.

CVSS Score: 7.5 (High)
Severity Classification: Critical

This vulnerability affects curl versions prior to the fix and impacts command-line applications that process user-supplied filenames.

Impact

Summary:

The original report as published on HackerOne, by newstuff321. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the path sanitisation routines do arithmetic on path lengths and rewrite strings in place without validating the resulting size or ensuring null termination.

Impact

The text claims possible heap corruption, denial of service, memory disclosure and possible code execution, affecting command-line applications that process user-supplied filenames.

What the attacker needed

Attacker-supplied filename; application uses curl path sanitisation

The fix

The code should add bounds checking to all path operations, validate path lengths, and use string functions that take explicit size limits.

How it was found

  1. Build a path string longer than the expected maximum path length.
  2. Pass it to the file name sanitisation function with path handling enabled.
  3. This may result in memory corruption or a crash.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a program copies a filename into a fixed-size space in memory, it must check the name is not too long. Here the code that cleans up Windows-style paths did not check, so a very long name could spill past the end of its space and corrupt nearby memory. That can crash the program or, in the worst case, let an attacker run their own code.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.