summaryrefslogtreecommitdiff
path: root/filesystems/glusterfs/patches/patch-ba
blob: 8911d245580be260fa6d3224ee5fd9eff063d3a5 (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
$NetBSD: patch-ba,v 1.4 2011/07/08 08:02:57 manu Exp $

glibc dirname() modify the string it is given and returns it.
glusterfs takes this behavior for granted, and assume that if it
gives a malloc'ed string to dirname(), then it can free()) the
return value.

Here is what SUSv2 says:
http://opengroup.org/onlinepubs/007908799/xsh/dirname.html
"The dirname() function may modify the string pointed to by path,
and may return a pointer to static storage"

At least NetBSD returns a static storage. glusterfs will return it to
a calling function that has the responsability to free it, causing
a SIGSEGV.

--- xlators/performance/stat-prefetch/src/stat-prefetch.c.orig	2011-04-22 19:37:28.000000000 +0200
+++ xlators/performance/stat-prefetch/src/stat-prefetch.c	2011-05-19 12:41:28.000000000 +0200
@@ -949,18 +949,24 @@
                 path = dirname (cpy);
                 switch (i)
                 {
                 case 0:
-                        *parent = path;
+                        *parent = gf_strdup (path);
+			if (*parent == NULL)
+				goto out;
                         break;
                 case 1:
-                        *grand_parent = path;
+                        *grand_parent = gf_strdup (path);
+			if (*grand_parent == NULL)
+				goto out;
                         break;
                 }
         }
 
         ret = 0;
 out:
+	if (cpy != NULL)
+		GF_FREE(cpy);
         return ret;
 }