* Better ungetc() implementation. Now we don't need to care about the
fuzzing method.
This commit is contained in:
parent
f0610fc22b
commit
b4fbf4c088
1
src/fd.c
1
src/fd.c
@ -256,6 +256,7 @@ void _zz_register(int fd)
|
||||
#if defined HAVE_FGETLN
|
||||
files[i].fuzz.tmp = NULL;
|
||||
#endif
|
||||
files[i].fuzz.uflag = 0;
|
||||
|
||||
if(autoinc)
|
||||
seed++;
|
||||
|
||||
10
src/fuzz.c
10
src/fuzz.c
@ -152,7 +152,7 @@ void _zz_fuzz(int fd, volatile uint8_t *buf, uint64_t len)
|
||||
if(j >= r[0] && (r[0] == r[1] || j < r[1]))
|
||||
goto range_ok;
|
||||
|
||||
continue; /* Not in a range */
|
||||
continue; /* Not in one of the ranges, skip byte */
|
||||
|
||||
range_ok:
|
||||
byte = aligned_buf[j];
|
||||
@ -168,6 +168,14 @@ void _zz_fuzz(int fd, volatile uint8_t *buf, uint64_t len)
|
||||
aligned_buf[j] = byte;
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle ungetc() */
|
||||
if(fuzz->uflag)
|
||||
{
|
||||
fuzz->uflag = 0;
|
||||
if(fuzz->upos == pos)
|
||||
buf[0] = fuzz->uchar;
|
||||
}
|
||||
}
|
||||
|
||||
static void readchars(int *table, char const *list)
|
||||
|
||||
@ -378,7 +378,6 @@ char *NEW(fgets)(char *s, int size, FILE *stream)
|
||||
|
||||
int NEW(ungetc)(int c, FILE *stream)
|
||||
{
|
||||
unsigned char ch = c;
|
||||
int ret, fd;
|
||||
|
||||
LOADSYM(ungetc);
|
||||
@ -386,22 +385,21 @@ int NEW(ungetc)(int c, FILE *stream)
|
||||
if(!_zz_ready || !_zz_iswatched(fd))
|
||||
return ORIG(ungetc)(c, stream);
|
||||
|
||||
#if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
|
||||
#else
|
||||
_zz_addpos(fd, -1);
|
||||
_zz_fuzz(fd, &ch, 1);
|
||||
#endif
|
||||
_zz_lock(fd);
|
||||
ret = ORIG(ungetc)((int)ch, stream);
|
||||
ret = ORIG(ungetc)(c, stream);
|
||||
_zz_unlock(fd);
|
||||
|
||||
if(ret >= 0)
|
||||
ret = c;
|
||||
if(ret != EOF)
|
||||
{
|
||||
struct fuzz *fuzz = _zz_getfuzz(fd);
|
||||
fuzz->uflag = 1;
|
||||
fuzz->upos = _zz_getpos(fd) - 1;
|
||||
fuzz->uchar = c;
|
||||
#if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
|
||||
#else
|
||||
else
|
||||
_zz_addpos(fd, 1); /* revert what we did */
|
||||
_zz_addpos(fd, -1);
|
||||
#endif
|
||||
}
|
||||
|
||||
debug("%s(0x%02x, [%i]) = '%c'", __func__, c, fd, ret);
|
||||
return ret;
|
||||
|
||||
@ -38,6 +38,7 @@ struct fuzz
|
||||
#ifdef HAVE_FGETLN
|
||||
char *tmp;
|
||||
#endif
|
||||
int uflag; uint64_t upos; uint8_t uchar; /* ungetc stuff */
|
||||
uint8_t data[CHUNKBYTES];
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user