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 index out of range on compose.buildContainerMountOptions #8750

Merged
merged 1 commit into from
Oct 11, 2021

Conversation

ulyssessouza
Copy link
Collaborator

What I did
Remove buggy code, since it seems to be incorrect even when not panic-ing

Related issue
Resolves #8505

@ulyssessouza ulyssessouza requested review from ndeloof and mat007 October 5, 2021 07:20
Comment on lines -766 to -768
l := len(s.Volumes) - 1
s.Volumes[i] = s.Volumes[l]
s.Volumes = s.Volumes[:l]
Copy link
Member

Choose a reason for hiding this comment

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

This is an attempt at deleting the i element, but clearly doing this while iterating is a recipe for disaster…

However there was a definite intent there, as the comment seems to imply.
Do we really not know what it’s supposed to do?

Do we have unit tests? 😁

@@ -762,10 +762,6 @@ func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby
Target: m.Destination,
ReadOnly: !m.RW,
}
// Avoid mount to be later re-defined
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I remember the detail, but deletion here is expected afaict.
Maybe better create a new Volumes before the loop, copy those that need to be kept while iterating, then override s.Volumes

Copy link
Member

Choose a reason for hiding this comment

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

Yes, either that or a good old for i := 0; i < len(s.Volumes {, incrementing i only when not deleting.

@ulyssessouza
Copy link
Collaborator Author

I actually removed that cuz in the end in the docker inpect that was correct even without it.
But you are right... Maybe that breaks a special case.
I'll reimplement that just refactoring the removal

@ulyssessouza ulyssessouza force-pushed the fix-recreate-panic branch 2 times, most recently from a93f66b to 479d3e4 Compare October 8, 2021 06:41
@ndeloof ndeloof merged commit ef786f9 into docker:v2 Oct 11, 2021
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.

panic: runtime error: index out of range [1] with length 1 in compose.buildContainerMountOptions
3 participants