summaryrefslogtreecommitdiffstats
path: root/package/keyutils/keyutils-01-memleak-from-realloc.patch
blob: 0faa9d860489e1eec629a8592a73458573b79803 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Patch vampirised from Debian's packaging of keyutils-1.4

Author: Michael Gebetsroither <gebi@grml.org>
Description: Fixed memleak from realloc (Closes: #496466).

diff -Naurp keyutils.orig/keyutils.c keyutils/keyutils.c
--- keyutils.orig/keyutils.c	2008-08-09 21:46:52.000000000 +0200
+++ keyutils/keyutils.c	2008-08-25 13:38:07.000000000 +0200
@@ -165,6 +165,24 @@ long keyctl_assume_authority(key_serial_
 	return keyctl(KEYCTL_ASSUME_AUTHORITY, id);
 }
 
+
+/*****************************************************************************/
+/*
+ * plain realloc is just crazy
+ */
+static void* __xrealloc(void* ptr, size_t size)
+{
+    void* ret;
+
+    ret = realloc(ptr, size);
+    if(!ret) {
+        free(ptr);
+        return 0;
+    }
+    return ret;
+}
+
+
 /*****************************************************************************/
 /*
  * fetch key description into an allocated buffer
@@ -194,7 +212,7 @@ int keyctl_describe_alloc(key_serial_t i
 			break;
 
 		buflen = ret;
-		buf = realloc(buf, buflen);
+		buf = __xrealloc(buf, buflen);
 		if (!buf)
 			return -1;
 	}
@@ -233,7 +251,7 @@ int keyctl_read_alloc(key_serial_t id, v
 			break;
 
 		buflen = ret;
-		buf = realloc(buf, buflen + 1);
+		buf = __xrealloc(buf, buflen + 1);
 		if (!buf)
 			return -1;
 	}