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 issue 24549 - std.process.environment.get(null) segfaults #9002

Merged
merged 1 commit into from
May 16, 2024

Conversation

schveiguy
Copy link
Member

The true fix I think would b to make it so tempCString never returns null (it doesn't make a lot of sense). But the code was clearly intended to work this way, and was set up because of a long ago regression.

Even if that problem is eventually fixed, this fix is not invalidated.

@dlang-bot
Copy link
Contributor

dlang-bot commented May 14, 2024

Thanks for your pull request, @schveiguy!

Bugzilla references

Auto-close Bugzilla Severity Description
24549 normal std.process.environment.get(null) segfaults

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "stable + phobos#9002"

@CyberShadow
Copy link
Member

Would it more correct to do something like if (!name) name = ""; ?

@Geod24 Geod24 changed the title Fix issue 24549 Fix issue 24549 - std.process.environment.get(null) segfaults May 14, 2024
@Geod24
Copy link
Member

Geod24 commented May 14, 2024

Won't this lead to a different behavior between get(null) and get("") ?

@schveiguy
Copy link
Member Author

schveiguy commented May 14, 2024

Would it more correct to do something like if (!name) name = ""; ?

I think in this case, it doesn't matter -- I don't think an empty string is a valid environment variable name.

@Geod24
Copy link
Member

Geod24 commented May 14, 2024

I don't think an empty string is a valid environment variable name.

Yes, but the distinction between empty string and null is a common gotcha.

@schveiguy
Copy link
Member Author

There are many ways to solve this. I think if we are going to do a check for null anyway, we might as well circumvent the entire process. Why call an opaque C function when we know it's going to return "variable not found"?

@schveiguy
Copy link
Member Author

All green now. Would be nice to get this in the next release...

@dlang-bot dlang-bot merged commit 82e8e32 into dlang:stable May 16, 2024
10 checks passed
@schveiguy schveiguy deleted the fix24549 branch May 16, 2024 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants