Skip to content

Unset the DYLD_LIBRARY_PATH env var when running Sorbet#820

Closed
egiurleo wants to merge 1 commit into
mainfrom
dyld-library-path
Closed

Unset the DYLD_LIBRARY_PATH env var when running Sorbet#820
egiurleo wants to merge 1 commit into
mainfrom
dyld-library-path

Conversation

@egiurleo

@egiurleo egiurleo commented Nov 20, 2025

Copy link
Copy Markdown
Contributor

There are cases where a dev environment can set the DYLD_LIBRARY_PATH env variable in a way that loads a version of the C++ standard library that is not compatible with the system version of the library used by Sorbet. This will cause Sorbet to generate corrupted JSON if the --print=symbol-table-json flag is passed. Unsetting this environment variable forces Sorbet to default to the system version of the C++ standard library, preventing this bug.

Major question: how to test this?

I tried testing this by setting an env var on a Context object, and then seeing if it would be unset in the context of a Context.srb call, but I believe that every invocation of Context.exec creates a new shell env that doesn't persist between calls (correct me if I'm wrong here), so none of my attempts were successful. Would appreciate thoughts here!

There are cases where a dev environment can set the
`DYLD_LIBRARY_PATH` env variable in a way that loads a version of
the C++ standard library that is not compatible with the system
version of the library used by Sorbet. This will cause Sorbet to
generate corrupted JSON if the --print=symbol-table-json flag is
passed. Unsetting this environment variable forces Sorbet to default
to the system version of the C++ standard library, preventing this bug.
@egiurleo egiurleo requested a review from a team as a code owner November 20, 2025 22:56
# standard library other than the one used by Sorbet, it will cause Sorbet to generate
# corrupted JSON. Unsetting this environment variable forces Sorbet to default to the system
# version of the C++ standard library.
unset_dyld_library_path = "env -u DYLD_LIBRARY_PATH"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Another question -- would it be worth unsetting more than just this env var? I don't want to risk unsetting something that Sorbet actually needs, but at the same time, it seems like this might not be the only env var that could load harmful C++ dependencies by accident?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wouldn't do it this way, since it isn't portable. popen3 and friends use Process.spawn in the backend, so they all have the ability to set new env variables for the duration of the spawn, which is what I would use inside exec and bundle_exec.

Moreover, I doubt running sorbet needs any env variables, so I would lean towards using unsetenv_others option in the popen3 implementation to unset all env vars.

@vinistock

Copy link
Copy Markdown
Member

Could someone legitimately want to set the DYLD path if they only have a custom installation of the C++ stdlib in their system? And if not, should we erase the variable with ENV.delete?

@egiurleo

Copy link
Copy Markdown
Contributor Author

@vinistock I think you're right -- they might also have other things in their ENV that impact what they want to run here? Issue with this being such an abstract code path that could be used for so many things. I'm going to close this in favor of #808 to avoid this issue.

@egiurleo egiurleo closed this Nov 21, 2025
@paracycle

Copy link
Copy Markdown
Member

I think this was the right approach, tbh. I think we can safely remove all env variables from the Sorbet invocation.

@vinistock

Copy link
Copy Markdown
Member

Yeah, for clarity, I was raising these questions not as a way to point anything wrong with the approach. I truly don't know if someone might want to set these variables manually for a custom C++ installation.

However, I don't think we can remove more environment variables, especially anything related to the PATH or Bundler. It might mess up the Sorbet call.

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