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

os:getenv/1 incorrectly handles environment variables with trailing = #9401

Closed
saveman71 opened this issue Feb 6, 2025 · 2 comments
Closed
Labels
bug Issue is reported as a bug

Comments

@saveman71
Copy link

saveman71 commented Feb 6, 2025

Describe the Bug

Erlang's os:getenv/1 function fails to correctly retrieve environment variables when their value contains a trailing equals sign (=). This common with base64 encoded secrets (paddingà.

This issue affects both Erlang and Elixir.


To Reproduce

  1. Set an environment variable that contains a trailing equals sign (=):

    export HELLO="WORLD="
  2. Verify that the variable is correctly set:

    echo "$HELLO"
    WORLD=
  3. Attempt to retrieve the variable using Erlang:

    erl -eval 'io:format("~s~n", [os:getenv("HELLO")]).' -noshell
    false

Expected Behavior
Erlang's os:getenv/1 should correctly return the environment variable's full value, including any trailing = characters, only null bytes are invalid.

Other programming languages, such as Python and Bash, handle this correctly:

  • Python:

    python -c "import os; print(os.getenv('HELLO', ''))"
    WORLD=
  • Bash:

    echo "$HELLO"
    WORLD=

Would appreciate any insights regarding this behavior!

Affected versions
27 (I assume all versions prior)

@saveman71 saveman71 added the bug Issue is reported as a bug label Feb 6, 2025
@garazdawi
Copy link
Contributor

What OS are you using? The above reproduction works as it should on Ubuntu Linux.

> export HELLO="WORLD="
> echo "$HELLO"
WORLD=
> erl -eval 'io:format("~s~n", [os:getenv("HELLO")]).' -noshell
WORLD=

@saveman71
Copy link
Author

saveman71 commented Feb 6, 2025

You're absolutely right, after having a look at it again, the culprit seems to be ASDF.

sh-5.2$ .asdf/installs/erlang/27.2/bin/erl -eval 'io:format("~s~n", [os:getenv("HELLO")]).' -noshell
WORLD=
sh-5.2$ erl -eval 'io:format("~s~n", [os:getenv("HELLO")]).' -noshell
false

sorry for the noise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug
Projects
None yet
Development

No branches or pull requests

2 participants