[PATCH] acpi: cstates: set state->present[nr] if nr < MAX_CSTATE

Colin King colin.king at canonical.com
Tue May 7 00:13:33 UTC 2013


From: Colin Ian King <colin.king at canonical.com>

Coverity CID #997274, Out-of-bounds write (OVERRUN)

We can get an out of bounds write on state->present[] if
nr >= MAX_CSTATE, so guard against this.  We already do this
for state->counts[].

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/acpi/cstates/cstates.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/acpi/cstates/cstates.c b/src/acpi/cstates/cstates.c
index 93a7e50..90b5c03 100644
--- a/src/acpi/cstates/cstates.c
+++ b/src/acpi/cstates/cstates.c
@@ -100,10 +100,10 @@ static void get_cstates(char *path, fwts_cstates *state)
 			count = strtoull(data, NULL, 10);
 			free(data);
 
-			if ((nr>=0) && (nr < MAX_CSTATE))
+			if ((nr >= 0) && (nr < MAX_CSTATE)) {
 				state->counts[nr] = count;
-
-			state->present[nr] = true;
+				state->present[nr] = true;
+			}
 		}
 	}
 	closedir(dir);
-- 
1.8.1.2




More information about the fwts-devel mailing list