From 39e3909ae2c89a1bab498fc3cdb583ba5e745288 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 13 Dec 2017 17:03:22 +0100 Subject: [PATCH 1/5] Avoid a crash in "script list" This command crashes if the path to the executable directory could not be found. --- client/cmdscript.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index 23163aa..0d19f49 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -76,8 +76,11 @@ int CmdList(const char *Cmd) { DIR *dp; struct dirent *ep; - char script_directory_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; - strcpy(script_directory_path, get_my_executable_directory()); + char const * exedir = get_my_executable_directory(); + if (exedir == NULL) + return 0; + char script_directory_path[strlen(exedir) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; + strcpy(script_directory_path, exedir); strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); dp = opendir(script_directory_path); From 669957afeeb60f02cb844da0afbab302c6bac71c Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 13 Dec 2017 17:06:47 +0100 Subject: [PATCH 2/5] Register NetBSD into the build system This is probably not the best way. Also, I have not looked at Lua yet; it may need to be built differently than with -DLUA_USE_LINUX. --- client/Makefile | 12 +++++++++--- liblua/Makefile | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/client/Makefile b/client/Makefile index ec59355..6f386cb 100644 --- a/client/Makefile +++ b/client/Makefile @@ -31,9 +31,15 @@ else ifeq ($(platform),Darwin) LUAPLATFORM = macosx else - LUALIB += -ldl - LDLIBS += -ltermcap -lncurses - LUAPLATFORM = linux + ifeq ($(platform),NetBSD) + LDLIBS += -L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib + LDLIBS += -ltermcap -lncurses + LUAPLATFORM = netbsd + else + LUALIB += -ldl + LDLIBS += -ltermcap -lncurses + LUAPLATFORM = linux + endif endif endif diff --git a/liblua/Makefile b/liblua/Makefile index 5525606..346afae 100644 --- a/liblua/Makefile +++ b/liblua/Makefile @@ -26,7 +26,7 @@ MYOBJS= # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= -PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris +PLATS= aix ansi bsd freebsd generic linux macosx mingw netbsd posix solaris LUA_A= liblua.a CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \ @@ -114,6 +114,9 @@ mingw: "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe $(MAKE) "LUAC_T=luac.exe" luac.exe +netbsd: + $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLDFLAGS="-L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib" SYSLIBS="-Wl,-E -lreadline -ltermcap -lncurses" + posix: $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX" From 80bbafecfc45683dc4441b0fa9f721fbccbcee5c Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 13 Dec 2017 17:31:55 +0100 Subject: [PATCH 3/5] Fix detection of the executable directory on NetBSD --- client/util.h | 2 +- client/whereami.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/client/util.h b/client/util.h index 8dc56f8..f4ea49d 100644 --- a/client/util.h +++ b/client/util.h @@ -82,7 +82,7 @@ void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length); void xor(unsigned char *dst, unsigned char *src, size_t len); int32_t le24toh(uint8_t data[3]); -uint32_t le32toh (uint8_t *data); +#endif void rol(uint8_t *data, const size_t len); void clean_ascii(unsigned char *buf, size_t len); diff --git a/client/whereami.c b/client/whereami.c index 6e5e85f..8cc49da 100644 --- a/client/whereami.c +++ b/client/whereami.c @@ -559,6 +559,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) defined(__FreeBSD_kernel__) || defined(__NetBSD__) #include +#include #include #include #include @@ -576,7 +577,11 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) for (;;) { +#ifdef KERN_PROC_ARGV + int mib[4] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV }; +#else int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; +#endif size_t size = sizeof(buffer1); if (sysctl(mib, (u_int)(sizeof(mib) / sizeof(mib[0])), path, &size, NULL, 0) != 0) From c02d36a2f72ba9db7869df2f7104d2483f8122da Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 13 Dec 2017 20:46:59 +0100 Subject: [PATCH 4/5] Also use posix_memalign() on NetBSD This helps fix the build on this platform. --- client/hardnested/hardnested_bf_core.c | 2 +- client/hardnested/hardnested_bitarray_core.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/hardnested/hardnested_bf_core.c b/client/hardnested/hardnested_bf_core.c index 3c0c044..b9c0691 100644 --- a/client/hardnested/hardnested_bf_core.c +++ b/client/hardnested/hardnested_bf_core.c @@ -146,7 +146,7 @@ bitslice_test_nonces_t bitslice_test_nonces_dispatch; #if defined (_WIN32) #define malloc_bitslice(x) __builtin_assume_aligned(_aligned_malloc((x), MAX_BITSLICES/8), MAX_BITSLICES/8) #define free_bitslice(x) _aligned_free(x) -#elif defined (__APPLE__) +#elif defined (__APPLE__) || defined(__NetBSD__) static void *malloc_bitslice(size_t x) { char *allocated_memory; if (posix_memalign((void**)&allocated_memory, MAX_BITSLICES/8, x)) { diff --git a/client/hardnested/hardnested_bitarray_core.c b/client/hardnested/hardnested_bitarray_core.c index aca4f14..4127d96 100644 --- a/client/hardnested/hardnested_bitarray_core.c +++ b/client/hardnested/hardnested_bitarray_core.c @@ -147,7 +147,7 @@ inline uint32_t *MALLOC_BITARRAY(uint32_t x) { #if defined (_WIN32) return __builtin_assume_aligned(_aligned_malloc((x), __BIGGEST_ALIGNMENT__), __BIGGEST_ALIGNMENT__); -#elif defined (__APPLE__) +#elif defined (__APPLE__) || defined(__NetBSD__) uint32_t *allocated_memory; if (posix_memalign((void**)&allocated_memory, __BIGGEST_ALIGNMENT__, x)) { return NULL; From 6f0f4abe8c08fbd4a90f04e84b3e417b5f121ac6 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 13 Dec 2017 21:09:25 +0100 Subject: [PATCH 5/5] Fix build on NetBSD (conflicting macro) --- client/util.c | 3 +++ client/util.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/client/util.c b/client/util.c index 7e6b407..c7d8134 100644 --- a/client/util.c +++ b/client/util.c @@ -704,6 +704,9 @@ void xor(unsigned char *dst, unsigned char *src, size_t len) { int32_t le24toh (uint8_t data[3]) { return (data[2] << 16) | (data[1] << 8) | data[0]; } +#ifdef le32toh +# undef le32toh +#endif uint32_t le32toh (uint8_t *data) { return (uint32_t)( (data[3]<<24) | (data[2]<<16) | (data[1]<<8) | data[0]); } diff --git a/client/util.h b/client/util.h index f4ea49d..c7dbc7e 100644 --- a/client/util.h +++ b/client/util.h @@ -82,7 +82,10 @@ void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length); void xor(unsigned char *dst, unsigned char *src, size_t len); int32_t le24toh(uint8_t data[3]); +#ifdef le32toh +# undef le32toh #endif +uint32_t le32toh (uint8_t *data); void rol(uint8_t *data, const size_t len); void clean_ascii(unsigned char *buf, size_t len);