summaryrefslogtreecommitdiff
path: root/filesystems/glusterfs/patches/patch-ba
blob: 3d4c7dea4a5eb4584d1f23edfb45c42608f7f434 (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.2 2011/04/18 16:19:48 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-13 09:59:38.000000000 +0200
+++ ./xlators/performance/stat-prefetch/src/stat-prefetch.c	2011-04-13 10:01:01.000000000 +0200
@@ -905,18 +905,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; 
 }