Skip to content

tool_operate: improve the error message for bad output file name - #20113

Closed
bagder wants to merge 1 commit into
masterfrom
bagder/glob-output
Closed

bagder wants to merge 1 commit into
masterfrom
bagder/glob-output

Conversation

@bagder

@bagder bagder commented Dec 29, 2025 •

Copy link
Copy Markdown
Member

if for example sanitize_file_name deems it bad, saying bad output filename seems much better than bad output glob.

Reported-by: Viktor Szakats
Ref: #20044

@bagder
bagder marked this pull request as ready for review December 29, 2025 22:10
if for example sanitize_file_name deems it bad, saying `bad output file
name` seems much better than `bad output glob`.

Reported-by: Viktor Szakats
Ref: #20044
Closes #20113
@bagder
bagder force-pushed the bagder/glob-output branch from 44df221 to 5ee4c4d Compare December 29, 2025 22:19
@testclutch

Copy link
Copy Markdown

Analysis of PR #20113 at 5ee4c4d5:

Test ../../tests/http/test_07_upload.py::TestUpload::test_07_70_put_earlydata[h3-limited-body] failed, but it has been 0.6% flaky lately, so it's probably NOT a fault of the PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them).

Generated by Testclutch

Comment thread src/tool_operate.c
if(result) {
/* bad globbing */
warnf("bad output glob");
warnf("bad output filename");

@vszakats vszakats Dec 30, 2025 •

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.

This fixes the sanitizer case, but would this also be accurate
for real globbing and URL issues returned by glob_match_url()?

It can return CURLE_FAILED_INIT, CURLE_OUT_OF_MEMORY,
also CURLE_TOO_LARGE via dynbuf. Only CURLE_URL_MALFORMAT
means that the sanitizier found an issue in the output filename. (and not
in the URL / globbing.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I believe it is still a better error message. It explains that the problem is with the filename, which previously was not easy to understand.

@vszakats vszakats Dec 30, 2025 •

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.

Definitely better for the filename case, but may be confusing to see 'filename' in the unlikely case of a failure dealing with the input URL:

Output when glob_match_url returns CURLE_OUT_OF_MEMORY:

$ ./curl 'https://curl.se/[0-1]' --output out.out
Warning: bad output filename
curl: (27) Out of memory

Also the CURLE_URL_MALFORMAT code returned is weird in the filename case,
because the error isn't with the URL. It'd probably need a new error code.

PR attempting to fix both, and one more corner case: #20116

@jay

jay commented Dec 31, 2025

Copy link
Copy Markdown
Member

See #20121 for a different way. The sanitizer should only fail if the path is too long so I'm proposing a warning specifically for that in the sanitizer. The way in this PR may have problems which Viktor already mentioned and that it should be left as a bad glob message

@bagder bagder closed this Jan 10, 2026
@bagder
bagder deleted the bagder/glob-output branch January 10, 2026 11:40
vszakats added a commit that referenced this pull request Jan 10, 2026
…n fails

On MS-DOS (OOM and bad filename) and Windows (OOM only).

Given the rarity of both platform and error, we make a compromise and
return an unrelated libcurl error (43) in case of a bad output filename
on MS-DOS.

After:
```
$ CURL_FN_SANITIZE_OOM=1 wine curl.exe https://curl.se/ --output out.txt
curl: (27) Out of memory

$ CURL_FN_SANITIZE_BAD=1 wine curl.exe https://curl.se/ --output out.txt
Warning: bad output filename
curl: (43) A libcurl function was given a bad argument

$ CURL_FN_SANITIZE_OOM=1 wine curl.exe https://curl.se/index.html --globoff -O
curl: (27) Out of memory

$ CURL_FN_SANITIZE_BAD=1 wine curl.exe https://curl.se/index.html --globoff -O
curl: bad output filename
curl: (43) A libcurl function was given a bad argument
```

Before:
```
$ CURL_FN_SANITIZE_OOM=1 wine curl.exe https://curl.se/ --output out.txt
Warning: bad output glob
curl: (27) Out of memory

$ CURL_FN_SANITIZE_BAD=1 wine curl.exe https://curl.se/ --output out.txt
Warning: bad output glob
curl: (3) URL using bad/illegal format or missing URL

$ CURL_FN_SANITIZE_OOM=1 wine curl.exe https://curl.se/index.html --globoff -O
curl: Failed to extract a filename from the URL to use for storage
curl: (27) Out of memory

$ CURL_FN_SANITIZE_BAD=1 wine curl.exe https://curl.se/index.html --globoff -O
curl: Failed to extract a filename from the URL to use for storage
curl: (3) URL using bad/illegal format or missing URL
```

Ref: #20116 (simpler reboot of)
Ref: #20113 #20121
Ref: 40c1748 #20198
Ref: eb7f5b7 #20143
Ref: 8c02407 #20125
Fixes #20044
Closes #20199
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants