fix(standalone): resolve image LD_LIBRARY_PATH instead of literal shell var#764
Merged
ilopezluna merged 1 commit intodocker:mainfrom Mar 18, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
The pull request correctly identifies that Docker does not perform shell expansion for environment variables and fixes it by manually resolving the LD_LIBRARY_PATH from the image. However, the implementation has a flaw that could introduce a security vulnerability by unintentionally adding the current working directory to the library search path. I've added a comment with a suggested fix for this issue.
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider handling the
ImageInspecterror explicitly (e.g., logging at debug level) so that unexpected failures to read the image’sLD_LIBRARY_PATHare easier to diagnose rather than silently falling back to the default path.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider handling the `ImageInspect` error explicitly (e.g., logging at debug level) so that unexpected failures to read the image’s `LD_LIBRARY_PATH` are easier to diagnose rather than silently falling back to the default path.
## Individual Comments
### Comment 1
<location path="cmd/cli/pkg/standalone/containers.go" line_range="573-581" />
<code_context>
+ ldLibPath := "/usr/lib/wsl/lib:/usr/local/cuda/lib64"
+ if imgInfo, err := dockerClient.ImageInspect(ctx, imageName); err == nil {
+ for _, e := range imgInfo.Config.Env {
+ if strings.HasPrefix(e, "LD_LIBRARY_PATH=") {
+ ldLibPath += ":" + strings.TrimPrefix(e, "LD_LIBRARY_PATH=")
+ break
+ }
</code_context>
<issue_to_address>
**suggestion:** Guard against appending a trailing colon when the image LD_LIBRARY_PATH is empty.
If the image config has `LD_LIBRARY_PATH=` with an empty value, `strings.TrimPrefix` returns an empty string and this code adds a trailing `:`. While often harmless, it can change behavior in some environments. Consider storing the trimmed value in a variable and only appending `":" + value` when it’s non-empty.
```suggestion
ldLibPath := "/usr/lib/wsl/lib:/usr/local/cuda/lib64"
if imgInfo, err := dockerClient.ImageInspect(ctx, imageName); err == nil {
for _, e := range imgInfo.Config.Env {
if strings.HasPrefix(e, "LD_LIBRARY_PATH=") {
imageLdLibPath := strings.TrimPrefix(e, "LD_LIBRARY_PATH=")
if imageLdLibPath != "" {
ldLibPath += ":" + imageLdLibPath
}
break
}
}
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…ll var Signed-off-by: Dorin Geman <dorin.geman@docker.com>
8979f0d to
d20e4d0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #547.