Skip to content

Make a deep copy of the returned value from setlocale #7458

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

victorshcherbakov
Copy link

When I tested this library on Linux Manjaro 6.6.85 with enabled ASAN I faced with the issue heep-use-after-free.

As I understood it's necessary to make a deep copy of the returned value from setlocale, because during the next call of this function, the returned memory can be freed.
Also https://en.cppreference.com/w/cpp/locale/setlocale recommends making a deep copy.
When I looked at the setlocale implementation in glibc 2.41 (it's a version from my system) I see that there is a chance of such behaviour (a returned memory can be freed):
https://github.com/bminor/glibc/blob/release/2.41/master/locale/setlocale.c#L395
I made such a fix and now everything is OK.

My compiler is clang 19.1.7.

Copy link
Contributor

github-actions bot commented May 19, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@victorshcherbakov
Copy link
Author

@victorshcherbakov please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

@s-perron s-perron moved this to For MSFT in HLSL Triage May 29, 2025
@s-perron s-perron requested review from tex3d and pow2clk May 29, 2025 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Status: For MSFT
Development

Successfully merging this pull request may close these issues.

1 participant