OSDN Git Service

osi: Prevent memory allocations with MSB set
authorChris Manton <cmanton@google.com>
Thu, 30 Sep 2021 00:49:25 +0000 (17:49 -0700)
committerChris Manton <cmanton@google.com>
Fri, 1 Oct 2021 15:42:20 +0000 (15:42 +0000)
Limit allocations on 32bit to 2 GB
Limit allocations on 64bit to 8 Exabyte

Bug: 197868577
Tag: #refactor
Test: gd/cert/run
Ignore-AOSP-First: Security
Change-Id: I1c347084d7617b1e364a3241f1b37b398a2a6c6a

osi/src/allocator.cc

index 1c0449e..e2c356d 100644 (file)
@@ -56,6 +56,7 @@ char* osi_strndup(const char* str, size_t len) {
 }
 
 void* osi_malloc(size_t size) {
+  CHECK(static_cast<ssize_t>(size) >= 0);
   size_t real_size = allocation_tracker_resize_for_canary(size);
   void* ptr = malloc(real_size);
   CHECK(ptr);
@@ -63,6 +64,7 @@ void* osi_malloc(size_t size) {
 }
 
 void* osi_calloc(size_t size) {
+  CHECK(static_cast<ssize_t>(size) >= 0);
   size_t real_size = allocation_tracker_resize_for_canary(size);
   void* ptr = calloc(1, real_size);
   CHECK(ptr);