Skip to content
Memory corruption Disclosed report Advanced

Off-by-One Buffer Overflow in SMB Path Handler

An off-by-one buffer overflow exists in curl's SMB path handler because the bounds check uses '>' instead of '>='. A path of exactly 1023 bytes passes the check and then strcpy writes one byte past the 1024-byte buffer.

pelioro Follow

Originally disclosed on HackerOne

  • Disclosed after 3 hours

Summary

Found an off-by-one buffer overflow in lib/smb.c when handling SMB file paths. The bounds check uses > instead of >=, allowing a path of exactly 1023 bytes to overflow the 1024-byte buffer by one byte when the null terminator is added.

Details

File: lib/smb.c
Function: smb_send_open()
Lines: 784, 801

The Bug

C
struct smb_nt_create {
    // ... other fields ...
    char bytes[1024];  // fixed size buffer
} PACK;

static CURLcode smb_send_open(...) {
    struct smb_nt_create msg;
    const size_t byte_count = strlen(req->path) + 1;
    
    if(byte_count > sizeof(msg.bytes))  // Wrong: should be >=
        return CURLE_FILESIZE_EXCEEDED;
    
    // ... setup code ...
    
    strcpy(msg.bytes, req->path);  // Overflow when byte_count == 1024
}

The Math

  • Buffer size: 1024 bytes
  • Check allows: byte_count <= 1024 (because > not >=)
  • If path is 1023 bytes:
    • strlen(req->path) = 1023
    • byte_count = 1024
    • Check: 1024 > 1024 = FALSE (passes)
    • strcpy() writes 1024 bytes + null = 1025 bytes
    • Overflow by 1 byte

Testing

Built curl with ASan to verify:

Bash
./configure --with-openssl --enable-smb --enable-debug \
  CFLAGS="-fsanitize=address"
make

SMB support confirmed:

$ ./src/curl --version | grep smb
Protocols: ... smb smbs ...

Note: Couldn't trigger the crash in testing because it requires an actual SMB connection, but the bug is visible in the code.

Fix

Two changes needed:

Diff
- if(byte_count > sizeof(msg.bytes))
+ if(byte_count >= sizeof(msg.bytes))
    return CURLE_FILESIZE_EXCEEDED;

- strcpy(msg.bytes, req->path);
+ memcpy(msg.bytes, req->path, byte_count);

Notes

  • Tested on curl master branch
  • SMB support must be compiled in
  • Bug is in release builds, not debug-only
  • Manual code review, no AI used

This is a real bug that should be fixed, even though exploitation is unlikely.

Impact

  • Memory corruption (1 byte past buffer)
  • Likely causes crash
  • RCE unlikely (off-by-one is hard to exploit)
  • Affects any app using libcurl with SMB

The original report as published on HackerOne, by pelioro. 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

The size check uses '>' instead of '>=' so a byte_count equal to the buffer size is accepted, and strcpy then writes the null terminator one byte past the end.

Impact

A one-byte memory corruption past the buffer could cause a crash, though remote code execution is unlikely and the author could not trigger it without a real SMB connection.

What the attacker needed

Curl built with SMB support; an SMB server connection; a path of exactly 1023 bytes

The fix

The check should use '>=' and the copy should use memcpy with the computed byte count.

How it was found

  1. Build curl with SMB support and AddressSanitizer enabled.
  2. Confirm SMB is listed in the build's supported protocols.
  3. Attempt to trigger the overflow over an actual SMB connection (not achieved in testing).

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.

A buffer is a fixed-size space in memory. The code checks whether the path fits, but the check is off by one: a path that is exactly the maximum allowed size still gets copied in, and the extra null terminator at the end spills one byte past the buffer. That single stray byte can corrupt nearby memory and crash the program.

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 by pelioro

View all

3 more disclosed reports, best first.

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.