]> git.pld-linux.org Git - packages/xen.git/blob - deprecated-readdir_r.patch
- up to 4.6.5
[packages/xen.git] / deprecated-readdir_r.patch
1 From c2a17869d5dcd845d646bf4db122cad73596a2be Mon Sep 17 00:00:00 2001
2 From: Chris Patterson <pattersonc@ainfosec.com>
3 Date: Fri, 3 Jun 2016 12:50:10 -0400
4 Subject: [PATCH] libfsimage: replace deprecated readdir_r() with readdir()
5
6 Replace the usage of readdir_r() with readdir() to address a
7 compilation error under glibc due to the deprecation of readdir_r
8 for their next release (2.24) [1, 2].
9
10 Add new error checking on readdir(), and fail if error occurs.
11
12 --
13
14 From the GNU libc manual [3]:
15 "
16  It is expected that future versions of POSIX will obsolete readdir_r and
17  mandate the level of thread safety for readdir which is provided by the
18  GNU C Library and other implementations today.
19 "
20
21 There is a filed bug in the Austin Group Defect Tracker [4]  in which 'dalias'
22 proposes (in comment 0001632) that:
23 "
24    I would like to propose an alternate solution. For readdir, replace the text:
25     "The readdir() function need not be thread-safe."
26    with:
27     "If multiple threads call the readdir() function with the same directory
28     stream argument and without synchronization to preclude simultaneous
29     access, then the behavior is undefined."
30
31    With this change, the clunky readdir_r function is no longer needed or
32    useful, and should probably be deprecated. As the only reasonable way
33    to meet the implementation requirements for readdir is to have the dirent
34    buffer in the DIR structure, this change should not require any change to
35    existing implementations.
36 "
37
38 [1] https://sourceware.org/ml/libc-alpha/2016-02/msg00093.html
39 [2] https://sourceware.org/bugzilla/show_bug.cgi?id=19056
40 [3] https://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html
41 [4] http://austingroupbugs.net/view.php?id=696
42
43 Signed-off-by: Chris Patterson <pattersonc@ainfosec.com>
44 Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
45 Release-acked-by: Wei Liu <wei.liu2@citrix.com>
46 ---
47  tools/libfsimage/common/fsimage_plugin.c | 21 ++++++++++++---------
48  1 file changed, 12 insertions(+), 9 deletions(-)
49
50 diff --git a/tools/libfsimage/common/fsimage_plugin.c b/tools/libfsimage/common/fsimage_plugin.c
51 index 3fa06c7..0744e7b 100644
52 --- a/tools/libfsimage/common/fsimage_plugin.c
53 +++ b/tools/libfsimage/common/fsimage_plugin.c
54 @@ -123,7 +123,6 @@ static int load_plugins(void)
55  {
56         const char *fsdir = getenv("FSIMAGE_FSDIR");
57         struct dirent *dp = NULL;
58 -       struct dirent *dpp;
59         DIR *dir = NULL;
60         char *tmp = NULL;
61         size_t name_max;
62 @@ -139,22 +138,26 @@ static int load_plugins(void)
63         if ((tmp = malloc(name_max + 1)) == NULL)
64                 goto fail;
65  
66 -       if ((dp = malloc(sizeof (struct dirent) + name_max + 1)) == NULL)
67 -               goto fail;
68 -
69         if ((dir = opendir(fsdir)) == NULL)
70                 goto fail;
71  
72 -       bzero(dp, sizeof (struct dirent) + name_max + 1);
73 +       for (;;) {
74 +               errno = 0;
75 +               dp = readdir(dir);
76 +
77 +               if (dp == NULL && errno != 0)
78 +                       goto fail;
79 +
80 +               if (dp == NULL)
81 +                       break;
82  
83 -       while (readdir_r(dir, dp, &dpp) == 0 && dpp != NULL) {
84 -               if (strcmp(dpp->d_name, ".") == 0)
85 +               if (strcmp(dp->d_name, ".") == 0)
86                         continue;
87 -               if (strcmp(dpp->d_name, "..") == 0)
88 +               if (strcmp(dp->d_name, "..") == 0)
89                         continue;
90  
91                 (void) snprintf(tmp, name_max, "%s/%s/fsimage.so", fsdir,
92 -                       dpp->d_name);
93 +                       dp->d_name);
94  
95                 if (init_plugin(tmp) != 0)
96                         goto fail;
97 -- 
98 2.1.4
99
100 From b9daff9d811285f1e40669bc621c2241793f7a95 Mon Sep 17 00:00:00 2001
101 From: Chris Patterson <pattersonc@ainfosec.com>
102 Date: Fri, 3 Jun 2016 12:50:09 -0400
103 Subject: [PATCH] libxl: replace deprecated readdir_r() with readdir()
104
105 Replace the usage of readdir_r() with readdir() to address a
106 compilation error under glibc due to the deprecation of readdir_r
107 for their next release (2.24) [1, 2].
108
109 Remove code specific to usage of readdir_r which is no longer required,
110 such as zalloc_dirent().
111
112 --
113
114 From the GNU libc manual [3]:
115 "
116  It is expected that future versions of POSIX will obsolete readdir_r and
117  mandate the level of thread safety for readdir which is provided by the
118  GNU C Library and other implementations today.
119 "
120
121 There is a filed bug in the Austin Group Defect Tracker [4]  in which 'dalias'
122 proposes (in comment 0001632) that:
123 "
124    I would like to propose an alternate solution. For readdir, replace the text:
125     "The readdir() function need not be thread-safe."
126    with:
127     "If multiple threads call the readdir() function with the same directory
128     stream argument and without synchronization to preclude simultaneous
129     access, then the behavior is undefined."
130
131    With this change, the clunky readdir_r function is no longer needed or
132    useful, and should probably be deprecated. As the only reasonable way
133    to meet the implementation requirements for readdir is to have the dirent
134    buffer in the DIR structure, this change should not require any change to
135    existing implementations.
136 "
137
138 [1] https://sourceware.org/ml/libc-alpha/2016-02/msg00093.html
139 [2] https://sourceware.org/bugzilla/show_bug.cgi?id=19056
140 [3] https://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html
141 [4] http://austingroupbugs.net/view.php?id=696
142
143 Signed-off-by: Chris Patterson <pattersonc@ainfosec.com>
144 Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
145 Release-acked-by: Wei Liu <wei.liu2@citrix.com>
146 ---
147  tools/libxl/libxl_utils.c |  8 +++-----
148  2 files changed, 9 insertions(+), 23 deletions(-)
149
150 diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
151 index ceb8825..4ca6bcb 100644
152 --- a/tools/libxl/libxl_utils.c
153 +++ b/tools/libxl/libxl_utils.c
154 @@ -548,14 +548,12 @@ int libxl__remove_directory(libxl__gc *gc, const char *dirpath)
155          goto out;
156      }
157  
158 -    size_t need = offsetof(struct dirent, d_name) +
159 -        pathconf(dirpath, _PC_NAME_MAX) + 1;
160 -    struct dirent *de_buf = libxl__zalloc(gc, need);
161      struct dirent *de;
162  
163      for (;;) {
164 -        int r = readdir_r(d, de_buf, &de);
165 -        if (r) {
166 +        errno = 0;
167 +        de = readdir(d);
168 +        if (!de && errno) {
169              LOGE(ERROR, "failed to readdir %s for removal", dirpath);
170              rc = ERROR_FAIL;
171              break;
172 -- 
173 2.1.4
174
This page took 0.038341 seconds and 3 git commands to generate.