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

fix GetAll() potentially return an unprotected map #139

Merged
merged 2 commits into from
Dec 18, 2020

Conversation

gavwu
Copy link
Contributor

@gavwu gavwu commented Dec 10, 2020

l.mu.RLock()
defer l.mu.RUnlock()
return l.servicesMap
for k,v := range l.servicesMap {
res[k] = append(make([]string,0,len(v)), v...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggest to just use
res[k]=v

Copy link
Contributor Author

Choose a reason for hiding this comment

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

res[k]=v is not totally safe if the caller modify the slice with index

Copy link
Collaborator

Choose a reason for hiding this comment

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

v is not a pointer of the actual value of l.servicesMap. FYI: https://github.com/golang/go/wiki/Range#gotchas

Copy link
Collaborator

Choose a reason for hiding this comment

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

@CarlJi, v is slice, it is sth like pointer

@codecov
Copy link

codecov bot commented Dec 13, 2020

Codecov Report

Merging #139 (237bdb3) into master (e9e6b61) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #139      +/-   ##
==========================================
+ Coverage   75.18%   75.21%   +0.02%     
==========================================
  Files          37       37              
  Lines        2019     2021       +2     
==========================================
+ Hits         1518     1520       +2     
  Misses        358      358              
  Partials      143      143              
Flag Coverage Δ
e2e-1.11.x 44.73% <100.00%> (-0.05%) ⬇️
e2e-1.12.x 44.63% <100.00%> (-0.05%) ⬇️
e2e-1.13.x 44.73% <100.00%> (-0.05%) ⬇️
e2e-1.14.x 44.73% <100.00%> (+0.15%) ⬆️
e2e-1.15.x 44.73% <100.00%> (+0.05%) ⬆️
unittest-1.13.x 67.72% <100.00%> (+0.15%) ⬆️
unittest-1.14.x 67.72% <100.00%> (+0.15%) ⬆️
unittest-1.15.x 67.60% <100.00%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/cover/store.go 80.67% <100.00%> (+0.33%) ⬆️

@gavwu
Copy link
Contributor Author

gavwu commented Dec 16, 2020

/assign lyyyuna

@lyyyuna
Copy link
Collaborator

lyyyuna commented Dec 18, 2020

/approve
/lgtm

@qiniu-bot qiniu-bot added the lgtm label Dec 18, 2020
@qiniu-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gavwu, lyyyuna

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@qiniu-bot qiniu-bot merged commit ea5a665 into qiniu:master Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants