* Got rid of the *_load() functions. Now each diverted function is supposed
to check that the *_orig() functions it calls are properly loaded.
This commit is contained in:
parent
c0147e553f
commit
9dee8b079e
@ -36,7 +36,6 @@
|
||||
|
||||
#include "libzzuf.h"
|
||||
#include "debug.h"
|
||||
#include "load.h"
|
||||
#include "fd.h"
|
||||
#include "fuzz.h"
|
||||
|
||||
@ -53,11 +52,6 @@ void _zz_init(void)
|
||||
{
|
||||
char *tmp, *tmp2;
|
||||
|
||||
_zz_load_mem();
|
||||
_zz_load_signal();
|
||||
_zz_load_fd();
|
||||
_zz_load_stream();
|
||||
|
||||
tmp = getenv("ZZUF_DEBUG");
|
||||
if(tmp && *tmp == '1')
|
||||
_zz_hasdebug = 1;
|
||||
|
||||
@ -70,25 +70,6 @@ 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(accept);
|
||||
LOADSYM(socket);
|
||||
LOADSYM(read);
|
||||
LOADSYM(readv);
|
||||
LOADSYM(pread);
|
||||
LOADSYM(lseek);
|
||||
#ifdef HAVE_LSEEK64
|
||||
LOADSYM(lseek64);
|
||||
#endif
|
||||
LOADSYM(close);
|
||||
}
|
||||
|
||||
#define OPEN(fn) \
|
||||
do \
|
||||
{ \
|
||||
@ -173,9 +154,13 @@ static void offset_check(int fd)
|
||||
{
|
||||
/* Sanity check, can be OK though (for instance with a character device) */
|
||||
#ifdef HAVE_LSEEK64
|
||||
off64_t ret = lseek64_orig(fd, 0, SEEK_CUR);
|
||||
off64_t ret;
|
||||
LOADSYM(lseek64);
|
||||
ret = lseek64_orig(fd, 0, SEEK_CUR);
|
||||
#else
|
||||
off_t ret = lseek_orig(fd, 0, SEEK_CUR);
|
||||
off_t ret;
|
||||
LOADSYM(lseek);
|
||||
ret = lseek_orig(fd, 0, SEEK_CUR);
|
||||
#endif
|
||||
if(ret != -1 && ret != _zz_getpos(fd))
|
||||
debug("warning: offset inconsistency");
|
||||
@ -307,12 +292,11 @@ int close(int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
LOADSYM(close);
|
||||
|
||||
/* Hey, it’s our debug channel! Silently pretend we closed it. */
|
||||
if(fd == DEBUG_FILENO)
|
||||
return 0;
|
||||
|
||||
LOADSYM(close);
|
||||
ret = close_orig(fd);
|
||||
if(!_zz_ready || !_zz_iswatched(fd) || _zz_disabled)
|
||||
return ret;
|
||||
|
||||
@ -82,30 +82,6 @@ static kern_return_t (*map_fd_orig) (int fd, vm_offset_t offset,
|
||||
vm_size_t numbytes);
|
||||
#endif
|
||||
|
||||
void _zz_load_mem(void)
|
||||
{
|
||||
LOADSYM(calloc);
|
||||
LOADSYM(malloc);
|
||||
LOADSYM(free);
|
||||
LOADSYM(realloc);
|
||||
LOADSYM(valloc);
|
||||
#ifdef HAVE_MEMALIGN
|
||||
LOADSYM(memalign);
|
||||
#endif
|
||||
#ifdef HAVE_POSIX_MEMALIGN
|
||||
LOADSYM(posix_memalign);
|
||||
#endif
|
||||
|
||||
LOADSYM(mmap);
|
||||
#ifdef HAVE_MMAP64
|
||||
LOADSYM(mmap64);
|
||||
#endif
|
||||
LOADSYM(munmap);
|
||||
#ifdef HAVE_MAP_FD
|
||||
LOADSYM(map_fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* We need a static memory buffer because some functions call memory
|
||||
* allocation routines before our library is loaded. Hell, even dlsym()
|
||||
* calls calloc(), so we need to do something about it */
|
||||
|
||||
@ -52,12 +52,6 @@ static int (*sigaction_orig) (int signum, const struct sigaction *act,
|
||||
/* Local functions */
|
||||
static int isfatal(int signum);
|
||||
|
||||
void _zz_load_signal(void)
|
||||
{
|
||||
LOADSYM(signal);
|
||||
LOADSYM(sigaction);
|
||||
}
|
||||
|
||||
static int isfatal(int signum)
|
||||
{
|
||||
switch(signum)
|
||||
|
||||
@ -88,45 +88,6 @@ static char * (*fgetln_orig) (FILE *stream, size_t *len);
|
||||
int (*__srefill_orig) (FILE *fp);
|
||||
#endif
|
||||
|
||||
|
||||
void _zz_load_stream(void)
|
||||
{
|
||||
LOADSYM(fopen);
|
||||
#ifdef HAVE_FOPEN64
|
||||
LOADSYM(fopen64);
|
||||
#endif
|
||||
LOADSYM(freopen);
|
||||
LOADSYM(fseek);
|
||||
#ifdef HAVE_FSEEKO
|
||||
LOADSYM(fseeko);
|
||||
#endif
|
||||
LOADSYM(rewind);
|
||||
LOADSYM(fread);
|
||||
LOADSYM(getc);
|
||||
LOADSYM(fgetc);
|
||||
#ifdef HAVE__IO_GETC
|
||||
LOADSYM(_IO_getc);
|
||||
#endif
|
||||
LOADSYM(fgets);
|
||||
LOADSYM(ungetc);
|
||||
LOADSYM(fclose);
|
||||
#ifdef HAVE_GETLINE
|
||||
LOADSYM(getline);
|
||||
#endif
|
||||
#ifdef HAVE_GETDELIM
|
||||
LOADSYM(getdelim);
|
||||
#endif
|
||||
#ifdef HAVE___GETDELIM
|
||||
LOADSYM(__getdelim);
|
||||
#endif
|
||||
#ifdef HAVE_FGETLN
|
||||
LOADSYM(fgetln);
|
||||
#endif
|
||||
#ifdef HAVE___SREFILL
|
||||
LOADSYM(__srefill);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Our function wrappers */
|
||||
#define FOPEN(fn) \
|
||||
do \
|
||||
@ -355,6 +316,7 @@ char *fgets(char *s, int size, FILE *stream)
|
||||
int fd;
|
||||
|
||||
LOADSYM(fgets);
|
||||
LOADSYM(fgetc);
|
||||
fd = fileno(stream);
|
||||
if(!_zz_ready || !_zz_iswatched(fd))
|
||||
return fgets_orig(s, size, stream);
|
||||
@ -461,6 +423,8 @@ int fclose(FILE *fp)
|
||||
ssize_t done, size; \
|
||||
int fd, finished = 0; \
|
||||
LOADSYM(fn); \
|
||||
LOADSYM(getdelim); \
|
||||
LOADSYM(fgetc); \
|
||||
fd = fileno(stream); \
|
||||
if(!_zz_ready || !_zz_iswatched(fd)) \
|
||||
return getdelim_orig(lineptr, n, delim, stream); \
|
||||
@ -542,6 +506,7 @@ char *fgetln(FILE *stream, size_t *len)
|
||||
int fd;
|
||||
|
||||
LOADSYM(fgetln);
|
||||
LOADSYM(fgetc);
|
||||
fd = fileno(stream);
|
||||
if(!_zz_ready || !_zz_iswatched(fd))
|
||||
return fgetln_orig(stream, len);
|
||||
|
||||
@ -27,8 +27,3 @@
|
||||
abort(); \
|
||||
} while(0)
|
||||
|
||||
extern void _zz_load_fd(void);
|
||||
extern void _zz_load_mem(void);
|
||||
extern void _zz_load_signal(void);
|
||||
extern void _zz_load_stream(void);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user