Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves error and warning messages when output filename sanitization fails on Windows and MS-DOS platforms. It addresses misleading error messages that incorrectly referred to "output glob" issues when the actual problem was with filename sanitization. The PR propagates sanitization error codes through the call chain to enable more accurate error reporting.
Key Changes:
- Moved
SANITIZEcodeenum fromtool_doswin.htotool_sdecls.hfor broader accessibility - Modified
glob_match_url()andget_url_file_name()to accept aSANITIZEcode*output parameter - Enhanced error handling in
setup_outfile()to distinguish between out-of-memory and invalid path errors, displaying appropriate messages for each case
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tool_sdecls.h | Adds SANITIZEcode enum definition for use across tool files |
| src/tool_doswin.h | Removes SANITIZEcode enum (relocated to tool_sdecls.h) |
| src/tool_urlglob.h | Updates glob_match_url() signature to include SANITIZEcode* parameter |
| src/tool_urlglob.c | Implements sanitization error propagation in glob_match_url() |
| src/tool_operhlp.h | Updates get_url_file_name() signature to include SANITIZEcode* parameter |
| src/tool_operhlp.c | Implements sanitization error propagation in get_url_file_name() |
| src/tool_operate.c | Adds improved error handling logic to display context-appropriate messages based on sanitization error type |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
augment review |
🤖 Augment PR SummarySummary: Improves curl tool diagnostics on Windows/MS-DOS when output filename sanitization fails, avoiding misleading “bad output glob”/URL-format errors. Changes:
Technical Notes: Sanitization failures now surface as 🤖 Was this summary useful? React with 👍 or 👎 |
| SANITIZE_ERR_LAST /* never use! */ | ||
| } SANITIZEcode; | ||
|
|
||
| SANITIZEcode sanitize_file_name(char ** const sanitized, const char *file_name, |
There was a problem hiding this comment.
tool_doswin.h now declares sanitize_file_name() using SANITIZEcode, but no longer defines that type (and this header only includes tool_setup.h). That creates an include-order dependency and looks like it could break compilation for translation units (notably MS-DOS ones) that include tool_doswin.h without having seen SANITIZEcode first.
🤖 Was this useful? React with 👍 or 👎
There was a problem hiding this comment.
Nice pick. Fix pushed. tool_doswin.h relies on its includer to include tool_cfgable.h first, but in case of tool_doswin.c this was only done for _WIN32.
(Tried to build-test it, but the DJGPP build breaks while compiling libcurl. (for unrelated reasons))
There was a problem hiding this comment.
(also nice knowing Augment works on fork branches now?)
There was a problem hiding this comment.
(also nice knowing Augment works on fork branches now?)
Right, I took the liberty of testing that out on your PR as I was just told it started working today!
There was a problem hiding this comment.
The fallout is kind of not good: after the uint32_t update, printf masks mismatch, which is for some reason upsetting DJGPP (but nothing in CI). Tried using PRIu32, which'd need inttypes.h. Which is a no-go doing last minute.
There was a problem hiding this comment.
(also nice knowing Augment works on fork branches now?)
Right, I took the liberty of testing that out on your PR as I was just told it started working today!
Nice! I'll give it a spin.
|
Couldn't we just do this in two lines? The chances of the sanitizer failing now are limited to a corner case on MS-DOS. diff --git a/src/tool_operhlp.c b/src/tool_operhlp.c
index 4ad8f84..dde6e65 100644
--- a/src/tool_operhlp.c
+++ b/src/tool_operhlp.c
@@ -225,7 +225,7 @@ CURLcode get_url_file_name(char **filename, const char *url)
if(sc) {
if(sc == SANITIZE_ERR_OUT_OF_MEMORY)
return CURLE_OUT_OF_MEMORY;
- return CURLE_URL_MALFORMAT;
+ return CURLE_BAD_FUNCTION_ARGUMENT;
}
*filename = sanitized;
}
diff --git a/src/tool_urlglob.c b/src/tool_urlglob.c
index 7a0e153..cbbb850 100644
--- a/src/tool_urlglob.c
+++ b/src/tool_urlglob.c
@@ -707,7 +707,7 @@ CURLcode glob_match_url(char **output, const char *filename,
if(sc) {
if(sc == SANITIZE_ERR_OUT_OF_MEMORY)
return CURLE_OUT_OF_MEMORY;
- return CURLE_URL_MALFORMAT;
+ return CURLE_BAD_FUNCTION_ARGUMENT;
}
*output = sanitized;
return CURLE_OK; |
This also doesn't fix the misleading messages. |
This comment was marked as outdated.
This comment was marked as outdated.
Also adjust a printf mask for signedness.
Fixing with MS-DOS DJGPP gcc 12.2.0:
```
lib/conncache.c:612:22: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:394:22: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:520:20: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:520:20: error: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:611:20: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:614:22: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:887:20: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:887:20: error: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:2719:26: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:2725:30: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:2729:28: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:3126:34: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:3348:34: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:3991:28: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi_ev.c:343:24: error: format '%u' expects argument of type 'unsigned int', but argument 6 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi_ev.c:413:24: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi_ev.c:584:36: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi_ntfy.c:113:34: error: format '%d' expects argument of type 'int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi_ntfy.c:113:34: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi_ntfy.c:171:22: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'}
lib/url.c:883:22: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
lib/url.c:889:22: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'}
```
Bug: #20199 (comment)
Follow-up to 4c9e4e9 #20208
Closes #20200
In `!ssl` variant. It's useful to catch `uint32_t` mismatches with `unsigned int` or its printf mask. Also add Renovate version bump rule. It takes about 1m (autotools) + 30s (cmake) in CI. Bug: #20199 (comment) Follow-up to 8881a52 #20210 Follow-up to e70436a #20200 Follow-up to 0630e66 #18338 Closes #20204
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
| SANITIZE_ERR_BAD_ARGUMENT, /* 2 - bad function parameter */ | ||
| SANITIZE_ERR_OUT_OF_MEMORY, /* 3 - out of memory */ | ||
| SANITIZE_ERR_LAST /* never use! */ | ||
| } SANITIZEcode; |
There was a problem hiding this comment.
Why move the declaration of the SANITIZEcode ? Since it is used for return values for code in tool_doswin.c it seems logical to me to have it declared in tool_doswin.h
There was a problem hiding this comment.
With this change it's no longer a DOS/Windows-specific enum, ie any platform may use it or return it and two low-level functions now return this type on all platforms. (Though it will be an OK value on non WinDOS ones). (These are also not inherently WinDOS things.)
Moving it allows to avoid littering the code with tool_doswin includes and/or avoids adding more platform ifdefs, which I thought was the more elegant/simple way to do this. (I find minimizing platform-specific branches and code generally a good thing)
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:
Before:
Ref: #20116 (simpler reboot of)
Ref: #20113 #20121
Ref: 40c1748 #20198
Ref: eb7f5b7 #20143
Ref: 8c02407 #20125
Fixes #20044