dcavalca / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone
Blob Blame History Raw
From aa37345b6b9c0910d871d05ff028c257b657ffb7 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Tue, 10 Dec 2013 18:53:03 +0000
Subject: [PATCH] util: check for overflow in greedy_realloc()

Conflicts:
	src/shared/util.c
---
 src/shared/util.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/shared/util.c b/src/shared/util.c
index 8a542da..e9b8255 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5838,10 +5838,18 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need) {
         size_t a;
         void *q;
 
+        assert(p);
+        assert(allocated);
+
         if (*allocated >= need)
                 return *p;
 
         a = MAX(64u, need * 2);
+
+        /* check for overflows */
+        if (a < need)
+                return NULL;
+
         q = realloc(*p, a);
         if (!q)
                 return NULL;