daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
572a44
From aa37345b6b9c0910d871d05ff028c257b657ffb7 Mon Sep 17 00:00:00 2001
572a44
From: Lennart Poettering <lennart@poettering.net>
572a44
Date: Tue, 10 Dec 2013 18:53:03 +0000
572a44
Subject: [PATCH] util: check for overflow in greedy_realloc()
572a44
572a44
Conflicts:
572a44
	src/shared/util.c
572a44
---
572a44
 src/shared/util.c | 8 ++++++++
572a44
 1 file changed, 8 insertions(+)
572a44
572a44
diff --git a/src/shared/util.c b/src/shared/util.c
572a44
index 8a542da..e9b8255 100644
572a44
--- a/src/shared/util.c
572a44
+++ b/src/shared/util.c
572a44
@@ -5838,10 +5838,18 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need) {
572a44
         size_t a;
572a44
         void *q;
572a44
 
572a44
+        assert(p);
572a44
+        assert(allocated);
572a44
+
572a44
         if (*allocated >= need)
572a44
                 return *p;
572a44
 
572a44
         a = MAX(64u, need * 2);
572a44
+
572a44
+        /* check for overflows */
572a44
+        if (a < need)
572a44
+                return NULL;
572a44
+
572a44
         q = realloc(*p, a);
572a44
         if (!q)
572a44
                 return NULL;