Skip to content

fix: upper case all env vars on Windows#161

Merged
ddneilson merged 1 commit intoOpenJobDescription:mainlinefrom
edwards-aws:edwards_fix_windows_casing
Aug 7, 2024
Merged

fix: upper case all env vars on Windows#161
ddneilson merged 1 commit intoOpenJobDescription:mainlinefrom
edwards-aws:edwards_fix_windows_casing

Conversation

@edwards-aws
Copy link
Copy Markdown
Contributor

@edwards-aws edwards-aws commented Aug 2, 2024

Fixes: #157

What was the problem/requirement? (What/Why)

We've observed on Windows systems that even though environment variables are case insensitive, the win32 API will allow duplicate environment variables with different casing. This causes issues as openjd reads in user environment variables via Python, which uppercases all environment variables it reads in on Windows. If there already existed an environment variable in the system that wasn't uppercased, say Path, and openjd reads in a variable it needs to update, say PATH. The win32 API will accept both. This leads to undefined behaviour when Windows accesses that environment variable

What was the solution? (How)

Upper case all environment variables that come into openjd on Windows, whether it's through the win32 API or openjd.

What is the impact of this change?

Paths added by printing openjd_env: key=value should override environment variables as expected, regardless of casing.

How was this change tested?

I've added unit tests that ensure that the environment variables are all converted to upper case as expected and that variables are overwritten as expected regardless of casing.

Was this change documented?

N/A, but I've also added some dev documentation to make running the impersonation tests on Windows easier.

Is this a breaking change?

N/A

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@edwards-aws edwards-aws requested a review from a team as a code owner August 2, 2024 22:30
@edwards-aws edwards-aws force-pushed the edwards_fix_windows_casing branch from 8cc6aa7 to 73f99df Compare August 2, 2024 22:35
@edwards-aws edwards-aws changed the title fix: upper case all env vars on Windows (#157) fix: upper case all env vars on Windows Aug 2, 2024
crowecawcaw
crowecawcaw previously approved these changes Aug 2, 2024
Copy link
Copy Markdown

@crowecawcaw crowecawcaw left a comment

Choose a reason for hiding this comment

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

Looks like the description of testing in the PR description is missing some text, but tests look thorough to me!

@edwards-aws
Copy link
Copy Markdown
Contributor Author

Thanks for pointing that out Stephen! I've updated the PR text!

@ddneilson ddneilson self-requested a review August 6, 2024 15:15
Copy link
Copy Markdown
Contributor

@ddneilson ddneilson left a comment

Choose a reason for hiding this comment

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

Thanks for the work, Cody. It looks like there's a linter issue that needs resolving, and a left-over debugging print statement. Otherwise, this looks great!

Comment thread test/openjd/sessions/test_subprocess.py Outdated
Comment thread test/openjd/sessions/test_subprocess.py Outdated
@edwards-aws edwards-aws force-pushed the edwards_fix_windows_casing branch 2 times, most recently from 36db590 to b4fd005 Compare August 7, 2024 00:21
Problem:
We've observed on Windows systems that even though environment variables
are case insensitive, the win32 API will allow duplicate environment
variables with different casing. This causes issues as openjd reads in
user environment variables via Python, which uppercases all environment
variables it reads in on Windows. If there already existed an
environment variable in the system that wasn't uppercased, say Path, and
openjd reads in a variable it needs to update, say PATH. The win32 API
will accept both. This leads to undefined behaviour when Windows
accesses that environment variable

Solution:
Upper case all environment variables that come into openjd on Windows,
whether it's through the win32 API or openjd.

Signed-off-by: Cody Edwards <edwards@amazon.com>
@edwards-aws edwards-aws force-pushed the edwards_fix_windows_casing branch from b4fd005 to af3cb52 Compare August 7, 2024 00:53
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Aug 7, 2024

}
}"""

def _inject_value_to_user_dict(block: c_void_p) -> dict[str, str]:

Check failure

Code scanning / CodeQL

Potentially uninitialized local variable

Local variable 'c_void_p' may be used before it is initialized.
@ddneilson ddneilson enabled auto-merge (squash) August 7, 2024 14:07
@ddneilson ddneilson merged commit de03049 into OpenJobDescription:mainline Aug 7, 2024
This was referenced Aug 12, 2024
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.

Bug: Duplicate Environment Variables on Windows

4 participants