* The whole crap now builds on OS X. Now if it only agreed to run, too...
This commit is contained in:
@@ -27,6 +27,12 @@ if test "$build" != "$host" -a "${PKG_CONFIG_LIBDIR}" = ""; then
|
||||
fi
|
||||
|
||||
AC_CHECK_HEADERS(inttypes.h stdint.h getopt.h)
|
||||
AC_CHECK_FUNCS(open64 lseek64 fopen64 getline getdelim __getdelim)
|
||||
AC_CHECK_TYPES(sighandler_t, [], [],
|
||||
[#define _GNU_SOURCE
|
||||
#include <signal.h>])
|
||||
AC_CHECK_TYPES(sig_t, [], [],
|
||||
[#include <signal.h>])
|
||||
|
||||
AC_CHECK_FUNCS(getopt_long,
|
||||
[AC_DEFINE(HAVE_GETOPT_LONG, 1, Define to 1 if you have the `getopt_long' function.)],
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
|
||||
bin_PROGRAMS = zzuf
|
||||
zzuf_SOURCES = zzuf.c
|
||||
zzuf_CPPFLAGS = -DLIBDIR=\"$(libdir)/zzuf\"
|
||||
AM_CPPFLAGS = -DLIBDIR=\"$(libdir)/zzuf\"
|
||||
|
||||
pkglib_LTLIBRARIES = libzzuf.la
|
||||
libzzuf_la_SOURCES = libzzuf.c libzzuf.h fuzz.c fuzz.h debug.c debug.h \
|
||||
|
||||
+17
-1
@@ -20,7 +20,7 @@
|
||||
|
||||
/* Can't remember what that's for */
|
||||
#define _GNU_SOURCE
|
||||
/* Use this to get lseek64() */
|
||||
/* Use this to get lseek64() on glibc systems */
|
||||
#define _LARGEFILE64_SOURCE
|
||||
|
||||
#if defined HAVE_STDINT_H
|
||||
@@ -43,19 +43,27 @@
|
||||
|
||||
/* Library functions that we divert */
|
||||
static int (*open_orig) (const char *file, int oflag, ...);
|
||||
#ifdef HAVE_OPEN64
|
||||
static int (*open64_orig) (const char *file, int oflag, ...);
|
||||
#endif
|
||||
static ssize_t (*read_orig) (int fd, void *buf, size_t count);
|
||||
static off_t (*lseek_orig) (int fd, off_t offset, int whence);
|
||||
#ifdef HAVE_LSEEK64
|
||||
static off64_t (*lseek64_orig) (int fd, off64_t offset, int whence);
|
||||
#endif
|
||||
static int (*close_orig) (int fd);
|
||||
|
||||
void _zz_load_fd(void)
|
||||
{
|
||||
LOADSYM(open);
|
||||
#ifdef HAVE_OPEN64
|
||||
LOADSYM(open64);
|
||||
#endif
|
||||
LOADSYM(read);
|
||||
LOADSYM(lseek);
|
||||
#ifdef HAVE_LSEEK64
|
||||
LOADSYM(lseek64);
|
||||
#endif
|
||||
LOADSYM(close);
|
||||
}
|
||||
|
||||
@@ -97,10 +105,12 @@ int open(const char *file, int oflag, ...)
|
||||
int ret; OPEN(open); return ret;
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPEN64
|
||||
int open64(const char *file, int oflag, ...)
|
||||
{
|
||||
int ret; OPEN(open64); return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
ssize_t read(int fd, void *buf, size_t count)
|
||||
{
|
||||
@@ -120,7 +130,11 @@ ssize_t read(int fd, void *buf, size_t count)
|
||||
}
|
||||
|
||||
/* Sanity check, can be OK though (for instance with a character device) */
|
||||
#ifdef HAVE_LSEEK64
|
||||
if(lseek64_orig(fd, 0, SEEK_CUR) != _zz_getpos(fd))
|
||||
#else
|
||||
if(lseek_orig(fd, 0, SEEK_CUR) != _zz_getpos(fd))
|
||||
#endif
|
||||
debug("warning: offset inconsistency");
|
||||
|
||||
return ret;
|
||||
@@ -146,12 +160,14 @@ off_t lseek(int fd, off_t offset, int whence)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LSEEK64
|
||||
off64_t lseek64(int fd, off64_t offset, int whence)
|
||||
{
|
||||
off64_t ret;
|
||||
LSEEK(lseek64, off64_t);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
|
||||
+11
-5
@@ -37,10 +37,16 @@
|
||||
#include "fuzz.h"
|
||||
#include "load.h"
|
||||
|
||||
#if defined HAVE_SIGHANDLER_T
|
||||
# define SIG_T sighandler_t
|
||||
#elif defined HAVE_SIG_T
|
||||
# define SIG_T sig_t
|
||||
#endif
|
||||
|
||||
/* Library functions that we divert */
|
||||
static sighandler_t (*signal_orig) (int signum, sighandler_t handler);
|
||||
static int (*sigaction_orig) (int signum, const struct sigaction *act,
|
||||
struct sigaction *oldact);
|
||||
static SIG_T (*signal_orig) (int signum, SIG_T handler);
|
||||
static int (*sigaction_orig) (int signum, const struct sigaction *act,
|
||||
struct sigaction *oldact);
|
||||
/* Local functions */
|
||||
static int isfatal(int signum);
|
||||
|
||||
@@ -81,9 +87,9 @@ static int isfatal(int signum)
|
||||
}
|
||||
}
|
||||
|
||||
sighandler_t signal(int signum, sighandler_t handler)
|
||||
SIG_T signal(int signum, SIG_T handler)
|
||||
{
|
||||
sighandler_t ret;
|
||||
SIG_T ret;
|
||||
|
||||
if(!_zz_ready)
|
||||
LOADSYM(signal);
|
||||
|
||||
+24
-1
@@ -37,7 +37,9 @@
|
||||
|
||||
/* Library functions that we divert */
|
||||
static FILE * (*fopen_orig) (const char *path, const char *mode);
|
||||
#ifdef HAVE_FOPEN64
|
||||
static FILE * (*fopen64_orig) (const char *path, const char *mode);
|
||||
#endif
|
||||
static int (*fseek_orig) (FILE *stream, long offset, int whence);
|
||||
static size_t (*fread_orig) (void *ptr, size_t size, size_t nmemb,
|
||||
FILE *stream);
|
||||
@@ -48,16 +50,24 @@ static int (*ungetc_orig) (int c, FILE *stream);
|
||||
static int (*fclose_orig) (FILE *fp);
|
||||
|
||||
/* Additional GNUisms */
|
||||
#ifdef HAVE_GETLINE
|
||||
static ssize_t (*getline_orig) (char **lineptr, size_t *n, FILE *stream);
|
||||
#endif
|
||||
#ifdef HAVE_GETDELIM
|
||||
static ssize_t (*getdelim_orig) (char **lineptr, size_t *n, int delim,
|
||||
FILE *stream);
|
||||
#endif
|
||||
#ifdef HAVE___GETDELIM
|
||||
static ssize_t (*__getdelim_orig) (char **lineptr, size_t *n, int delim,
|
||||
FILE *stream);
|
||||
#endif
|
||||
|
||||
void _zz_load_stream(void)
|
||||
{
|
||||
LOADSYM(fopen);
|
||||
#ifdef HAVE_FOPEN64
|
||||
LOADSYM(fopen64);
|
||||
#endif
|
||||
LOADSYM(fseek);
|
||||
LOADSYM(fread);
|
||||
LOADSYM(getc);
|
||||
@@ -65,10 +75,15 @@ void _zz_load_stream(void)
|
||||
LOADSYM(fgets);
|
||||
LOADSYM(ungetc);
|
||||
LOADSYM(fclose);
|
||||
|
||||
#ifdef HAVE_GETLINE
|
||||
LOADSYM(getline);
|
||||
#endif
|
||||
#ifdef HAVE_GETDELIM
|
||||
LOADSYM(getdelim);
|
||||
#endif
|
||||
#ifdef HAVE___GETDELIM
|
||||
LOADSYM(__getdelim);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Our function wrappers */
|
||||
@@ -94,10 +109,12 @@ FILE *fopen(const char *path, const char *mode)
|
||||
FILE *ret; FOPEN(fopen); return ret;
|
||||
}
|
||||
|
||||
#ifdef HAVE_FOPEN64
|
||||
FILE *fopen64(const char *path, const char *mode)
|
||||
{
|
||||
FILE *ret; FOPEN(fopen64); return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int fseek(FILE *stream, long offset, int whence)
|
||||
{
|
||||
@@ -320,18 +337,24 @@ int fclose(FILE *fp)
|
||||
return ret; \
|
||||
} while(0)
|
||||
|
||||
#ifdef HAVE_GETLINE
|
||||
ssize_t getline(char **lineptr, size_t *n, FILE *stream)
|
||||
{
|
||||
ssize_t ret; GETDELIM(getline, '\n', 0); return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GETDELIM
|
||||
ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream)
|
||||
{
|
||||
ssize_t ret; GETDELIM(getdelim, delim, 1); return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE___GETDELIM
|
||||
ssize_t __getdelim(char **lineptr, size_t *n, int delim, FILE *stream)
|
||||
{
|
||||
ssize_t ret; GETDELIM(__getdelim, delim, 1); return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+11
-5
@@ -43,7 +43,7 @@
|
||||
static void spawn_child(char **);
|
||||
static char *merge_regex(char *, char *);
|
||||
static char *merge_file(char *, char *);
|
||||
static void set_ld_preload(char const *);
|
||||
static void set_environment(char const *);
|
||||
static void version(void);
|
||||
#if defined(HAVE_GETOPT_H)
|
||||
static void usage(void);
|
||||
@@ -222,7 +222,7 @@ int main(int argc, char *argv[])
|
||||
child_count = 0;
|
||||
|
||||
/* Preload libzzuf.so */
|
||||
set_ld_preload(argv[0]);
|
||||
set_environment(argv[0]);
|
||||
|
||||
/* Create new argv */
|
||||
newargv = malloc((argc - optind + 1) * sizeof(char *));
|
||||
@@ -483,19 +483,25 @@ static void spawn_child(char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
static void set_ld_preload(char const *progpath)
|
||||
static void set_environment(char const *progpath)
|
||||
{
|
||||
char *libpath, *tmp;
|
||||
int len = strlen(progpath);
|
||||
#ifdef __APPLE__
|
||||
char const *preload = "DYLD_INSERT_LIBRARIES";
|
||||
setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", 1);
|
||||
#else
|
||||
char const *preload = "LD_PRELOAD";
|
||||
#endif
|
||||
|
||||
libpath = malloc(len + strlen("/.libs/libzzuf.so") + 1);
|
||||
strcpy(libpath, progpath);
|
||||
tmp = strrchr(libpath, '/');
|
||||
strcpy(tmp ? tmp + 1 : libpath, ".libs/libzzuf.so");
|
||||
if(access(libpath, R_OK) == 0)
|
||||
setenv("LD_PRELOAD", libpath, 1);
|
||||
setenv(preload, libpath, 1);
|
||||
else
|
||||
setenv("LD_PRELOAD", LIBDIR "/libzzuf.so", 1);
|
||||
setenv(preload, LIBDIR "/libzzuf.so", 1);
|
||||
free(libpath);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,9 +54,11 @@ int main(int argc, char *argv[])
|
||||
lseek(fd, rand() % pos, SEEK_SET);
|
||||
for(j = 0; j < 16; j++)
|
||||
read(fd, data + lseek(fd, 0, SEEK_CUR), rand() % 4096);
|
||||
#ifdef HAVE_LSEEK64
|
||||
lseek64(fd, rand() % pos, SEEK_SET);
|
||||
for(j = 0; j < 16; j++)
|
||||
read(fd, data + lseek(fd, 0, SEEK_CUR), rand() % 4096);
|
||||
#endif
|
||||
}
|
||||
|
||||
fwrite(data, pos, 1, stdout);
|
||||
|
||||
Reference in New Issue
Block a user