Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows: always use curl's basename() implementation #10475

Closed
wants to merge 1 commit into from

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Feb 11, 2023

The basename() [1][2] implementation provided by mingw-w64 [3] makes assumptions about input encoding and may break with non-ASCII strings.

basename() was auto-detected with CMake, autotools and since 68fa9bf (2022-10-13), also in Makefile.mk after syncing its behaviour with the mainline build methods. A similar patch for curl-for-win broke official Windows builds earlier, in release 7.83.1_4 (2022-06-15).

This patch forces all Windows builds to use curl's internal basename() implementation to avoid such problems.

[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/basename.html
[2]: https://www.man7.org/linux/man-pages/man3/basename.3.html
[3]: https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/basename.c

Reported-by: UnicornZhang on Github
Assisted-by: Cherish98 on Github

Fixes #10261
Closes #10475

@vszakats vszakats added build Windows Windows-specific labels Feb 11, 2023
@vszakats
Copy link
Member Author

vszakats commented Feb 11, 2023

Unrelated failure while linking a test:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
    lib2305.o:lib2305.c:(.text+0x28): undefined reference to `curlx_win32_fopen'
collect2.exe: error: ld returned 1 exit status

Possibly a regression after 5a9a04d.

bagder added a commit that referenced this pull request Feb 11, 2023
Fixes a build regression.

Follow-up to 5a9a04d
Reported-by: Viktor Szakats
Ref: #10475 (comment)
@@ -838,6 +838,10 @@ int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf,
#define USE_HTTP3
#endif

#if defined(HAVE_BASENAME) && defined(WIN32)
Copy link
Member

Choose a reason for hiding this comment

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

I suggest a brief comment explaining why. Also is this a bug in mingw-w64 or is it our bug?

Copy link
Member Author

@vszakats vszakats Feb 12, 2023

Choose a reason for hiding this comment

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

Added a comment.

Sticking with the short example from #10261 (comment), this seems to be a mingw-w64 issue. But hard to say for certain without reproducing/debugging this with that exact (raw byte!) input and locale (and possibly the OS env). Also the original bug report is a slightly different case.

[ Just by eyeballing the source, there seems to be one bug at least, where the if (*refname) condition is always true, so the else branch never executes. ]

vszakats added a commit to vszakats/curl that referenced this pull request Feb 12, 2023
The `basename()` implementation provided by mingw-w64 [1] makes
assumptions about input encoding and thus may break with non-ASCII
strings.

`basename()` was auto-detected with CMake, autotools and since
68fa9bf (2022-10-13), also in
`Makefile.mk` after syncing its behaviour with the mainline build
methods. A similar patch for curl-for-win broke official Windows
builds earlier, in release 7.83.1_4 (2022-06-15).

This patch forces all Windows builds to use curl's internal
`basename()` implementation to avoid such problems.

[1]: https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/basename.c

Reported-by: UnicornZhang on Github
Assisted-by: Cherish98 on Github

Fixes curl#10261
Closes curl#10475
bagder added a commit that referenced this pull request Feb 12, 2023
Fixes a build regression.

Follow-up to 5a9a04d
Reported-by: Viktor Szakats
Ref: #10475 (comment)

Closes #10477
The `basename()` [1][2] implementation provided by mingw-w64 [3] makes
assumptions about input encoding and thus may break with non-ASCII
strings.

`basename()` was auto-detected with CMake, autotools and since
68fa9bf (2022-10-13), also in
`Makefile.mk` after syncing its behaviour with the mainline build
methods. A similar patch for curl-for-win broke official Windows
builds earlier, in release 7.83.1_4 (2022-06-15).

This patch forces all Windows builds to use curl's internal
`basename()` implementation to avoid such problems.

[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/basename.html
[2]: https://www.man7.org/linux/man-pages/man3/basename.3.html
[3]: https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/basename.c

Reported-by: UnicornZhang on Github
Assisted-by: Cherish98 on Github

Fixes curl#10261
Closes curl#10475
@vszakats vszakats closed this in 5309e32 Feb 12, 2023
@vszakats vszakats added the unicode Unicode, code page, character encoding label Feb 16, 2023
@vszakats vszakats deleted the win-no-basename branch February 28, 2023 07:49
bch pushed a commit to bch/curl that referenced this pull request Jul 19, 2023
Fixes a build regression.

Follow-up to 5a9a04d
Reported-by: Viktor Szakats
Ref: curl#10475 (comment)

Closes curl#10477
bch pushed a commit to bch/curl that referenced this pull request Jul 19, 2023
The `basename()` [1][2] implementation provided by mingw-w64 [3] makes
assumptions about input encoding and may break with non-ASCII strings.

`basename()` was auto-detected with CMake, autotools and since
68fa9bf (2022-10-13), also in
`Makefile.mk` after syncing its behaviour with the mainline build
methods. A similar patch for curl-for-win broke official Windows
builds earlier, in release 7.83.1_4 (2022-06-15).

This patch forces all Windows builds to use curl's internal
`basename()` implementation to avoid such problems.

[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/basename.html
[2]: https://www.man7.org/linux/man-pages/man3/basename.3.html
[3]: https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/basename.c

Reported-by: UnicornZhang on Github
Assisted-by: Cherish98 on Github
Reviewed-by: Daniel Stenberg

Fixes curl#10261
Closes curl#10475
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build unicode Unicode, code page, character encoding Windows Windows-specific
Development

Successfully merging this pull request may close these issues.

windows:curl -F filename error when i use chinese
3 participants