- Timestamp:
- Nov 23, 2009, 1:27:05 AM (13 years ago)
- Location:
- zzuf/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/configure.ac
r4006 r4011 79 79 80 80 AC_MSG_CHECKING(for FILE* internal members) 81 ac_cv_have_glibc_fp="no" 81 82 ac_v_fp_cnt="unknown" 82 83 ac_v_fp_ptr="unknown" 83 84 AC_TRY_COMPILE([#include <stdio.h>], 84 [FILE *fp; fp->_ _cnt++; fp->__ptr++],85 [ac_ v_fp_cnt=__cnt; ac_v_fp_ptr=__ptr],85 [FILE *fp; fp->_IO_read_ptr++; fp->_IO_read_end++], 86 [ac_cv_have_glibc_fp=yes; ac_v_fp_cnt=_IO_read_end; ac_v_fp_ptr=_IO_read_ptr], 86 87 [AC_TRY_COMPILE([#include <stdio.h>], 87 [FILE *fp; fp->_ cnt++; fp->_ptr++],88 [ac_v_fp_cnt=_ cnt; ac_v_fp_ptr=_ptr],88 [FILE *fp; fp->__cnt++; fp->__ptr++], 89 [ac_v_fp_cnt=__cnt; ac_v_fp_ptr=__ptr], 89 90 [AC_TRY_COMPILE([#include <stdio.h>], 90 [FILE *fp; fp->_c ++; fp->_p++],91 [ac_v_fp_cnt=_c ; ac_v_fp_ptr=_p],91 [FILE *fp; fp->_cnt++; fp->_ptr++], 92 [ac_v_fp_cnt=_cnt; ac_v_fp_ptr=_ptr], 92 93 [AC_TRY_COMPILE([#include <stdio.h>], 93 [FILE *fp; fp->_r++; fp->_p++], 94 [ac_v_fp_cnt=_r; ac_v_fp_ptr=_p])])])]) 95 AC_MSG_RESULT($ac_v_fp_cnt/$ac_v_fp_ptr) 96 AC_DEFINE_UNQUOTED(FILE_CNT, $ac_v_fp_cnt, [Define to the FILE::cnt member name]) 97 AC_DEFINE_UNQUOTED(FILE_PTR, $ac_v_fp_ptr, [Define to the FILE::ptr member name]) 94 [FILE *fp; fp->_c++; fp->_p++], 95 [ac_v_fp_cnt=_c; ac_v_fp_ptr=_p], 96 [AC_TRY_COMPILE([#include <stdio.h>], 97 [FILE *fp; fp->_r++; fp->_p++], 98 [ac_v_fp_cnt=_r; ac_v_fp_ptr=_p])])])])]) 99 AC_MSG_RESULT($ac_v_fp_ptr/$ac_v_fp_cnt) 100 if test "$ac_cv_have_glibc_fp" != "no"; then 101 AC_DEFINE(HAVE_GLIBC_FP, 1, [Define to 1 if FILE has glibc-style members]) 102 fi 103 AC_DEFINE_UNQUOTED(FILE_PTR, $ac_v_fp_ptr, [Define to the FILE::ptr member]) 104 AC_DEFINE_UNQUOTED(FILE_CNT, $ac_v_fp_cnt, [Define to the FILE::cnt member]) 98 105 99 106 dnl On HP-UX, fpos64_t == int64_t, but on Linux it's a compound object. -
zzuf/trunk/msvc/config.h
r4006 r4011 50 50 #define HAVE_GETPAGESIZE 1 51 51 #define HAVE_GETTIMEOFDAY 1 52 /* #undef HAVE_GLIBC_FP */ 52 53 #define HAVE_INTTYPES_H 1 53 54 #define HAVE_IO_H 1 -
zzuf/trunk/src/lib-stream.c
r3981 r4011 1 1 /* 2 2 * zzuf - general purpose fuzzer 3 * Copyright (c) 2006 Sam Hocevar <sam@zoy.org>3 * Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net> 4 4 * All Rights Reserved 5 5 * … … 60 60 #endif 61 61 62 #if defined HAVE___UFLOW 63 int NEW(__uflow)(FILE *fp); 64 #endif 65 62 66 /* Library functions that we divert */ 63 67 static FILE * (*ORIG(fopen)) (const char *path, const char *mode); … … 135 139 FILE *stream); 136 140 #endif 141 #if defined HAVE___UFLOW 142 static int (*ORIG(__uflow)) (FILE *fp); 143 #endif 137 144 138 145 /* Additional BSDisms */ … … 152 159 #endif 153 160 161 /* Helper functions for refill-like functions */ 162 #if defined HAVE___FILBUF || defined HAVE___SRGET || defined HAVE___UFLOW 163 static inline uint8_t *get_stream_ptr(FILE *stream) 164 { 165 return (uint8_t *)stream->FILE_PTR; 166 } 167 168 static inline int get_stream_cnt(FILE *stream) 169 { 170 # if defined HAVE_GLIBC_FP 171 return (int)((uint8_t *)stream->FILE_CNT - (uint8_t *)stream->FILE_PTR); 172 # else 173 return stream->FILE_CNT; 174 # endif 175 } 176 #endif 177 154 178 /* Our function wrappers */ 155 179 #if defined REFILL_ONLY_STDIO /* Fuzz fp if we have __srefill() */ 156 180 # define FOPEN_FUZZ() \ 157 _zz_fuzz(fd, ret->FILE_PTR, ret->FILE_CNT)181 _zz_fuzz(fd, get_stream_ptr(ret), get_stream_cnt(ret)) 158 182 #else 159 183 # define FOPEN_FUZZ() 160 184 #endif 185 186 #define BEGIN_STREAM(fp) \ 187 debug2("oldstream([%i], %p, %i)", fileno(fp), \ 188 get_stream_ptr(fp), get_stream_cnt(fp)); 189 190 #define END_STREAM(fp) \ 191 debug2("newstream([%i], %p, %i)", fileno(fp), \ 192 get_stream_ptr(fp), get_stream_cnt(fp)); 161 193 162 194 #define FOPEN(fn) \ … … 174 206 _zz_register(fd); \ 175 207 debug("%s(\"%s\", \"%s\") = [%i]", __func__, path, mode, fd); \ 208 END_STREAM(ret); \ 176 209 FOPEN_FUZZ(); \ 177 210 } \ … … 270 303 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 271 304 return ORIG(fn)(stream, offset, whence); \ 305 BEGIN_STREAM(stream); \ 272 306 _zz_lock(fd); \ 273 307 ret = ORIG(fn)(stream, offset, whence); \ … … 276 310 fd, (long long int)offset, whence, ret); \ 277 311 FSEEK_FUZZ(fn2) \ 312 END_STREAM(stream); \ 278 313 } while(0) 279 314 … … 312 347 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 313 348 return ORIG(fn)(stream, pos); \ 349 BEGIN_STREAM(stream); \ 314 350 _zz_lock(fd); \ 315 351 ret = ORIG(fn)(stream, pos); \ … … 318 354 fd, (long long int)FPOS_CAST(*pos), ret); \ 319 355 _zz_setpos(fd, (int64_t)FPOS_CAST(*pos)); \ 356 END_STREAM(stream); \ 320 357 } \ 321 358 while(0) … … 359 396 } 360 397 361 #if defined HAVE___FILBUF || defined HAVE___SRGET 398 #if defined HAVE___FILBUF || defined HAVE___SRGET || defined HAVE___UFLOW 362 399 # define FREAD_PREFUZZ() \ 363 400 do \ … … 428 465 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 429 466 return ORIG(fn)(ptr, size, nmemb, stream); \ 467 BEGIN_STREAM(stream); \ 430 468 pos = ftell(stream); \ 431 469 _zz_lock(fd); \ … … 434 472 FREAD_PREFUZZ(); \ 435 473 FREAD_FUZZ(); \ 474 END_STREAM(stream); \ 436 475 } while(0) 437 476 … … 449 488 #endif 450 489 451 #if defined HAVE___FILBUF || defined HAVE___SRGET 490 #if defined HAVE___FILBUF || defined HAVE___SRGET || defined HAVE___UFLOW 452 491 # define FGETC_PREFUZZ already_fuzzed = _zz_getfuzzed(fd); 453 492 #else … … 476 515 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 477 516 return ORIG(fn)(arg); \ 517 BEGIN_STREAM(s); \ 478 518 _zz_lock(fd); \ 479 519 ret = ORIG(fn)(arg); \ … … 485 525 else \ 486 526 debug("%s([%i]) = '%c'", __func__, fd, ret); \ 527 END_STREAM(s); \ 487 528 } while(0) 488 529 … … 584 625 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 585 626 return ORIG(fn)(s, size, stream); \ 627 BEGIN_STREAM(s); \ 586 628 FGETS_FUZZ(fn, fn2) \ 587 629 debug("%s(%p, %i, [%i]) = %p", __func__, s, size, fd, ret); \ 630 END_STREAM(s); \ 588 631 } while(0) 589 632 … … 609 652 return ORIG(ungetc)(c, stream); 610 653 654 BEGIN_STREAM(stream); 611 655 _zz_lock(fd); 612 656 ret = ORIG(ungetc)(c, stream); … … 629 673 else 630 674 debug("%s(0x%02x, [%i]) = '%c'", __func__, c, fd, ret); 631 675 END_STREAM(stream); 632 676 return ret; 633 677 } … … 642 686 return ORIG(fclose)(fp); 643 687 688 BEGIN_STREAM(fp); 644 689 _zz_lock(fd); 645 690 ret = ORIG(fclose)(fp); … … 661 706 fd = fileno(stream); \ 662 707 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 663 return ORIG(getdelim)(lineptr, n, delim, stream); \ 708 { \ 709 ret = ORIG(getdelim)(lineptr, n, delim, stream); \ 710 break; \ 711 } \ 712 BEGIN_STREAM(stream); \ 664 713 line = *lineptr; \ 665 714 size = line ? *n : 0; \ … … 704 753 debug("%s(%p, %p, [%i]) = %li", __func__, \ 705 754 lineptr, n, fd, (long int)ret); \ 706 return ret; \ 755 END_STREAM(stream); \ 756 break; \ 707 757 } while(0) 708 758 … … 745 795 return ORIG(fgetln)(stream, len); 746 796 797 BEGIN_STREAM(stream); 747 798 #if defined REFILL_ONLY_STDIO /* Don't fuzz or seek if we have __srefill() */ 748 799 _zz_lock(fd); … … 779 830 780 831 debug("%s([%i], &%li) = %p", __func__, fd, (long int)*len, ret); 832 END_STREAM(stream); 781 833 return ret; 782 834 } 835 #endif 836 837 #if defined HAVE___FILBUF || defined HAVE___SRGET 838 # define REFILL_RETURNS_INT 1 839 #elif defined HAVE___UFLOW 840 # define REFILL_RETURNS_INT 0 783 841 #endif 784 842 … … 793 851 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 794 852 return ORIG(fn)(fp); \ 853 BEGIN_STREAM(fp); \ 795 854 pos = _zz_getpos(fd); \ 796 855 _zz_lock(fd); \ … … 805 864 uint8_t ch = (uint8_t)(unsigned int)ret; \ 806 865 if(newpos != -1) \ 807 _zz_setpos(fd, newpos - fp->FILE_CNT- 1); \866 _zz_setpos(fd, newpos - get_stream_cnt(fp) - 1); \ 808 867 already_fuzzed = _zz_getfuzzed(fd); \ 809 868 _zz_fuzz(fd, &ch, 1); \ 810 ret = fp->FILE_PTR[-1] = ch; \811 _zz_setfuzzed(fd, fp->FILE_CNT+ 1); \869 ret = get_stream_ptr(fp)[-1] = ch; \ 870 _zz_setfuzzed(fd, get_stream_cnt(fp) + 1); \ 812 871 _zz_addpos(fd, 1); \ 813 872 } \ 814 873 else \ 815 874 { \ 816 _zz_setfuzzed(fd, fp->FILE_CNT); \875 _zz_setfuzzed(fd, get_stream_cnt(fp)); \ 817 876 if(newpos != -1) \ 818 _zz_setpos(fd, newpos - fp->FILE_CNT); \877 _zz_setpos(fd, newpos - get_stream_cnt(fp)); \ 819 878 } \ 820 if( fp->FILE_CNT> already_fuzzed) \879 if(get_stream_cnt(fp) > already_fuzzed) \ 821 880 { \ 822 881 _zz_addpos(fd, already_fuzzed); \ 823 _zz_fuzz(fd, fp->FILE_PTR, fp->FILE_CNT - already_fuzzed); \ 882 _zz_fuzz(fd, get_stream_ptr(fp), \ 883 get_stream_cnt(fp) - already_fuzzed); \ 824 884 } \ 825 _zz_addpos(fd, fp->FILE_CNT- already_fuzzed); \885 _zz_addpos(fd, get_stream_cnt(fp) - already_fuzzed); \ 826 886 } \ 827 887 _zz_setpos(fd, pos); /* FIXME: do we always need to do this? */ \ 828 debug("%s([%i]) = %i", __func__, fd, ret); \ 888 if (REFILL_RETURNS_INT) \ 889 debug("%s([%i]) = %i", __func__, fd, ret); \ 890 else if (ret == EOF) \ 891 debug("%s([%i]) = EOF", __func__, fd, ret); \ 892 else \ 893 debug("%s([%i]) = '%c'", __func__, fd, ret); \ 894 END_STREAM(fp); \ 829 895 } \ 830 896 while(0) … … 851 917 #endif 852 918 919 #if defined HAVE___UFLOW 920 int NEW(__uflow)(FILE *fp) 921 { 922 int ret; REFILL(__uflow, 1); return ret; 923 } 924 #endif 925
Note: See TracChangeset
for help on using the changeset viewer.