File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -188,17 +188,22 @@ std::vector<std::string> get_directory_contents (const char* path)
188
188
throw System_error (" opendir" , path, errno);
189
189
}
190
190
try {
191
- struct dirent * ent = NULL ;
192
-
193
191
errno = 0 ;
194
-
195
- while ((ent = readdir (dir)) != NULL && errno == 0 ) {
196
- if (std::strcmp (ent->d_name , " ." ) && std::strcmp (ent->d_name , " .." ))
192
+ // Note: readdir is reentrant in new implementations. In old implementations,
193
+ // it might not be, but git-crypt isn't multi-threaded so that's OK.
194
+ // We don't use readdir_r because it's buggy and deprecated:
195
+ // https://womble.decadent.org.uk/readdir_r-advisory.html
196
+ // http://austingroupbugs.net/view.php?id=696
197
+ // http://man7.org/linux/man-pages/man3/readdir_r.3.html
198
+ while (struct dirent * ent = readdir (dir)) {
199
+ if (!(std::strcmp (ent->d_name , " ." ) == 0 || std::strcmp (ent->d_name , " .." ) == 0 )) {
197
200
contents.push_back (ent->d_name );
201
+ }
198
202
}
199
203
200
- if (errno)
204
+ if (errno) {
201
205
throw System_error (" readdir" , path, errno);
206
+ }
202
207
203
208
} catch (...) {
204
209
closedir (dir);
You can’t perform that action at this time.
0 commit comments