Changeset 4012 for zzuf/trunk


Ignore:
Timestamp:
Nov 23, 2009, 1:27:11 AM (11 years ago)
Author:
Sam Hocevar
Message:

Document the srefill strategy in the source code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/lib-stream.c

    r4011 r4012  
    396396}
    397397
     398/* Compute how many bytes from the stream were already fuzzed by __filbuf,
     399 * __srget or __uflow, and store it in already_fuzzed. If these functions
     400 * are not available, do nothing. */
    398401#if defined HAVE___FILBUF || defined HAVE___SRGET || defined HAVE___UFLOW
    399 #   define FREAD_PREFUZZ() \
     402#   define FREAD_PREFUZZ(fd, pos) \
    400403    do \
    401404    { \
     
    407410    while(0)
    408411#else
    409 #   define FREAD_PREFUZZ() do {} while(0)
    410 #endif
    411 
    412 #if defined REFILL_ONLY_STDIO /* Don't fuzz or seek if we have __srefill() */
    413 #   define FREAD_FUZZ() \
     412#   define FREAD_PREFUZZ(fd, pos) do {} while(0)
     413#endif
     414
     415/* Fuzz the data returned by fread(). If a __fillbuf mechanism already
     416 * fuzzed some of our data, we skip the relevant amount of bytes. If we
     417 * have __srefill, we just do nothing because that function is the only
     418 * one that actually fuzzes things. */
     419#if defined REFILL_ONLY_STDIO
     420#   define FREAD_FUZZ(fd, pos) \
    414421    do \
    415422    { \
     
    418425    } while(0)
    419426#else
    420 #   define FREAD_FUZZ() \
     427#   define FREAD_FUZZ(fd, pos) \
    421428    do \
    422429    { \
     
    440447                _zz_fuzz(fd, ptr, newpos - pos - already_fuzzed); \
    441448            } \
     449            /* FIXME: we need to fuzz the extra bytes that may have been \
     450             * read by the fread call we just made, or subsequent calls \
     451             * to getc_unlocked may miss them. */ \
    442452            _zz_setpos(fd, newpos); \
    443453            if(newpos >= pos + 4) \
     
    470480        ret = ORIG(fn)(ptr, size, nmemb, stream); \
    471481        _zz_unlock(fd); \
    472         FREAD_PREFUZZ(); \
    473         FREAD_FUZZ(); \
     482        FREAD_PREFUZZ(fd, pos); \
     483        FREAD_FUZZ(fd, pos); \
    474484        END_STREAM(stream); \
    475485    } while(0)
     
    700710        char *line; \
    701711        ssize_t done, size; \
    702         int fd, finished = 0; \
     712        int fd, already_fuzzed = 0, finished = 0; \
    703713        LOADSYM(fn); \
    704714        LOADSYM(getdelim); \
Note: See TracChangeset for help on using the changeset viewer.