rizin icon indicating copy to clipboard operation
rizin copied to clipboard

Add array bounds, write strings, type limits, overshadowing warnings

Open XVilka opened this issue 2 years ago • 3 comments

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:

  1. Added array bounds checking:
        -Warray-bounds
        -fsanitize=bounds
        -fsanitize-undefined-trap-on-error
  1. Added type limits warnings
  2. Added writing into constant strings warnings
  3. 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

XVilka avatar Feb 02 '23 10:02 XVilka

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)) { \
      |                       ^~~~

XVilka avatar Feb 02 '23 10:02 XVilka

Will be fixed with https://github.com/capstone-engine/capstone/pull/2312

Rot127 avatar Apr 07 '24 09:04 Rot127

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.

XVilka avatar Jun 01 '24 04:06 XVilka