Skip to content

Commit

Permalink
fix(api): add newResponse for function SearchAllPages (#770)
Browse files Browse the repository at this point in the history
* add newResponse for function SearchAllPages

This is necessary as using the current response to iterate over pages
corrupts data that are slices, such as the tags within imageInfo. This is beacause
the memory address from the previous response will still contain data from the previous request.
By creating a new response using the nextPage url we get a new spot in memory to put the next
requests data.

Signed-off-by: aircraft-cerier <[email protected]>

* add newResponse for function SearchAllPages

This is necessary as using the current response to iterate over pages
corrupts data that are slices, such as the tags within imageInfo. This is beacause
the memory address from the previous response will still contain data from the previous request.
By creating a new response using the nextPage url we get a new spot in memory to put the next
requests data.

Signed-off-by: aircraft-cerier <[email protected]>

* typo in type

Signed-off-by: aircraft-cerier <[email protected]>

* typo in type

Signed-off-by: aircraft-cerier <[email protected]>

* fix signing

Signed-off-by: aircraft-cerier <[email protected]>
  • Loading branch information
aircraft-cerier committed May 5, 2022
1 parent c9d7f48 commit 474a163
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions api/v2_vulnerabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ func (svc *v2ContainerVulnerabilityService) SearchAllPages(filters SearchFilter)
for {
all = append(all, response.Data...)

pageOk, err = svc.client.NextPage(&response)
newResponse := VulnerabilitiesContainersResponse{
Paging: response.Paging,
}
pageOk, err = svc.client.NextPage(&newResponse)
if err == nil && pageOk {
response = newResponse
continue
}
break
Expand Down Expand Up @@ -216,8 +220,12 @@ func (svc *v2HostVulnerabilityService) SearchAllPages(filters SearchFilter) (
for {
all = append(all, response.Data...)

pageOk, err = svc.client.NextPage(&response)
newResponse := VulnerabilitiesHostResponse{
Paging: response.Paging,
}
pageOk, err = svc.client.NextPage(&newResponse)
if err == nil && pageOk {
response = newResponse
continue
}
break
Expand Down

0 comments on commit 474a163

Please sign in to comment.