Skip to content

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 Windows-specific 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 Compare September 17, 2021 03:53
Copy link
Member

@bagder bagder left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Member

@MarcelRaad MarcelRaad left a comment

Choose a reason for hiding this comment

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

👍

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

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

Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

4 participants