Skip to content

fix: NULL pointer dereference in multipart parser (GHSA-8m8p-vhxc-jmjw)#450

Merged
mathieucarbou merged 1 commit into
mainfrom
security/advisories/GHSA-8m8p-vhxc-jmjw
Jun 28, 2026
Merged

fix: NULL pointer dereference in multipart parser (GHSA-8m8p-vhxc-jmjw)#450
mathieucarbou merged 1 commit into
mainfrom
security/advisories/GHSA-8m8p-vhxc-jmjw

Conversation

@mathieucarbou

Copy link
Copy Markdown
Member

Fix for security advisory: GHSA-8m8p-vhxc-jmjw

When the multipart parser matched '--' inside file data, it freed _itemBuffer but left _itemIsFile = true. If the next byte was neither the closing '--' nor a clean '\r\n', the rewind logic in DASH3_OR_RETURN2 / EXPECT_FEED2 called itemWriteByte(), which dereferenced the now-NULL _itemBuffer via _handleUploadByte, causing a StoreProhibited crash on ESP32 (remote DoS, CWE-476 / CWE-672).

Fix:

  • Reset _itemIsFile = false immediately after freeing _itemBuffer in BOUNDARY_OR_DATA, so the rewind logic writes to _itemValue (String) instead of the freed buffer.
  • Add a NULL guard in _handleUploadByte as defense-in-depth.

Added test case 11 in MultiPart.ino to reproduce and verify the fix.

When the multipart parser matched '--<boundary>' inside file data, it
freed _itemBuffer but left _itemIsFile = true.  If the next byte was
neither the closing '--' nor a clean '\r\n', the rewind logic in
DASH3_OR_RETURN2 / EXPECT_FEED2 called itemWriteByte(), which dereferenced
the now-NULL _itemBuffer via _handleUploadByte, causing a StoreProhibited
crash on ESP32 (remote DoS, CWE-476 / CWE-672).

Fix:
- Reset _itemIsFile = false immediately after freeing _itemBuffer in
  BOUNDARY_OR_DATA, so the rewind logic writes to _itemValue (String)
  instead of the freed buffer.
- Add a NULL guard in _handleUploadByte as defense-in-depth.

Added test case 11 in MultiPart.ino to reproduce and verify the fix.

@willmmiles willmmiles left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@mathieucarbou mathieucarbou merged commit 21305e1 into main Jun 28, 2026
37 of 38 checks passed
@mathieucarbou mathieucarbou deleted the security/advisories/GHSA-8m8p-vhxc-jmjw branch June 28, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants