OSDN Git Service

procrank: fix bounds check to prevent heap overflow
authorNick Desaulniers <ndesaulniers@google.com>
Thu, 11 Aug 2016 00:32:59 +0000 (00:32 +0000)
committerandroid-build-merger <android-build-merger@google.com>
Thu, 11 Aug 2016 00:32:59 +0000 (00:32 +0000)
am: 98a20cd128

Change-Id: I9e79ff3f83f36b68fa119d1b95f235a804cfb34e

libpagemap/pm_memusage.c

index 70cfede..71a5783 100644 (file)
@@ -89,15 +89,15 @@ void pm_memusage_pswap_add_offset(pm_memusage_t *mu, unsigned int offset) {
     if (mu->p_swap == NULL)
         return;
 
-    if (offset > mu->p_swap->array_size) {
+    if (offset >= mu->p_swap->array_size) {
         fprintf(stderr, "SWAP offset %d is out of swap bounds.\n", offset);
         return;
+    }
+
+    if (mu->p_swap->offset_array[offset] == USHRT_MAX) {
+        fprintf(stderr, "SWAP offset %d ref. count if overflowing ushort type.\n", offset);
     } else {
-        if (mu->p_swap->offset_array[offset] == USHRT_MAX) {
-            fprintf(stderr, "SWAP offset %d ref. count if overflowing ushort type.\n", offset);
-        } else {
-            mu->p_swap->offset_array[offset]++;
-        }
+        mu->p_swap->offset_array[offset]++;
     }
 
     soff = malloc(sizeof(pm_swap_offset_t));