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

Issue found by Svace static analyzer #13400

Closed
vvdvortsova opened this issue Oct 7, 2021 · 7 comments
Closed

Issue found by Svace static analyzer #13400

vvdvortsova opened this issue Oct 7, 2021 · 7 comments

Comments

@vvdvortsova
Copy link
Contributor

Hello
This warning found with the Svace.
Pointer 'resp' returned from function 'concurrency.stm.fetch' at stm.go:316 may be null, and it is dereferenced at stm.go:320.

resp := s.stm.fetch(keys...)

Here resp may be dereferenced here.
v3.WithRev(resp.Header.Revision),

The function fetch returns nil value here.

@jmhbnz
Copy link
Member

jmhbnz commented Apr 24, 2023

Hey @ahrtr , @serathius - While doing some exploration I found this issue which is our oldest open and un-triaged issue.

Reviewing main my naive interpretation is that this looks like a valid issue as resp can be used while possibly being nil. So a fix could be as simple as checking for nil before using resp and raising some kind of error or panic if nil so at least it is maintainable moving forward.

Can I please get your thoughts on this? If you think it's valid I will assign and propose a fix. Otherwise let's close this down as it has been open a long time.

@ahrtr
Copy link
Member

ahrtr commented Apr 25, 2023

Thanks both and sorry for the late response.

The passed keys will not be empty (len(keys) == 0), it will not run into any issue. We have four options,

  1. Keep it as it's, because it actually will not run into any issue;
  2. Change line 317 if firstRead to if firstRead && resp != nil && resp.Header != nil;
  3. Add a check something like if len(keys) == 0 { return "" } at the beginning of the method; (preferred)
  4. Add a assertion something like verify.Assert(len(keys) != 0, "no key provided");

@ShivangiM
Copy link

I would like to work on this issue, will raise pr for same

@jmhbnz
Copy link
Member

jmhbnz commented Apr 30, 2023

Thanks @ShivangiM - I've assigned this issue to you.

@jmhbnz
Copy link
Member

jmhbnz commented Jun 16, 2023

Hey @ShivangiM - How are you going with this? Please let us know if you have any questions 🙏🏻

@vianamjr
Copy link
Contributor

vianamjr commented Jul 8, 2023

I can do it, if it's still open.

@jmhbnz
Copy link
Member

jmhbnz commented Jul 12, 2023

Closing as completed in #16198 - thanks @vianamjr 🙏🏻

@jmhbnz jmhbnz closed this as completed Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants