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()
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].
10 Add new error checking on readdir(), and fail if error occurs.
14 From the GNU libc manual [3]:
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.
21 There is a filed bug in the Austin Group Defect Tracker [4] in which 'dalias'
22 proposes (in comment 0001632) that:
24 I would like to propose an alternate solution. For readdir, replace the text:
25 "The readdir() function need not be thread-safe."
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."
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.
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
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>
47 tools/libfsimage/common/fsimage_plugin.c | 21 ++++++++++++---------
48 1 file changed, 12 insertions(+), 9 deletions(-)
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)
56 const char *fsdir = getenv("FSIMAGE_FSDIR");
57 struct dirent *dp = NULL;
62 @@ -139,22 +138,26 @@ static int load_plugins(void)
63 if ((tmp = malloc(name_max + 1)) == NULL)
66 - if ((dp = malloc(sizeof (struct dirent) + name_max + 1)) == NULL)
69 if ((dir = opendir(fsdir)) == NULL)
72 - bzero(dp, sizeof (struct dirent) + name_max + 1);
77 + if (dp == NULL && errno != 0)
83 - while (readdir_r(dir, dp, &dpp) == 0 && dpp != NULL) {
84 - if (strcmp(dpp->d_name, ".") == 0)
85 + if (strcmp(dp->d_name, ".") == 0)
87 - if (strcmp(dpp->d_name, "..") == 0)
88 + if (strcmp(dp->d_name, "..") == 0)
91 (void) snprintf(tmp, name_max, "%s/%s/fsimage.so", fsdir,
95 if (init_plugin(tmp) != 0)
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()
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].
109 Remove code specific to usage of readdir_r which is no longer required,
110 such as zalloc_dirent().
114 From the GNU libc manual [3]:
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.
121 There is a filed bug in the Austin Group Defect Tracker [4] in which 'dalias'
122 proposes (in comment 0001632) that:
124 I would like to propose an alternate solution. For readdir, replace the text:
125 "The readdir() function need not be thread-safe."
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."
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.
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
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>
147 tools/libxl/libxl_utils.c | 8 +++-----
148 2 files changed, 9 insertions(+), 23 deletions(-)
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)
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);
164 - int r = readdir_r(d, de_buf, &de);
168 + if (!de && errno) {
169 LOGE(ERROR, "failed to readdir %s for removal", dirpath);