Open ghost opened 4 years ago
Of course, this has nothing to do with c++, it's the difference in d_name
member of struct dirent
being char d_name[256]
in linux and FreeBSD and char d_name[1]
in illumos (Solaris), so we have memory corruption here reading into d_name not having the actual storage allocated.
I see #184 filed to make kyua use readdir()
instead, can that be integrated?
For the moment I'll just use the following as (ugly) workaround:
diff --git a/utils/fs/directory.cpp b/utils/fs/directory.cpp
index ff7ad5e..a6fc9aa 100644
--- a/utils/fs/directory.cpp
+++ b/utils/fs/directory.cpp
@@ -32,6 +32,7 @@ extern "C" {
#include <sys/types.h>
#include <dirent.h>
+#include <limits.h>
}
#include <cerrno>
@@ -133,6 +134,10 @@ struct utils::fs::detail::directory_iterator::impl : utils::noncopyable {
/// readdir_r(3) function.
::dirent _dirent;
+ /// Solaris and derivatives define d_name member of struct dirent
+ /// as char d_name[1], so we need to provide the actual storage.
+ char _d_name[NAME_MAX];
+
/// Custom representation of the directory entry.
///
/// This is separate from _dirent because this is the type we return to the
I'm trying to port some tests over to kyua on illumos, and have problem with kyua itself -- I'm compiling all the dependencies (except system libraries) statically into one big executable. The same process works on FreeBSD (same Makefile and sources) and nearly follows what FreeBSD does in base system, so that should not be an issue.
Now running
~/kyua/kyua test
in sed tests subdirectory copied over from FreeBSD's /usr/tests/usr.bin/sed make kyua crash:Apparently, it's: https://github.com/jmmv/kyua/blob/a685f911237e7badddbfb71f1301f640c71673d0/utils/fs/directory.cpp#L210
Adding debug prints before and after the line as following:
...gives me the following in the log when run with
--loglevel=debug
:I'm really lost as C++ is still uncharted territory for me, but last pointer seems to be stomped on.
The build is done using different gcc versions (7, 9, 10) all producing the same result.
Any hints on debugging this further?