mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2026-09-02 20:28:50 +02:00
🐛 fix(cache): avoid nil-pointer panic on empty redis read
redisCache.get fell through to `switch err.Error()` when Get returned a nil error with an empty value, panicking on the nil error. simpleredis never returns that combination today (a miss yields RedisMiss), so it was unreachable in practice — but the read path is safer treating an empty, error-free read as a cache miss, which also guarantees err is non-nil before err.Error() is called. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Vendored
+4
@@ -72,6 +72,10 @@ func (rc *redisCache) get(key string) (string, error) {
|
|||||||
if len(valueString) > 0 {
|
if len(valueString) > 0 {
|
||||||
return valueString, nil
|
return valueString, nil
|
||||||
}
|
}
|
||||||
|
// Reachable and no error, but nothing stored: treat as a miss. This
|
||||||
|
// also keeps err non-nil for the switch below, which would otherwise
|
||||||
|
// panic on err.Error().
|
||||||
|
return "", errors.New(CacheMiss)
|
||||||
}
|
}
|
||||||
switch err.Error() {
|
switch err.Error() {
|
||||||
case simpleredis.RedisMiss:
|
case simpleredis.RedisMiss:
|
||||||
|
|||||||
Reference in New Issue
Block a user