Repository navigation
Conversation
A CURLU handle with only the scheme set to "file" has no path. Getting CURLUPART_PATH returns "/" for it, but getting CURLUPART_URL passed the NULL path to the %s in file_url(), which gives "file://(nil)" on glibc and is undefined behavior elsewhere. Use "/" when there is no path, like the non-file branch already does. Extend test 1560 to verify.
bagder
approved these changes
Oct 24, 2026
There was a problem hiding this comment.
🟢 Approval recommended
The narrow fallback preserves existing paths and includes a regression case covering the reported failure.
No open issues 🎉
What changed in this PR
This PR fixes file URL serialization when a URL handle has no path, addressing the NULL-path output reported in #21743 without changing existing paths.
Changes:
- Use
/instead of passing a NULL path to the file URL formatter. - Add a regression case verifying that a handle with only the
filescheme returnsfile:///.
| File | Description |
|---|---|
| tests/libtest/lib1560.c | Adds coverage for a file URL handle with no path set. |
| lib/urlapi.c | Defaults a missing file URL path to / during serialization. |
Review effort: Balanced
Member
|
Thanks! |
dkarpov1970
pushed a commit
to dkarpov1970/curl
that referenced
this pull request
Nov 18, 2026
A CURLU handle with only the scheme set to "file" has no path. Getting CURLUPART_PATH returns "/" for it, but getting CURLUPART_URL passed the NULL path to the %s in file_url(), which gives "file://(nil)" on glibc and is undefined behavior elsewhere. Use "/" when there is no path, like the non-file branch already does. Extend test 1560 to verify. Closes curl#23585 Backport notes: - The release builds file:// URLs inline in urlget_url(); applied the NULL path check there. (cherry picked from commit d611ca7)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Getting the full URL from a handle that only has the scheme set to "file" prints a NULL pointer:
file_url()passesu->pathstraight to%s, and it is NULL when no path was set. GettingCURLUPART_PATHon the same handle already returns "/", and the non-file branch ofurlget_url()usesu->path ? u->path : "/", so this does the same for file URLs. On non-glibc libcs this is undefined behavior rather than a funny string.This is the "(nil)" cleanup bagder mentioned in #21743. I added a case to the set_parts list in lib1560.c (fails before, passes after) and the other URL tests still pass locally.
I found this with an AI-assisted code review and then checked it by hand on a local build.