rizin
rizin copied to clipboard
Add array bounds, write strings, type limits, overshadowing warnings
Your checklist for this pull request
- [x] I've read the guidelines for contributing to this repository
- [x] I made sure to follow the project's coding style
- [ ] I've documented or updated the documentation of every function and struct this PR changes. If not so I've explained why.
- [ ] I've added tests that prove my fix is effective or that my feature works (if possible)
- [ ] I've updated the rizin book with the relevant information (if needed)
Detailed description
Experiment on adding more restrictions on the C code:
- Added array bounds checking:
-Warray-bounds
-fsanitize=bounds
-fsanitize-undefined-trap-on-error
- Added type limits warnings
- Added writing into constant strings warnings
- Added warning on overshadowing variables
-Wshadow=local
See more at:
- https://people.kernel.org/kees/bounded-flexible-arrays-in-c
- https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
Test plan
CI is green
Nice, it seems to work:
In file included from ../librz/include/rz_vector.h:5,
from ../librz/include/rz_util/rz_event.h:12,
from ../librz/include/rz_util.h:25,
from ../librz/util/bitmap.c:5:
../librz/util/bitmap.c: In function ‘rz_bitmap_set_bytes’:
../librz/util/bitmap.c:44:43: error: comparison of unsigned expression in ‘>= 0’ is always true [-Werror=type-limits]
44 | rz_return_if_fail(b && buf && len >= 0);
| ^~
../librz/include/rz_util/rz_assert.h:102:23: note: in definition of macro ‘rz_return_if_fail’
102 | if (!(expr)) { \
| ^~~~
../librz/util/bitmap.c: In function ‘rz_bitmap_set’:
../librz/util/bitmap.c:62:36: error: comparison of unsigned expression in ‘>= 0’ is always true [-Werror=type-limits]
62 | rz_return_if_fail(b && bit >= 0);
| ^~
../librz/include/rz_util/rz_assert.h:102:23: note: in definition of macro ‘rz_return_if_fail’
102 | if (!(expr)) { \
| ^~~~
../librz/util/bitmap.c: In function ‘rz_bitmap_unset’:
../librz/util/bitmap.c:72:36: error: comparison of unsigned expression in ‘>= 0’ is always true [-Werror=type-limits]
72 | rz_return_if_fail(b && bit >= 0);
| ^~
../librz/include/rz_util/rz_assert.h:102:23: note: in definition of macro ‘rz_return_if_fail’
102 | if (!(expr)) { \
| ^~~~
../librz/util/bitmap.c: In function ‘rz_bitmap_test’:
../librz/util/bitmap.c:82:40: error: comparison of unsigned expression in ‘>= 0’ is always true [-Werror=type-limits]
82 | rz_return_val_if_fail(b && bit >= 0, -1);
| ^~
../librz/include/rz_util/rz_assert.h:110:23: note: in definition of macro ‘rz_return_val_if_fail’
110 | if (!(expr)) { \
| ^~~~
Will be fixed with https://github.com/capstone-engine/capstone/pull/2312
Hmm, need to disable restarting services during the apt upgrade:
Running kernel seems to be up-to-date.
Restarting services...
systemctl restart chrony.service containerd.service cron.service haveged.service hv-kvp-daemon.service multipathd.service packagekit.service php8.3-fpm.service polkit.service rsyslog.service runner-provisioner.service systemd-journald.service systemd-networkd.service systemd-resolved.service systemd-udevd.service udisks2.service walinuxagent.service
Error: Process completed with exit code 143.