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

strerror: use sys_errlist instead of strerror on Windows #7735

Closed
wants to merge 1 commit into from

Conversation

@jay
Copy link
Member

@jay jay commented Sep 17, 2021

  • Change Curl_strerror to use sys_errlist[errnum] instead of strerror to
    retrieve the error message on Windows.

Windows' strerror writes to a static buffer and is not thread-safe.

Follow-up to 2f0bb86 which removed most instances of strerror in favor
of calling Curl_strerror (which calls strerror_r for other platforms).

Ref: #7685
Ref: 2f0bb86

Closes #xxxx

@jay jay added the Windows label Sep 17, 2021
- Change Curl_strerror to use sys_errlist[errnum] instead of strerror to
  retrieve the error message on Windows.

Windows' strerror writes to a static buffer and is not thread-safe.

Follow-up to 2f0bb86 which removed most instances of strerror in favor
of calling Curl_strerror (which calls strerror_r for other platforms).

Ref: curl#7685
Ref: curl@2f0bb86

Closes #xxxx
@jay jay force-pushed the win_stop_using_strerror branch from e2f4a3f to b8d9a72 Sep 17, 2021
bagder
bagder approved these changes Sep 17, 2021
Copy link
Member

@bagder bagder left a comment

👍

Copy link
Member

@MarcelRaad MarcelRaad left a comment

👍

@jay jay closed this in b0eda8d Sep 17, 2021
@jay jay deleted the win_stop_using_strerror branch Sep 17, 2021
@mback2k
Copy link
Member

@mback2k mback2k commented Sep 17, 2021

@jay it seems like Microsoft deprecated direct access to sys_errlist, see: https://docs.microsoft.com/en-us/cpp/c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr

Direct access to _sys_errlist and _sys_nerr is deprecated for code-security reasons. We recommend that you use the more secure, functional versions instead of the global macros, as shown here: ...

@jay
Copy link
Member Author

@jay jay commented Sep 17, 2021

Yes that's right however it's in all versions of the CRT and strerror_s is not.

@mback2k
Copy link
Member

@mback2k mback2k commented Sep 17, 2021

Yes that's right however it's in all versions of the CRT and strerror_s is not.

Okay, what do you think about checking for the availability of strerror_s and using that if available?

@jay
Copy link
Member Author

@jay jay commented Sep 17, 2021

I'm not aware of runtime checks for CRT functions so it would require a compile time check. The documentation does not say when the function was introduced. Frankly I don't think some of these "deprecations" from MS are true, like we're not going to stop using strncpy for strncpy_s or any of the other functions for the _s series. So I appreciate the point if you want to make a PR for strerror_s I won't object I just think it's sufficient as is.

@jay
Copy link
Member Author

@jay jay commented Sep 17, 2021

Note also how they define deprecated: In this context, "deprecated" means using the function's isn't recommended. It doesn't mean the function is scheduled to be removed from the CRT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants