summaryrefslogtreecommitdiff
path: root/filesystems/glusterfs/patches/patch-bc
blob: e93491e5a65aed45888726ba43f0a005a680823c (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
52
53
54
55
56
57
58
59
60
$NetBSD: patch-bc,v 1.1.1.1 2010/08/26 14:26:19 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/quick-read/src/quick-read.c.orig	2010-08-24 18:01:15.000000000 +0200
+++ ./xlators/performance/quick-read/src/quick-read.c	2010-08-24 18:04:22.000000000 +0200
@@ -80,8 +80,9 @@
 qr_loc_fill (loc_t *loc, inode_t *inode, char *path)
 {
         int32_t  ret = -1;
         char    *parent = NULL;
+        char    *path_copy = NULL;
 
         if ((loc == NULL) || (inode == NULL) || (path == NULL)) {
                 ret = -1;
                 errno = EINVAL;
@@ -91,15 +92,15 @@
         loc->inode = inode_ref (inode);
         loc->path = strdup (path);
         loc->ino = inode->ino;
 
-        parent = strdup (path);
-        if (parent == NULL) {
+        path_copy = strdup (path);
+        if (path_copy == NULL) {
                 ret = -1;
                 goto out;
         }
 
-        parent = dirname (parent);
+        parent = dirname (path_copy);
 
         loc->parent = inode_from_path (inode->table, parent);
         if (loc->parent == NULL) {
                 ret = -1;
@@ -114,10 +115,10 @@
                 qr_loc_wipe (loc);
 
         }
 
-        if (parent) {
-                FREE (parent);
+        if (path_copy) {
+                FREE (path_copy);
         }
         
         return ret;
 }