mirror of
https://github.com/curl/curl.git
synced 2026-08-25 06:03:32 +03:00
tool: improve error/warning messages when output filename sanitization 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:40c1748af5#20198 Ref:eb7f5b71e5#20143 Ref:8c02407bef#20125 Fixes #20044 Closes #20199
This commit is contained in:
parent
3e1179a695
commit
2465f7c61d
8 changed files with 43 additions and 31 deletions
|
|
@ -637,10 +637,11 @@ CURLcode glob_next_url(char **globbed, struct URLGlob *glob)
|
|||
#define MAX_OUTPUT_GLOB_LENGTH (1024 * 1024)
|
||||
|
||||
CURLcode glob_match_url(char **output, const char *filename,
|
||||
struct URLGlob *glob)
|
||||
struct URLGlob *glob, SANITIZEcode *sc)
|
||||
{
|
||||
struct dynbuf dyn;
|
||||
*output = NULL;
|
||||
*sc = SANITIZE_ERR_OK;
|
||||
|
||||
curlx_dyn_init(&dyn, MAX_OUTPUT_GLOB_LENGTH);
|
||||
|
||||
|
|
@ -700,15 +701,11 @@ CURLcode glob_match_url(char **output, const char *filename,
|
|||
#if defined(_WIN32) || defined(MSDOS)
|
||||
{
|
||||
char *sanitized;
|
||||
SANITIZEcode sc = sanitize_file_name(&sanitized, curlx_dyn_ptr(&dyn),
|
||||
(SANITIZE_ALLOW_PATH |
|
||||
SANITIZE_ALLOW_RESERVED));
|
||||
*sc = sanitize_file_name(&sanitized, curlx_dyn_ptr(&dyn),
|
||||
SANITIZE_ALLOW_PATH | SANITIZE_ALLOW_RESERVED);
|
||||
curlx_dyn_free(&dyn);
|
||||
if(sc) {
|
||||
if(sc == SANITIZE_ERR_OUT_OF_MEMORY)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
return CURLE_URL_MALFORMAT;
|
||||
}
|
||||
if(*sc)
|
||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
*output = sanitized;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue