From d23ae38ad0863aca418e2003af0fcb7e4edc8f26 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 11 Aug 2009 16:29:28 +0200 Subject: [PATCH] =?utf8?q?madwifi=20plugin:=20Add=20some=20assertions=20?= =?utf8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit … to otherwise unchecked array indices. --- src/madwifi.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/madwifi.c b/src/madwifi.c index 8538f685..9d973ec0 100644 --- a/src/madwifi.c +++ b/src/madwifi.c @@ -367,21 +367,29 @@ static int init_state = 0; static inline int item_watched(int i) { + assert (i >= 0); + assert (i < ((STATIC_ARRAY_SIZE (watch_items) + 1) * 32)); return watch_items[i / 32] & FLAG (i); } static inline int item_summed(int i) { + assert (i >= 0); + assert (i < ((STATIC_ARRAY_SIZE (misc_items) + 1) * 32)); return misc_items[i / 32] & FLAG (i); } static inline void watchlist_add (uint32_t *wl, int item) { + assert (item >= 0); + assert (item < ((WL_LEN + 1) * 32)); wl[item / 32] |= FLAG (item); } static inline void watchlist_remove (uint32_t *wl, int item) { + assert (item >= 0); + assert (item < ((WL_LEN + 1) * 32)); wl[item / 32] &= ~FLAG (item); } @@ -609,6 +617,9 @@ process_stat_struct (int which, const void *ptr, const char *dev, const char *ma uint32_t misc = 0; int i; + assert (which >= 1); + assert (which < STATIC_ARRAY_SIZE (bounds)); + for (i = bounds[which - 1]; i < bounds[which]; i++) { uint32_t val = *(uint32_t *)(((char *) ptr) + specs[i].offset) ; -- 2.11.0