Skip to content

[clientCertAuth] Nil pointer dereference on HTTP response when http.Get() fails #630

Description

@rustiqly

Description

In gnmi_server/clientCertAuth.go around line 161, resp.StatusCode is accessed even when http.Get() returns (nil, err). The current code checks resp != nil for the defer but then unconditionally accesses resp.StatusCode in the error check.

Current code

resp, err := http.Get(url)
if resp != nil { defer resp.Body.Close() }
if err != nil || resp.StatusCode != http.StatusOK {  // resp may be nil here!

Fix

Check err != nil first, return early, then access resp:

resp, err := http.Get(url)
if err != nil {
    return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {

Impact

Panic in the gNMI server when client certificate authentication makes an HTTP call that fails at the network level.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions