aquasecurity/libbpfgo

Check type cast results

Ouverte

#381 ouverte le 28 sept. 2023

 (0 commentaire) (0 réaction) (0 personne assignée)Go (100 forks)auto 404
good first issue

Métriques du dépôt

Stars
 (845 étoiles)
Métriques de merge PR
 (Merge moyen 21h 50m) (12 PRs mergées en 30 j)

Description

It's important to check type cast results to avoid panic.

Revive unchecked-type-assertion rule provided this output:

make lint-check
Linting golang code...
Error: rwArray_test.go:74:8: type cast result is unchecked in a.get(uint(i)).(*int) - type assertion will panic if not matched
Error: libbpfgo.go:1254:16: type cast result is unchecked in eventChannels.get(rb.slot).(chan []byte) - type assertion will panic if not matched
Error: helpers/kernel_symbols_test.go:65:11: type cast result is unchecked in syms.(*lazyKernelSymbols) - type assertion will panic if not matched
Error: helpers/kernel_config.go:359:14: type cast result is unchecked in k.configs[option].(KernelConfigOptionValue) - type assertion will panic if not matched
make: *** [Makefile:237: lint-check] Error 1

After solved, unchecked-type-assertion should be re-enabled:

https://github.com/roikol/libbpfgo/blob/2def7dd7296bf450e0cfd188863d303fcab7aab0/.revive.toml#L131-L132

Context: https://github.com/aquasecurity/libbpfgo/pull/380/commits/2def7dd7296bf450e0cfd188863d303fcab7aab0

Guide contributeur