- Fix getentropy compat code, function refs were not portable.

git-svn-id: file:///svn/unbound/trunk@3178 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2014-07-12 11:33:38 +00:00
parent f756509e27
commit 6712f6c511
4 changed files with 20 additions and 14 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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).