Skip to content

tool: fix error/warning messages when output filename sanitization fails - #20116

Closed
vszakats wants to merge 1 commit into
curl:masterfrom
vszakats:sanitglob
Closed

vszakats wants to merge 1 commit into
curl:masterfrom
vszakats:sanitglob

Conversation

@vszakats

@vszakats vszakats commented Dec 30, 2025 •

Copy link
Copy Markdown
Member

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:

  • tidy up messages when filename sanitization runs OOM.
  • tidy up low-level messages when the output filename fails sanitization
    on MS-DOS.

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

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: (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

Ref: #20113 #20121
Ref: 40c1748 #20198
Ref: eb7f5b7 #20143
Ref: 8c02407 #20125
Fixes #20044


  • avoid spilling the output stdout in case of a sanitization failure. (to keep existing behavior)
  • fixme one remaining output glob OOM case.

Comment thread include/curl/curl.h Outdated
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

@bagder bagder 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.

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.

Comment thread lib/strerror.c Outdated
return "ECH attempted but failed";

case CURLE_BAD_FILENAME:
return "Filename failed sanitization";

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 also shows how odd this error is, because libcurl has no such sanitization!

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.

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 wrapping curl_easy_strerror() into a tool_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.

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.

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.

@vszakats vszakats Dec 30, 2025 •

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.

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.

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.

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.

@vszakats vszakats Dec 30, 2025 •

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.

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.

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.

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!

@vszakats vszakats Dec 30, 2025 •

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.

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.

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.)

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.

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.

@vszakats vszakats Dec 31, 2025 •

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.

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.

@vszakats
vszakats force-pushed the sanitglob branch 5 times, most recently from 9fa0929 to 2688f42 Compare December 30, 2025 16:35
@vszakats
vszakats marked this pull request as draft December 30, 2025 19:10
@vszakats
vszakats marked this pull request as ready for review December 31, 2025 00:28
@vszakats
vszakats requested review from bagder and Copilot December 31, 2025 00:29
@vszakats
vszakats removed the request for review from bagder December 31, 2025 00:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 CURLtcode enum with CURLTE_BAD_FILENAME error code and tool_strerror() function for error message handling
  • Modified glob_match_url() and get_url_file_name() to set config->tresult and return appropriate error codes when sanitization fails
  • Added debug environment variables CURL_FN_SANITIZE_BAD and CURL_FN_SANITIZE_OOM to 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.

Comment thread src/tool_operhlp.c Resolved
Comment thread src/tool_operate.c Resolved
Comment thread src/tool_operate.c Resolved
Comment thread src/tool_doswin.c Resolved
Comment thread src/tool_operhlp.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/tool_operate.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@jay

jay commented Dec 31, 2025

Copy link
Copy Markdown
Member

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

@vszakats

Copy link
Copy Markdown
Member Author

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.

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.

@vszakats

vszakats commented Dec 31, 2025 •

Copy link
Copy Markdown
Member Author

@jay: with #20121 applied on master, here are the test outputs,
To my eye it doesn't fix the confusing messaging that this PR fixes:

$ 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: filename or path invalid (too long?): "out.txt"
Warning: bad output glob
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: 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
Warning: filename or path invalid (too long?): "index.html"
curl: Failed to extract a filename from the URL to use for storage
curl: (43) A libcurl function was given a bad argument

vszakats added a commit to vszakats/curl that referenced this pull request Dec 31, 2025
vszakats added a commit that referenced this pull request Dec 31, 2025
- `CURL_FN_SANITIZE_BAD=<any-value>` to simulate
  `SANITIZE_ERR_INVALID_PATH`.

- `CURL_FN_SANITIZE_OOM=<any-value>` to simulate
  `SANITIZE_ERR_OUT_OF_MEMORY`.

Both are Windows/MS-DOS-specific and require debug-enabled curl build.

Cherry-picked from #20116
Closes #20125
@vszakats
vszakats force-pushed the sanitglob branch 3 times, most recently from a9c6ecd to 50f7762 Compare January 4, 2026 10:38
@vszakats vszakats changed the title tool: use distinct error when output filename fails sanitization tool: fix error/warning messages when output filename fails sanitization Jan 4, 2026
@vszakats vszakats changed the title tool: fix error/warning messages when output filename fails sanitization tool: improve error/warning messages when output filename fails sanitization Jan 4, 2026
@bagder

bagder commented Jan 6, 2026

Copy link
Copy Markdown
Member

In the code right now, SANITIZE_ERR_INVALID_PATH is no longer returned at all on Windows, only on MS-DOS.

Combined with the fact that out of memory is so extremely rare maybe we can now actually go with #20113 for simplicity?

@vszakats

vszakats commented Jan 6, 2026 •

Copy link
Copy Markdown
Member Author

In the code right now, SANITIZE_ERR_INVALID_PATH is no longer returned at all on Windows, only on MS-DOS.

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
which also applies to Windows. It also doesn't fix it for MS-DOS, which
curl still supports.

IMO there is also value in supporting non-libcurl error codes in
other places in code, that's another reason I kept working on this.

With #20113, the messages look like this:

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

$ CURL_FN_SANITIZE_BAD=1 wine curl.exe https://curl.se/ --output out.txt
Warning: bad output filename
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
  1. says the wrong error, and shows an unnecessary/confusing message before. (MS-DOS/Windows)
  2. shows two contardicting messages. (MS-DOS)
  3. shows an unnecessary/confiusing message before the real one. (MS-DOS/Windows)
  4. two confusing messages. (MS-DOS)

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.

vszakats added a commit to vszakats/curl that referenced this pull request Jan 6, 2026
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
vszakats added a commit that referenced this pull request Jan 6, 2026
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
```
vszakats added a commit to vszakats/curl that referenced this pull request Jan 6, 2026
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
@vszakats

vszakats commented Jan 6, 2026 •

Copy link
Copy Markdown
Member Author

A smaller take here (+12 lines), which does the same as this one,
except the final error message is not tool-specific, but libcurl code 43:
#20199

@vszakats vszakats changed the title tool: improve error/warning messages when output filename fails sanitization tool: fix error/warning messages when output filename fails sanitization Jan 6, 2026
@vszakats vszakats changed the title tool: fix error/warning messages when output filename fails sanitization tool: fix error/warning messages when output filename sanitization fails Jan 6, 2026
vszakats added a commit to vszakats/curl that referenced this pull request Jan 7, 2026
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
@vszakats

vszakats commented Jan 9, 2026

Copy link
Copy Markdown
Member Author

Closing in favor of #20199, which is short/ligher, less complete fix, but enough for the purpose.

@vszakats vszakats closed this Jan 9, 2026
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
@vszakats
vszakats deleted the sanitglob branch January 18, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

misleading/wrong error when using long output filename on Windows

4 participants