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

Fix #7047 Safely handle setlocale #8735

Merged
merged 2 commits into from Jul 8, 2021

Commits on Jul 5, 2021

  1. fix protocolbuffers#7074 Safely handle setlocale

    `setlocale` returns a pointer to a buffer containing the current locale name.
    This needs to be copied into a `std::string` or it will be overwritten by the next call.
    
    Trying to call `setlocale` with a non-null, invalid pointer can have unpredictable results, such as
    ```
    [ RUN      ] StringPrintfTest.Multibyte
    minkernel\crts\ucrt\src\appcrt\convert\mbstowcs.cpp(246) : Assertion failed: (pwcs == nullptr && sizeInWords == 0) || (pwcs != nullptr && sizeInWords > 0)
    ```
    
    `setlocale` can also return a `nullptr` if it fails, but we assert against that.
    florin-crisan committed Jul 5, 2021
    Copy the full SHA
    039bc2c View commit details
    Browse the repository at this point in the history
  2. stringprintf_unittest.cc: Replace new char[n+1] with std::array

    Prefer safer alternative to naked pointers.
    
    This is a follow-up to 1dd313c
    florin-crisan committed Jul 5, 2021
    Copy the full SHA
    64cb893 View commit details
    Browse the repository at this point in the history