Browse Source

ensure: Validate buffer offset

Max Bruckner 8 năm trước cách đây
mục cha
commit
1934059554
1 tập tin đã thay đổi với 6 bổ sung0 xóa
  1. 6 0
      cJSON.c

+ 6 - 0
cJSON.c

@@ -253,6 +253,12 @@ static unsigned char* ensure(printbuffer * const p, size_t needed, const interna
         return NULL;
     }
 
+    if ((p->length > 0) && (p->offset >= p->length))
+    {
+        /* make sure that offset is valid */
+        return NULL;
+    }
+
     if (needed > INT_MAX)
     {
         /* sizes bigger than INT_MAX are currently not supported */