From b6b63f10b4999f54992b04be70daffaa572ee2a3 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 19 Sep 2013 23:08:06 +0200 Subject: [PATCH] Fix warning about out-of-bound read Actually the second part of the condition guaranteed that an out-of-bound read would never occur but now code is neater. It was: for (j = 0; (j < "too_large_bound") && (const_ca[i].saklist[j] >= 0); j++) Problem reported by Coverity CID 1090332 (#1 of 1): Out-of-bounds read (OVERRUN) 67. overrun-local: Overrunning array "const_ca[i].saklist" of 8 4-byte elements at element index 31 (byte offset 124) using index "j" (which evaluates to 31). --- libnfc/target-subr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfc/target-subr.c b/libnfc/target-subr.c index b99b28c..ea35e77 100644 --- a/libnfc/target-subr.c +++ b/libnfc/target-subr.c @@ -412,7 +412,7 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info *pna for (i = 0; i < sizeof(const_ca) / sizeof(const_ca[0]); i++) { if ((atqa & const_ca[i].mask) == const_ca[i].atqa) { - for (j = 0; (j < sizeof(const_ca[i].saklist)) && (const_ca[i].saklist[j] >= 0); j++) { + for (j = 0; (j < sizeof(const_ca[i].saklist) / sizeof(const_ca[i].saklist[0])) && (const_ca[i].saklist[j] >= 0); j++) { int sakindex = const_ca[i].saklist[j]; if ((sak & const_cs[sakindex].mask) == const_cs[sakindex].sak) { off += snprintf(dst + off, size - off, "* %s%s\n", const_ca[i].type, const_cs[sakindex].type);