Repository navigation
Conversation
| CURLE_UNRECOVERABLE_POLL, /* 99 - poll/select returned fatal error */ | ||
| CURLE_TOO_LARGE, /* 100 - a value/data met its maximum */ | ||
| CURLE_ECH_REQUIRED, /* 101 - ECH tried but failed */ | ||
| CURLE_BAD_FILENAME, /* 102 - filename failed sanitization |
There was a problem hiding this comment.
I understand what you want, but this error code is not used by the library so it feels wrong to add it here. We must be restrictive with adding return codes.
| return "ECH attempted but failed"; | ||
|
|
||
| case CURLE_BAD_FILENAME: | ||
| return "Filename failed sanitization"; |
There was a problem hiding this comment.
This also shows how odd this error is, because libcurl has no such sanitization!
There was a problem hiding this comment.
Fair enough. Though it feels somewhat better than reusing an unrelated
libcurl error code, creating confusion.
Other options:
- reusing a different code. (couldn't spot anything fitting earlier)
- define a tool-local CURLcode (as done in tests) and use that.
This needs wrappingcurl_easy_strerror()into atool_easy_strerror()
that recognizes this code for the two calls made from src. - drop Windows/MS-DOS-specific sanitiziation and fail on open/write
like other platforms? (It would affect compatibility for systems
relying on transformations done in this function.) - sanitize just so that it doesn't fail with anything other than OOM error.
- something else?
TL;DR: tool wants to return an error that's unknown to curl, but it's
also a real error that can happen.
There was a problem hiding this comment.
We can perhaps expand config->synthetic_error to maybe get its own set of tool-specific errors that when set override result. This is not the only place where we want to return an tool error and it would just be better if we could do better error codes in the tool rather than always trying to use a library one.
There was a problem hiding this comment.
Sounds good in theory. I might need more guidance on the details.
First thought tool error codes also should be stable, and not reuse
existing obsolete codes. Compilers are picky when using values not
declared as enums, so extending CURLcode isn't possible after
all. It needs to be a different enum. With a different enum, things fell
apart and I could not figure out how to integrate synthetic_error.
I pushed the changes, but it needs more work, or a different approach.
Also found another place that needs to handle the bad filename case.
There was a problem hiding this comment.
Right, we can't extend CURLcode with tool errors as that remains a libcurl thing. I think we can probably keep returning a value from that enum as a final result for the curl tool - my thinking was more around how to extend and change the displayed error messages for various problems that are detected in the curl tool itself: to add a separate enum for tool-specific problems that we could use to generate error messages without asking libcurl for them, but still use CURLcode for the final return code.
There was a problem hiding this comment.
But, the final return code is the one processed in the upper calls and shown
to the user. I don't see how that'd work either without extending CURLcode, or
adding a parallel error code for tool-specific codes and pass that up the chain
too. The latest iteration does the latter, and with a tool-specific code set, it's
taking precedence. But it feels fragile.
Taking a step back, why is curl trying to decide which filename is valid? Where
'valid' means: not too long. I understand we don't want to create truncated
filenames, but is this still a real possibility on the Windows versions curl supports?
It may have been on Win95 (that uses MS-DOS under the hood), but that's no
longer supported. On NT systems, an invalid filename fails to open.
Deleting this check would reduce the problem to MS-DOS, which may use the
smallest possible fix, or use no fix at all.
There was a problem hiding this comment.
But, the final return code is the one processed in the upper calls and shown to the user.
Yes, but in this specific case CURLE_BAD_FUNCTION_ARGUMENT could also work, or something else. I think fixing the error message is the more valuable fix here.
why is curl trying to decide which filename is valid?
I have no idea. We don't do it for non-Windows and I don't know why that has been deemed necessary on Windows!
There was a problem hiding this comment.
But, the final return code is the one processed in the upper calls and shown to the user.
Yes, but in this specific case
CURLE_BAD_FUNCTION_ARGUMENTcould also work, or something else. I think fixing the error message is the more valuable fix here.
I'd find that error message also confusing in this case.
Assuming, that ("Warning: bad output glob") is the only
error message affected, but this error code is bubbling
up from multiple places and appears as more misleading
messages:
> curl.exe https://curl.se/ --output out.txt
Warning: bad output glob [/ filename]
curl: (3) URL using bad/illegal format or missing URL(this happens if the sanity check returns OOM error or
invalid filename.)
or here, for invalid filenames (OOM error case is fine):
> 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(simulated by making sanitize_file_name() return either
SANITIZE_ERR_INVALID_PATH or SANITIZE_ERR_OUT_OF_MEMORY
by default.)
There was a problem hiding this comment.
I'd find that error message also confusing in this case.
Yes, that's what I'm saying. It is something to fix.
My point is that the error message is the wrong/confusing thing, not necessarily the final actual return code.
There was a problem hiding this comment.
Pushed another update, with which the patch basically implements
overriding the error message (and code) with a tool-specific one, otherwise
leaving control flow on a CURLE_BAD_FUNCTION_ARGUMENT path.
Meaning it behaves just like before, but displays the correct error(s).
In addition makes a code path interpret sanitizier OOM error correctly.
9fa0929 to
2688f42
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a new tool-specific error code CURLTE_BAD_FILENAME to signal when output filenames fail sanitization on Windows and MS-DOS platforms. The change allows curl to provide more specific error messages when filename sanitization fails, replacing the previous generic CURLE_URL_MALFORMAT error.
Key changes:
- Added
CURLtcodeenum withCURLTE_BAD_FILENAMEerror code andtool_strerror()function for error message handling - Modified
glob_match_url()andget_url_file_name()to setconfig->tresultand return appropriate error codes when sanitization fails - Added debug environment variables
CURL_FN_SANITIZE_BADandCURL_FN_SANITIZE_OOMto facilitate testing
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tool_setup.h | Defines the new CURLtcode enum with CURLTE_BAD_FILENAME error code |
| src/tool_util.h | Declares the tool_strerror() function for converting tool error codes to strings |
| src/tool_util.c | Implements tool_strerror() to provide human-readable error messages for tool-specific errors |
| src/tool_cfgable.h | Adds tresult field to OperationConfig to store tool-specific error codes |
| src/tool_cfgable.c | Initializes tresult to CURLTE_OK during config allocation |
| src/tool_operhlp.h | Updates get_url_file_name() signature to accept OperationConfig parameter |
| src/tool_operhlp.c | Modifies get_url_file_name() to set tresult on sanitization failure and return error code |
| src/tool_urlglob.h | Updates glob_match_url() signature to accept OperationConfig parameter |
| src/tool_urlglob.c | Modifies glob_match_url() to set tresult and return CURLE_BAD_FUNCTION_ARGUMENT on sanitization failure |
| src/tool_operate.c | Updates error handling to check tresult and display appropriate messages using tool_strerror() |
| src/tool_doswin.c | Adds debug environment variables to simulate sanitization errors for testing |
| .github/scripts/pyspelling.words | Adds "sanitization" to the accepted words list |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This change seems unnecessary and complicated to me. I don't think we need a separate class of error codes for this. The original intent of the PR was to add an error code to CURLE, frankly even if it's currently tool-only that would be a whole lot easier to work with. But anyway I think an error message or warning would suffice. See #20121 for an alternative |
Agree, and that's what the first commit did in this PR, but was replaced because it'd be a libcurl error code not used by libcurl itself. |
|
@jay: with #20121 applied on master, here are the test outputs, |
a9c6ecd to
50f7762
Compare
|
In the code right now, Combined with the fact that out of memory is so extremely rare maybe we can now actually go with #20113 for simplicity? |
#20113 is simpler, but doesn't fix the misleading messages for OOM IMO there is also value in supporting non-libcurl error codes in With #20113, the messages look like this:
The improved (IMO) output is in PR message for comparison. One OOM case is easy to fix separately, but not the other, I think. edit: Made #20198 which fixes half of case 1. [MERGED] edit 2: This PR could be further torn apart into two pieces, one fixing the bogus glob warnings, and another potential one to display an accurate final error on MS-DOS. |
Fixing: ``` $ CURL_FN_SANITIZE_OOM=1 wine curl.exe https://curl.se/ --output out.txt Warning: bad output glob curl: (3) URL using bad/illegal format or missing URL ``` To: ``` Warning: bad output glob curl: (27) Out of memory ``` Cherry-picked from curl#20116
Make sure to convert a low-level OOM error code a libcurl one, to make the curl tool to display an accurate error code and messages. On Windows and MS-DOS. Improving: ``` $ CURL_FN_SANITIZE_OOM=1 wine curl.exe https://curl.se/ --output out.txt [...] curl: (3) URL using bad/illegal format or missing URL ``` to: ``` [...] curl: (27) Out of memory ``` Cherry-picked from #20116 Closes #20198
refer to existing version handle it one more place undo curltcode use separate range tool_urlglob.c also return a CURLcode to stay on the error path in caller code cleanup merge two branches Revert "merge two branches" This reverts commit cdb0f53. tool_operhlp.c return CURLE err fixup one remaining case ``` $ CURL_FN_SANITIZE_OOM=1 wine curl.exe https://curl.se/ --output out.txt Warning: bad output glob curl: (27) Out of memory ``` Revert "fixup one remaining case" This reverts commit b4776b5. tool_operate.c reset tresult in config glob_match_url tell the caller if the failure happened in sanitiziation Without this the caller cannot tell where an OOM happened in that call. cleanup CURLtcode move cleanups ``` $ 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: (900) Filename failed sanitization $ 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: (900) Filename failed sanitization ```
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: curl#20116
|
A smaller take here (+12 lines), which does the same as this one, |
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: curl#20116
|
Closing in favor of #20199, which is short/ligher, less complete fix, but enough for the purpose. |
…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
Add support for curl-tool-specific error codes, and allow to show them
for errors that have no libcurl
CURLE_*code.Use this capability to show an accurate message when the output filename
fails sanitization on MS-DOS.
Also:
on MS-DOS.
Before:
After:
Ref: #20113 #20121
Ref: 40c1748 #20198
Ref: eb7f5b7 #20143
Ref: 8c02407 #20125
Fixes #20044
output globOOM case.