* 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
|
#if defined HAVE_FGETLN
|
||||||
files[i].fuzz.tmp = NULL;
|
files[i].fuzz.tmp = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
files[i].fuzz.uflag = 0;
|
||||||
|
|
||||||
if(autoinc)
|
if(autoinc)
|
||||||
seed++;
|
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]))
|
if(j >= r[0] && (r[0] == r[1] || j < r[1]))
|
||||||
goto range_ok;
|
goto range_ok;
|
||||||
|
|
||||||
continue; /* Not in a range */
|
continue; /* Not in one of the ranges, skip byte */
|
||||||
|
|
||||||
range_ok:
|
range_ok:
|
||||||
byte = aligned_buf[j];
|
byte = aligned_buf[j];
|
||||||
@ -168,6 +168,14 @@ void _zz_fuzz(int fd, volatile uint8_t *buf, uint64_t len)
|
|||||||
aligned_buf[j] = byte;
|
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)
|
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)
|
int NEW(ungetc)(int c, FILE *stream)
|
||||||
{
|
{
|
||||||
unsigned char ch = c;
|
|
||||||
int ret, fd;
|
int ret, fd;
|
||||||
|
|
||||||
LOADSYM(ungetc);
|
LOADSYM(ungetc);
|
||||||
@ -386,22 +385,21 @@ int NEW(ungetc)(int c, FILE *stream)
|
|||||||
if(!_zz_ready || !_zz_iswatched(fd))
|
if(!_zz_ready || !_zz_iswatched(fd))
|
||||||
return ORIG(ungetc)(c, stream);
|
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);
|
_zz_lock(fd);
|
||||||
ret = ORIG(ungetc)((int)ch, stream);
|
ret = ORIG(ungetc)(c, stream);
|
||||||
_zz_unlock(fd);
|
_zz_unlock(fd);
|
||||||
|
|
||||||
if(ret >= 0)
|
if(ret != EOF)
|
||||||
ret = c;
|
{
|
||||||
|
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() */
|
#if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
|
||||||
#else
|
#else
|
||||||
else
|
_zz_addpos(fd, -1);
|
||||||
_zz_addpos(fd, 1); /* revert what we did */
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
debug("%s(0x%02x, [%i]) = '%c'", __func__, c, fd, ret);
|
debug("%s(0x%02x, [%i]) = '%c'", __func__, c, fd, ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@ -38,6 +38,7 @@ struct fuzz
|
|||||||
#ifdef HAVE_FGETLN
|
#ifdef HAVE_FGETLN
|
||||||
char *tmp;
|
char *tmp;
|
||||||
#endif
|
#endif
|
||||||
|
int uflag; uint64_t upos; uint8_t uchar; /* ungetc stuff */
|
||||||
uint8_t data[CHUNKBYTES];
|
uint8_t data[CHUNKBYTES];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user