Skip to content

formdata: reject NULL filename and buffer name options - #23534

Closed
Huge wants to merge 1 commit into
curl:masterfrom
Huge:fix/formadd-null-filenames
Closed

Huge wants to merge 1 commit into
curl:masterfrom
Huge:fix/formadd-null-filenames

Conversation

@Huge

@Huge Huge commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

CURLFORM_FILENAME and CURLFORM_BUFFER share a branch that evaluates strlen(avalue) without checking whether the argument is NULL. The public header documents CURL_FORMADD_NULL for a NULL char pointer.

This check returns CURL_FORMADD_NULL before evaluating strlen(). Also add regression checks in tests/libtest/lib1308.c to exercise both options.


Vulnerability identified by BudgetScan static analysis.

Return CURL_FORMADD_NULL before evaluating strlen on the option.
Exercise both options in the existing formpost test.

Reported-by: BS.ehlas.cz
@github-actions github-actions Bot added the tests label Oct 21, 2026
@testclutch

Copy link
Copy Markdown

Analysis of PR #23534 at d9f4a12a:

Test ../../tests/http/test_02_download.py::TestDownload::test_02_33_max_host_conns[False-0-h2] failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them). Note that this CI job has had a number of other flaky tests recently (2, to be specific) so it may be that this failure is rather a systemic issue with this job and not with this specific PR.

Test 707 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 4 different CI jobs (the link just goes to one of them). Note that this CI job has had a number of other flaky tests recently (3, to be specific) so it may be that this failure is rather a systemic issue with this job and not with this specific PR.

Generated by Testclutch

@bagder bagder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think the documentation actually allows a NULL there, but I'm fine with checking anyway as a service.

Copilot AI 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.

🟢 Approval recommended

The focused guard prevents the NULL dereference, preserves existing error handling, and includes regression checks for both affected options.

No open issues 🎉

What changed in this PR

This PR fixes NULL-pointer handling in the legacy form API, returning the documented error instead of passing NULL to strlen().

Changes:

  • Return CURL_FORMADD_NULL for NULL CURLFORM_FILENAME and CURLFORM_BUFFER arguments.
  • Add regression checks for both options.
File Description
tests/​libtest/​lib1308.c Tests that both NULL arguments return CURL_FORMADD_NULL.
lib/​formdata.c Checks for NULL before processing the filename.

Review effort: Balanced

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

Labels

Development

Successfully merging this pull request may close these issues.

4 participants