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

Check the validity of the chmod option arguments for COPY and ADD #5148

Merged
merged 1 commit into from
Jul 25, 2024

Conversation

kariya-mitsuru
Copy link
Contributor

The current implementation silently ignores the chmod option argument for COPY and ADD if it is invalid, so this PR change to check the validity of the argument.

@tonistiigi
Copy link
Member

@Chenbinx Do you remember why this used err == nil #1492 ? Stricter validation seems to make more sense to me.

@kariya-mitsuru Ideally, we would have a test for this as well.

@Chenbinx
Copy link
Contributor

Chenbinx commented Jul 14, 2024 via email

@kariya-mitsuru
Copy link
Contributor Author

Sorry for the slow response.
I have added the test.
Also, a typo was found and has been fixed.

perm := os.FileMode(p)
mode = &perm
if err != nil {
return errors.New("invalid chown format")
Copy link
Member

Choose a reason for hiding this comment

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

Looks like the error message refers to "chown", not "chmod". Also curious if the original error should be preserved (although maybe it's not very informative)

Copy link
Member

Choose a reason for hiding this comment

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

LOL, looks like I had the above comment still pending? 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very sorry, I was not aware of this comment...

Copy link
Member

Choose a reason for hiding this comment

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

no! no need to apologise; I thought I submitted that one already, but looks like my review was still pending (but I saw you already found the typo 😄 🎉)

perm := os.FileMode(p)
mode = &perm
if err != nil {
return fmt.Errorf("invalid chmod format: '%v'", cfg.chmod)
Copy link
Member

Choose a reason for hiding this comment

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

Can you use errors.Errorf for this one? I think using pkg/errors is preferred in this project (as those errors contain additional data that's used for tracing)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you.
Based on the above comment, I also tried errors.Wrap, but the error message was as below, which didn't seem very useful for me, so I tried using errors.Errorf.

ERROR: failed to solve: invalid chmod format: strconv.ParseUint: parsing "64a": invalid syntax

If the above message is more appropriate, please feel free to let me know.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I don't think the ParseUint error is very useful. Perhaps the error message could mention that it should be a valid octal value, but otherwise it's probably fine as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the error message could mention that it should be a valid octal

Oh, certainly!

Furthermore, I have found that if the value is 0o3777777777777(-1), it is ignored, and otherwise all but the lower 12 bits are meaningless.

I will try to change it again and add more test later.

@kariya-mitsuru
Copy link
Contributor Author

Sorry, the error message changed did not pass golangci-lint.
I will fix it so that it passes and push again.

@tonistiigi
Copy link
Member

@kariya-mitsuru When making small updates to the unmerged commits in the PR, try to squash them together with existing commits for cleaner commit history.

The current implementation silently ignores the chmod option argument
for COPY and ADD if it is invalid, so this PR change to check the
validity of the argument.

I also found that if the value is 0o3777777777777(-1), it is ignored, and
otherwise all but the lower 12 bits are meaningless.

Signed-off-by: Mitsuru Kariya <[email protected]>
@tonistiigi tonistiigi merged commit 655a124 into moby:master Jul 25, 2024
75 checks passed
@kariya-mitsuru kariya-mitsuru deleted the check-chmod branch July 25, 2024 13:29
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.

4 participants