Skip to content

Add lock to Core::SystemInfo::(Get/Set)Environment #2104

Open
nxtum wants to merge 10 commits intordkcentral:masterfrom
nxtum:getsetEnviromentLock
Open

Add lock to Core::SystemInfo::(Get/Set)Environment #2104
nxtum wants to merge 10 commits intordkcentral:masterfrom
nxtum:getsetEnviromentLock

Conversation

@nxtum
Copy link
Copy Markdown
Contributor

@nxtum nxtum commented Apr 28, 2026

Not all libc implementation protect parallel usage of getenv and setenv

Copilot AI review requested due to automatic review settings April 28, 2026 11:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds synchronization around Core::SystemInfo::{GetEnvironment,SetEnvironment} to avoid unsafe parallel getenv/setenv usage on some libc implementations.

Changes:

  • Introduced a file-scope CriticalSection intended to protect environment access.
  • Wrapped Linux getenv() and setenv()/unsetenv() calls with SafeSyncType<CriticalSection>.

Comment thread Source/core/SystemInfo.cpp
@nxtum nxtum requested a review from sebaszm April 28, 2026 11:10
Copy link
Copy Markdown
Contributor

@sebaszm sebaszm left a comment

Choose a reason for hiding this comment

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

The problem is not only being setenv getenv not thread safe, but also the combination "getenv then setenv" is susceptible to race (so also the widows case needs a lock on set).

Please review the possibility of using getenv_s ( STDC_LIB_EXT1 ).

Also please check the return value of setenv I think it's -1/0 not true/false.

Copilot AI review requested due to automatic review settings April 29, 2026 11:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread Source/core/SystemInfo.cpp
Copilot AI review requested due to automatic review settings May 4, 2026 07:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread Source/core/SystemInfo.cpp Outdated
Comment thread Source/core/SystemInfo.cpp Outdated
Comment thread Source/core/SystemInfo.cpp Outdated
Copilot AI review requested due to automatic review settings May 4, 2026 07:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

/* static */ bool SystemInfo::SetEnvironment(const string& name, const TCHAR* value, const bool forced)
{
bool result = false;
SafeSyncType<CriticalSection> scopedLock(_lock);
Comment on lines +388 to +394
ASSERT(characters < capacity);
if (characters > 0) {
value.assign(buffer, characters);
} else {
value.clear();
}
return (characters > 0);
Comment on lines +388 to +390
ASSERT(characters < capacity);
if (characters > 0) {
value.assign(buffer, characters);
@sebaszm sebaszm self-requested a review May 4, 2026 09:41
Comment thread Source/core/SystemInfo.cpp Outdated
Copilot AI review requested due to automatic review settings May 4, 2026 11:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment on lines +388 to +390
ASSERT(characters < capacity);
if (characters > 0) {
value.assign(buffer, characters);
/* static */ bool SystemInfo::SetEnvironment(const string& name, const TCHAR* value, const bool forced)
{
bool result = false;
SafeSyncType<CriticalSection> scopedLock(_lock);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants