Implement ReOpenFile and fix a few Win32 compilation warnings.

This commit is contained in:
Sam Hocevar 2010-10-06 22:44:47 +00:00 committed by sam
parent 8c527cd15a
commit 4c504ac53e
8 changed files with 45 additions and 18 deletions

View File

@ -54,7 +54,7 @@ AC_CHECK_FUNCS(__getdelim __srefill __filbuf __srget __uflow)
AC_CHECK_FUNCS(open64 lseek64 mmap64 fopen64 freopen64 ftello64 fseeko64 fsetpos64)
AC_CHECK_FUNCS(__open64 __lseek64 __fopen64 __freopen64 __ftello64 __fseeko64 __fsetpos64)
AC_CHECK_FUNCS(__fgets_chk __fgets_unlocked_chk __fread_chk __fread_unlocked_chk __read_chk __recv_chk __recvfrom_chk)
AC_CHECK_FUNCS(CreateFileA CreateFileW ReadFile CloseHandle)
AC_CHECK_FUNCS(CreateFileA CreateFileW ReOpenFile ReadFile CloseHandle)
AC_CHECK_TYPES(sighandler_t, [], [],
[#define _GNU_SOURCE

View File

@ -79,6 +79,7 @@
#define HAVE_RECVFROM 1
/* #undef HAVE_RECVMSG */
/* #undef HAVE_REGEX_H */
#define HAVE_REOPENFILE 1
/* #undef HAVE_SETENV */
/* #undef HAVE_SETRLIMIT */
/* #undef HAVE_SIGACTION */

View File

@ -45,8 +45,8 @@ static int has_include = 0, has_exclude = 0;
#endif
/* File descriptor cherry picking */
static int *list = NULL;
static int static_list[512];
static int64_t *list = NULL;
static int64_t static_list[512];
/* File descriptor stuff. When program is launched, we use the static array of
* 32 structures, which ought to be enough for most programs. If it happens
@ -397,8 +397,8 @@ int _zz_getfuzzed(int fd)
+ files[fds[fd]].already_fuzzed)
return 0;
return files[fds[fd]].already_fuzzed + files[fds[fd]].already_pos
- files[fds[fd]].pos;
return (int)(files[fds[fd]].already_fuzzed + files[fds[fd]].already_pos
- files[fds[fd]].pos);
}
struct fuzz *_zz_getfuzz(int fd)

View File

@ -46,8 +46,8 @@ static enum fuzzing
fuzzing;
/* Per-offset byte protection */
static int *ranges = NULL;
static int static_ranges[512];
static int64_t *ranges = NULL;
static int64_t static_ranges[512];
/* Per-value byte protection */
static unsigned char protect[256];

View File

@ -32,10 +32,10 @@
* If more than 256 slots are required, new memory is allocated, otherwise
* the static array static_ranges is used. It is the caller's duty to call
* free() if the returned value is not static_ranges. */
int *_zz_allocrange(char const *list, int *static_ranges)
int64_t *_zz_allocrange(char const *list, int64_t *static_ranges)
{
char const *parser;
int *ranges;
int64_t *ranges;
unsigned int i, chunks;
/* Count commas */
@ -44,7 +44,7 @@ int *_zz_allocrange(char const *list, int *static_ranges)
chunks++;
if(chunks >= 256)
ranges = malloc((chunks + 1) * 2 * sizeof(unsigned int));
ranges = malloc((chunks + 1) * 2 * sizeof(int64_t));
else
ranges = static_ranges;
@ -69,9 +69,9 @@ int *_zz_allocrange(char const *list, int *static_ranges)
return ranges;
}
int _zz_isinrange(int value, int const *ranges)
int _zz_isinrange(int64_t value, int64_t const *ranges)
{
int const *r;
int64_t const *r;
if(!ranges)
return 1;

View File

@ -14,6 +14,6 @@
* ranges.c: range handling helper functions
*/
int *_zz_allocrange(char const *, int *);
int _zz_isinrange(int, int const *);
int64_t *_zz_allocrange(char const *, int64_t *);
int _zz_isinrange(int64_t, int64_t const *);

View File

@ -27,6 +27,9 @@
#if defined HAVE_WINDOWS_H
# include <windows.h>
#endif
#if defined HAVE_IO_H
# include <io.h>
#endif
#include "common.h"
#include "libzzuf.h"
@ -46,6 +49,10 @@ static HANDLE (__stdcall *ORIG(CreateFileW))(LPCWSTR, DWORD, DWORD,
LPSECURITY_ATTRIBUTES,
DWORD, DWORD, HANDLE);
#endif
#if defined HAVE_REOPENFILE
static HANDLE (__stdcall *ORIG(ReOpenFile))(HANDLE, DWORD,
DWORD, DWORD);
#endif
#if defined HAVE_READFILE
static BOOL (__stdcall *ORIG(ReadFile))(HANDLE, LPVOID, DWORD, LPDWORD,
LPOVERLAPPED);
@ -68,7 +75,7 @@ HANDLE __stdcall NEW(CreateFileA)(LPCTSTR lpFileName, DWORD dwDesiredAccess,
ret = ORIG(CreateFileA)(lpFileName, dwDesiredAccess, dwShareMode,
lpSecurityAttributes, dwCreationDisposition,
dwFlagsAndAttributes, hTemplateFile);
debug("CreateFileA(\"%s\", 0x%x, 0x%x, ..., 0x%x, 0x%x, ...) = [%i]",
debug("CreateFileA(\"%s\", 0x%x, 0x%x, {...}, 0x%x, 0x%x, {...}) = %i",
lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition,
dwFlagsAndAttributes, (int)ret);
return ret;
@ -85,13 +92,26 @@ HANDLE __stdcall NEW(CreateFileW)(LPCWSTR lpFileName, DWORD dwDesiredAccess,
ret = ORIG(CreateFileW)(lpFileName, dwDesiredAccess, dwShareMode,
lpSecurityAttributes, dwCreationDisposition,
dwFlagsAndAttributes, hTemplateFile);
debug("CreateFileW(\"%S\", 0x%x, 0x%x, ..., 0x%x, 0x%x, ...) = [%i]",
debug("CreateFileW(\"%S\", 0x%x, 0x%x, {...}, 0x%x, 0x%x, {...}) = %i",
lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition,
dwFlagsAndAttributes, (int)ret);
return ret;
}
#endif
#if defined HAVE_REOPENFILE
HANDLE __stdcall NEW(ReOpenFile)(HANDLE hOriginalFile, DWORD dwDesiredAccess,
DWORD dwShareMode, DWORD dwFlags)
{
HANDLE ret;
ret = ORIG(ReOpenFile)(hOriginalFile, dwDesiredAccess,
dwShareMode, dwFlags);
debug("ReOpenFile(%i, 0x%x, 0x%x, 0x%x) = %i", (int)hOriginalFile,
dwDesiredAccess, dwShareMode, dwFlags, (int)ret);
return ret;
}
#endif
/*
* ReadFile
*/
@ -113,7 +133,10 @@ BOOL __stdcall NEW(ReadFile)(HANDLE hFile, LPVOID lpBuffer,
#if defined HAVE_CLOSEHANDLE
BOOL __stdcall NEW(CloseHandle)(HANDLE hObject)
{
return ORIG(CloseHandle)(hObject);
BOOL ret;
ret = ORIG(CloseHandle)(hObject);
debug("CloseHandle(%i) = %i", (int)hObject, ret);
return ret;
}
#endif

View File

@ -25,6 +25,9 @@
#if defined HAVE_WINDOWS_H
# include <windows.h>
#endif
#if defined HAVE_IO_H
# include <io.h>
#endif
#if defined HAVE_PROCESS_H
# include <process.h>
#endif
@ -117,7 +120,7 @@ void _zz_init(void)
tmp = getenv("ZZUF_DEBUGFD");
if(tmp)
#if defined _WIN32
_zz_debugfd = _open_osfhandle((HANDLE)atoi(tmp));
_zz_debugfd = _open_osfhandle((long)atoi(tmp), 0);
#else
_zz_debugfd = atoi(tmp);
#endif