Skip to content

sql: audit json.AsText for nil return value#81927

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
yuzefovich:json-as-text
May 26, 2022
Merged

sql: audit json.AsText for nil return value#81927
craig[bot] merged 1 commit intocockroachdb:masterfrom
yuzefovich:json-as-text

Conversation

@yuzefovich
Copy link
Copy Markdown
Member

This commit audits all calls of json.AsText to make sure that we
always do nil-pointer check. I think all of the callsites where this
commit adds the check are impossible to hit the nil-pointer panic, but
it's still good to have the checks explicitly.

Informs: #81097.

Release note: None

@yuzefovich yuzefovich requested review from a team, linaqiu22, mgartner and wenyihu6 May 26, 2022 18:46
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@yuzefovich
Copy link
Copy Markdown
Member Author

We ended up reverting the changes from the first half of the collab session - some more context is in here.

Copy link
Copy Markdown
Contributor

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

Bummer that you had to undo all the work! Thanks for auditing this. :lgtm:

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @linaqiu22, @wenyihu6, and @yuzefovich)


pkg/util/json/json.go line 2063 at r1 (raw file):

				return nil, false, err
			}
			if t == nil || *t != s {

t should never be nil here because we check that it's a StringJSONType above. Maybe an assertion failure is less confusing?

This commit audits all calls of `json.AsText` to make sure that we
always do nil-pointer check. I think all of the callsites where this
commit adds the check are impossible to hit the nil-pointer panic, but
it's still good to have the checks explicitly.

Release note: None
Copy link
Copy Markdown
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

TFTR!

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @linaqiu22, @mgartner, and @wenyihu6)


pkg/util/json/json.go line 2063 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

t should never be nil here because we check that it's a StringJSONType above. Maybe an assertion failure is less confusing?

Good point, done.

@craig
Copy link
Copy Markdown
Contributor

craig bot commented May 26, 2022

Build succeeded:

@craig craig bot merged commit c7b09e6 into cockroachdb:master May 26, 2022
@yuzefovich yuzefovich deleted the json-as-text branch May 26, 2022 21:14
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