valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

Blame SOURCES/0127-util-check-for-overflow-in-greedy_realloc.patch

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