File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -188,17 +188,22 @@ std::vector<std::string> get_directory_contents (const char* path)
188188 throw System_error (" opendir" , path, errno);
189189 }
190190 try {
191- struct dirent * ent = NULL ;
192-
193191 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 )) {
197200 contents.push_back (ent->d_name );
201+ }
198202 }
199203
200- if (errno)
204+ if (errno) {
201205 throw System_error (" readdir" , path, errno);
206+ }
202207
203208 } catch (...) {
204209 closedir (dir);
You can’t perform that action at this time.
0 commit comments