From 6712f6c5119189a4e8a2f6d5c8bdecad8950a4d9 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Sat, 12 Jul 2014 11:33:38 +0000 Subject: [PATCH] - Fix getentropy compat code, function refs were not portable. git-svn-id: file:///svn/unbound/trunk@3178 be551aaa-1e26-0410-a405-d3ace91eadb9 --- compat/getentropy_linux.c | 11 +++++++---- compat/getentropy_osx.c | 13 +++++++------ compat/getentropy_solaris.c | 7 +++---- doc/Changelog | 3 +++ 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/compat/getentropy_linux.c b/compat/getentropy_linux.c index f4a81e5ea..5de2cc095 100644 --- a/compat/getentropy_linux.c +++ b/compat/getentropy_linux.c @@ -66,10 +66,13 @@ #define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l))) #define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x))) +/* (portability) some compilers cannot take sizeof a function pointer */ +#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*))) int getentropy(void *buf, size_t len); -extern int main(int, char *argv[]); +/* referencing functions in other link modules is not portable */ +/* extern int main(int, char *argv[]); */ static int gotdata(char *buf, size_t len); static int getentropy_urandom(void *buf, size_t len); #ifdef CTL_MAXNAME @@ -342,9 +345,9 @@ getentropy_fallback(void *buf, size_t len) HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, sigset); - HD(main); /* an addr in program */ - HD(getentropy); /* an addr in this library */ - HD(printf); /* an addr in libc */ + /* HF(main); */ /* an addr in program */ + HF(getentropy); /* an addr in this library */ + HF(printf); /* an addr in libc */ p = (char *)&p; HD(p); /* an addr on stack */ p = (char *)&errno; diff --git a/compat/getentropy_osx.c b/compat/getentropy_osx.c index 919f00641..d9c7cc861 100644 --- a/compat/getentropy_osx.c +++ b/compat/getentropy_osx.c @@ -69,11 +69,13 @@ } while (0) #define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l))) #define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x))) +/* (portability) some compilers cannot take sizeof a function pointer */ +#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*))) int getentropy(void *buf, size_t len); -/* using log_info instead of main for unbound */ +/* cannot reference main, or log_info for unbound, it + gives portability problems */ /*extern int main(int, char *argv[]);*/ -extern void log_info(const char* format, ...); static int gotdata(char *buf, size_t len); static int getentropy_urandom(void *buf, size_t len); static int getentropy_fallback(void *buf, size_t len); @@ -292,10 +294,9 @@ getentropy_fallback(void *buf, size_t len) sigset); /* using log_info instead of main for unbound */ - /*HD(main);*/ /* an addr in program */ - HD(log_info); /* an addr in program */ - HD(getentropy); /* an addr in this library */ - HD(printf); /* an addr in libc */ + /*HF(main);*/ /* an addr in program */ + HF(getentropy); /* an addr in this library */ + HF(printf); /* an addr in libc */ p = (char *)&p; HD(p); /* an addr on stack */ p = (char *)&errno; diff --git a/compat/getentropy_solaris.c b/compat/getentropy_solaris.c index abd387701..a8e6bb7d2 100644 --- a/compat/getentropy_solaris.c +++ b/compat/getentropy_solaris.c @@ -67,10 +67,10 @@ int getentropy(void *buf, size_t len); -/* a function in the main program, but main is only in executables, - referencing main does not work in sun-cc, but does work with gcc */ +/* cannot refernce main, or log_info for unbound, it gives + portability problems. For solaris specifically, sun-cc and gcc + have different link semantics (but it also fails on other platforms) */ /* extern int main(int, char *argv[]); */ -extern void log_info(const char* format, ...); static int gotdata(char *buf, size_t len); static int getentropy_urandom(void *buf, size_t len); static int getentropy_fallback(void *buf, size_t len); @@ -288,7 +288,6 @@ getentropy_fallback(void *buf, size_t len) /* replaced main with log_info */ /*HF(main);*/ /* an addr in program */ - HF(log_info); /* an addr in program */ HF(getentropy); /* an addr in this library */ HF(printf); /* an addr in libc */ p = (char *)&p; diff --git a/doc/Changelog b/doc/Changelog index f68baaf16..15bae9f73 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +12 July 2014: Wouter + - Fix getentropy compat code, function refs were not portable. + 11 July 2014: Matthijs - fake-rfc2553 patch (thanks Benjamin Baier). -- 2.47.2