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

Added Nil Check for Package in File Descriptor #3223

Closed
wants to merge 2 commits into from

Conversation

tmulkern
Copy link

What?

This code is to guard against a runtime error: invalid memory address or nil pointer dereference occuring

Why?

The package specifier is optional in protobuf spec https://protobuf.dev/programming-guides/proto3/#packages

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes. N/A
  • I have run linter locally (make ci-like-lint) and all checks pass. N/A
  • I have run tests locally (make tests) and all tests pass. N/A
  • I have commented on my code, particularly in hard-to-understand areas. N/A

Related PR(s)/Issue(s)

Fixes issue #3222

The package specifier is optional in protobuf spec https://protobuf.dev/programming-guides/proto3/#packages

This code is to guard against this
@CLAassistant
Copy link

CLAassistant commented Jul 21, 2023

CLA assistant check
All committers have signed the CLA.

@mstoykov mstoykov added this to the v0.47.0 milestone Jul 26, 2023
@mstoykov mstoykov linked an issue Jul 27, 2023 that may be closed by this pull request
mstoykov
mstoykov previously approved these changes Jul 27, 2023
Copy link
Contributor

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

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

LGTM!

Sorry for the slow review 🙇 .

Due to vacations across the team and the automatic assigning not taking this into account, sometimes things get assigned to people who are on vacation :(.

Unfortunately we are also at the end of the development cycle and have some higher priorities things we want to make certain do work for v0.46.0.

The fix seems pretty safe and I can't see any problems with it, but I still prefer if @olegbespalov gives it a 👍 specifically. This might mean that we do merge this in the codefreeze, but given the size and the fact it is a bug that doesn't seem like that much of a problem.

@tmulkern Can you please add a small test that panics without this change though.

Also we will need forward/backport this to xk6-grpc.

I will move this back to v0.46.0 milestone for now, but I can't promise we will actually make it :(

Thanks for the bug report and fix 🙇 And once again sorry for the slow reply

@mstoykov mstoykov modified the milestones: v0.47.0, v0.46.0 Jul 27, 2023
@tmulkern
Copy link
Author

@mstoykov no problem on the response, I am in the same situation myself in my day job, it is the time for Vacations!!

@tmulkern
Copy link
Author

Regarding the test, no problem in creating, but do we have a GRPC Test Service/Mock Service that I can reference. I couldn't find any. I am not that familiar with the code base, so I could be blind to it ;-)

Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

Hey @tmulkern,
thanks for your contribution. 🙇

Regarding the test, no problem in creating, but do we have a GRPC Test Service/Mock Service that I can reference

I guess it should be enough to add a new test case to the following test table. I think we should cover also the case with clashing names now that we are skipping the package.

func TestResolveFileDescriptors(t *testing.T) {

Added tests for following scenarios

* Services with no package - "NoPackage"
* Services with no package and duplicated - "NoPackageDeduplicateServices"
* One services with a package, one without - "MixPackage"
* Two services with a package (Duplicate), one without - "MixPackageDeduplicateServices"

Also updated the TestResolveFileDescriptors to handle cases with no packages
@tmulkern
Copy link
Author

Hey @codebien

Added tests for following scenarios

  • Services with no package - "NoPackage"
  • Services with no package and duplicated - "NoPackageDeduplicateServices"
  • One services with a package, one without - "MixPackage"
  • Two services with a package (Duplicate), one without - "MixPackageDeduplicateServices"

Also updated the TestResolveFileDescriptors to handle cases with no packages

@mstoykov mstoykov requested a review from codebien August 1, 2023 07:17
Comment on lines +192 to +213
{
name: "NoPackage",
services: []string{"Service1", "Service2"},
expectedDescriptors: 2,
},
{
name: "NoPackageDeduplicateServices",
services: []string{"Service1", "Service2", "Service1"},
expectedDescriptors: 2,
},
{
name: "MixPackage",
pkgs: []string{"mypkg1"},
services: []string{"Service1", "Service2"},
expectedDescriptors: 2,
},
{
name: "MixPackageDeduplicateServices",
pkgs: []string{"mypkg1"},
services: []string{"Service1", "Service2", "Service1"},
expectedDescriptors: 2,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is clear enough in this way because we already use undefined when we want to reuse for all of them. We could use an empty string for defining a no package.

Suggested change
{
name: "NoPackage",
services: []string{"Service1", "Service2"},
expectedDescriptors: 2,
},
{
name: "NoPackageDeduplicateServices",
services: []string{"Service1", "Service2", "Service1"},
expectedDescriptors: 2,
},
{
name: "MixPackage",
pkgs: []string{"mypkg1"},
services: []string{"Service1", "Service2"},
expectedDescriptors: 2,
},
{
name: "MixPackageDeduplicateServices",
pkgs: []string{"mypkg1"},
services: []string{"Service1", "Service2", "Service1"},
expectedDescriptors: 2,
},
{
name: "NoPackage",
pkgs: []string{""},
services: []string{"Service1", "Service2"},
expectedDescriptors: 2,
},
{
name: "NoPackageDeduplicateServices",
pkgs: []string{""},
services: []string{"Service1", "Service2", "Service1"},
expectedDescriptors: 2,
},
{
name: "MixPackage",
pkgs: []string{"mypkg1", ""},
services: []string{"Service1", "Service2"},
expectedDescriptors: 2,
},
{
name: "MixPackageDeduplicateServices",
pkgs: []string{"mypkg1", ""},
services: []string{"Service1", "Service2", "Service1"},
expectedDescriptors: 2,
},

Comment on lines +225 to +229
var pkg string
if len(tt.pkgs) == 1 {
pkg = tt.pkgs[0]
}

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 for completely removing this, every service should have an equivalent package defined (empty or non-empty), in this way we can remove any eventual confusion.

Copy link
Contributor

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

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

To be honest, in that particular case, I'm more up for keeping the logic (with the comment), like

pkg := ""

// if only one package is defined then
// the package is the same for every service
if len(tt.pkgs) == 1 {
   pkg = tt.pkgs[0]
}

The rationale is that having the empty strings confuses me more than the logic of the comment.

Comment on lines 231 to 232
// if only one package is defined then
// the package is the same for every service
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// if only one package is defined then
// the package is the same for every service

@tmulkern
Copy link
Author

tmulkern commented Aug 8, 2023

Applogies people for the late reply, as mstoykov alluded to it is vacation season and I was away on vacation. I will look into coming up with a commit to the test based on your comments

@oleiade oleiade modified the milestones: v0.46.0, v0.47.0 Aug 14, 2023
@olegbespalov
Copy link
Contributor

Hi @tmulkern !

I am sharing this here for the sake of transparency. We have another PR related to the support of gRPC's reflection v1.

I believe that PR also fixes the issue that you reported. So we will probably close this PR in favor of #3338.

Anyway, thank you for reporting and contribution! 🙇

@tmulkern
Copy link
Author

Hey olegbespalov, thank's for the update. Sorry, life got in the way the 2 months and I hadn't got round to finishing this PR.

@tmulkern tmulkern closed this Sep 19, 2023
@codebien codebien removed this from the v0.47.0 milestone Oct 2, 2023
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.

GRPC reflection will crash when there is no package specifier defined
6 participants