atc0005 / go-nagios

Shared Golang package for Nagios plugins
MIT License
8 stars 3 forks source link

panic in EvaluateThreshold because of unvalidated ParseRangeString return value #233

Closed Tommi2Day closed 8 months ago

Tommi2Day commented 9 months ago

ParseRangeString may return NIL on errors, but in EvaluateThreshold this is not checked will lead to a panic

runtime error: invalid memory address or nil pointer dereference goroutine 36 [running]: runtime/debug.Stack() C:/Users/user/go-sdk/go1.21.3/src/runtime/debug/stack.go:24 +0x6b github.com/atc0005/go-nagios.(*Plugin).ReturnCheckResults(0xc0000c40e0) C:/local/progs/go-proj/src/check_hm/vendor/github.com/atc0005/go-nagios/nagios.go:283 +0x305 panic({0x1af6600?, 0x216afd0?}) C:/Users/user/go-sdk/go1.21.3/src/runtime/panic.go:920 +0x290 github.com/atc0005/go-nagios.(*Plugin).EvaluateThreshold(0xc0000c40e0, {0xc0001f16c0, 0x1, 0x1}) C:/local/progs/go-proj/src/check_hm/vendor/github.com/atc0005/go-nagios/range.go:153 +0xed First https://github.com/atc0005/go-nagios/blob/7a6e9212a75d7cf063a1d0c787c74a4cb847f1a1/range.go#L151-L153 may panic here if CritcalThreshold object is nil

second: https://github.com/atc0005/go-nagios/blob/7a6e9212a75d7cf063a1d0c787c74a4cb847f1a1/range.go#L160-L164

may panic here if warningThreshold object is nil

atc0005 commented 9 months ago

@Tommi2Day,

Thank you for this report. I appreciate the specifics you have provided.

@infraweavers,

Any interest in taking a look at this? If you use a modified version of the code contributed in GH-178 is it publicly available?

I figured it was best to touch base with you to see if this was already resolved in a private branch before digging into it.

Thanks.