Skip to content

fmtsafe: allow string(RedactableString) as safe arg#70979

Closed
tbg wants to merge 1 commit intocockroachdb:masterfrom
tbg:linter
Closed

fmtsafe: allow string(RedactableString) as safe arg#70979
tbg wants to merge 1 commit intocockroachdb:masterfrom
tbg:linter

Conversation

@tbg
Copy link
Copy Markdown
Member

@tbg tbg commented Oct 1, 2021

It's safe to use a RedactableString as a format argument instead
of a constant string. This teaches the linter that.

Needed for #70485

Release note: None

It's safe to use a RedactableString as a format argument instead
of a constant string. This teaches the linter that.

Release note: None
@tbg tbg requested a review from knz October 1, 2021 10:24
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

This does not seem correct. Say, I have this:

f := redact.SafeString("‹%s seecret›")
s := redact.Sprintf("abc")   // s == "‹abc›"

out := redact.Sprintf(s, f) // out == "‹‹abc› seecret›"

The linter is really there to preserve the invariant that the format string is a literal constant:

  • either it is actually a literal constant
  • or it forwarding an incoming format parameter, which recursively is provably a literal constant

If there's one thing missing, is that we should probably assert that the literal string constant does not contain redaction markers. but allowing the format to be hidden via a variable doesn't seem to be the right way to go?

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained

Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

(I meant fmt.Sprintf(f, s) in the example but the remainder of the argument remains the same)

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained

@tbg
Copy link
Copy Markdown
Member Author

tbg commented Oct 6, 2021

You're right, let's solve the original problem in a different way. (And there is no rush on doing so).

@tbg tbg closed this Oct 6, 2021
@tbg tbg deleted the linter branch October 6, 2021 07:26
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