Changeset 4232


Ignore:
Timestamp:
Jan 6, 2010, 3:00:41 AM (13 years ago)
Author:
Sam Hocevar
Message:

Fix a bug caused by our seek() not understanding eglibc's behaviour.

Location:
zzuf/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/common/fuzz.c

    r4112 r4232  
    9595
    9696#if defined LIBZZUF
    97     debug2("fuzz(%i, @%lli, %lli)", fd, (long long int)pos, (long long int)len);
     97    debug2("... fuzz(%i, @%lli, %lli)", fd, (long long int)pos,
     98           (long long int)len);
    9899#endif
    99100
  • zzuf/trunk/src/libzzuf/lib-stream.c

    r4230 r4232  
    220220static inline void debug_stream(char const *prefix, FILE *stream)
    221221{
    222     debug2("%p stream([%i], %p, %i)", prefix, fileno(stream),
    223            get_stream_ptr(stream), get_stream_cnt(stream));
     222    debug2("... %s stream([%i], %p, %i + %i)", prefix, fileno(stream),
     223           get_stream_ptr(stream), get_stream_off(stream),
     224           get_stream_cnt(stream));
    224225}
    225226
     
    246247            _zz_register(fd); \
    247248            _zz_fuzz(fd, get_stream_ptr(ret), get_stream_cnt(ret)); \
     249            debug_stream("after", ret); \
    248250            debug("%s(\"%s\", \"%s\") = [%i]", __func__, path, mode, fd); \
    249             debug_stream("new", ret); \
    250251        } \
    251252    } while(0)
     
    335336        if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \
    336337            return ORIG(myfseek)(stream, offset, whence); \
    337         debug_stream("old", stream); \
     338        debug_stream("before", stream); \
    338339        /* FIXME: ftell() will return -1 on a pipe such as stdin */ \
    339340        oldpos = MYFTELL(stream); \
     
    344345        _zz_unlock(fd); \
    345346        newpos = MYFTELL(stream); \
    346         if (newpos > oldpos + oldcnt || newpos < oldpos - oldoff) \
     347        if (newpos >= oldpos + oldcnt || newpos < oldpos - oldoff) \
    347348        { \
    348349            _zz_setpos(fd, newpos - get_stream_off(stream)); \
     
    351352        } \
    352353        _zz_setpos(fd, newpos); \
     354        debug_stream("after", stream); \
    353355        debug("%s([%i], %lli, %s) = %i", __func__, \
    354356              fd, (long long int)offset, get_seek_mode_name(whence), ret); \
    355         debug_stream("new", stream); \
    356357    } while(0)
    357358
     
    366367        if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \
    367368            return ORIG(myfsetpos)(stream, pos); \
    368         debug_stream("old", stream); \
     369        debug_stream("before", stream); \
    369370        /* FIXME: ftell() will return -1 on a pipe such as stdin */ \
    370371        oldpos = MYFTELL(stream); \
     
    375376        _zz_unlock(fd); \
    376377        newpos = MYFTELL(stream); \
    377         if (newpos > oldpos + oldcnt || newpos < oldpos - oldoff) \
     378        if (newpos >= oldpos + oldcnt || newpos < oldpos - oldoff) \
    378379        { \
    379380            _zz_setpos(fd, newpos - get_stream_off(stream)); \
     
    382383        } \
    383384        _zz_setpos(fd, (int64_t)FPOS_CAST(*pos)); \
     385        debug_stream("after", stream); \
    384386        debug("%s([%i], %lli) = %i", __func__, \
    385387              fd, (long long int)FPOS_CAST(*pos), ret); \
    386         debug_stream("new", stream); \
    387388    } \
    388389    while(0)
     
    398399        if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \
    399400            return ORIG(rewind)(stream); \
    400         debug_stream("old", stream); \
     401        debug_stream("before", stream); \
    401402        /* FIXME: ftell() will return -1 on a pipe such as stdin */ \
    402403        oldpos = MYFTELL(stream); \
     
    407408        _zz_unlock(fd); \
    408409        newpos = MYFTELL(stream); \
    409         if (newpos > oldpos + oldcnt || newpos < oldpos - oldoff) \
     410        if (newpos >= oldpos + oldcnt || newpos < oldpos - oldoff) \
    410411        { \
    411412            _zz_setpos(fd, newpos - get_stream_off(stream)); \
     
    414415        } \
    415416        _zz_setpos(fd, newpos); \
     417        debug_stream("after", stream); \
    416418        debug("%s([%i])", __func__, fd); \
    417         debug_stream("new", stream); \
    418419    } while(0)
    419420
     
    483484        if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \
    484485            return ORIG(myfread)(ptr, size, nmemb, stream); \
    485         debug_stream("old", stream); \
     486        debug_stream("before", stream); \
    486487        /* FIXME: ftell() will return -1 on a pipe such as stdin */ \
    487488        oldpos = MYFTELL(stream); \
     
    492493        _zz_unlock(fd); \
    493494        newpos = MYFTELL(stream); \
    494         if (newpos > oldpos + oldcnt) \
     495        if (newpos >= oldpos + oldcnt) \
    495496        { \
    496497            /* Fuzz returned data that wasn't in the old internal buffer */ \
     
    503504        } \
    504505        _zz_setpos(fd, newpos); \
    505         if (newpos > oldpos + 4) \
     506        debug_stream("after", stream); \
     507        if (newpos >= oldpos + 4) \
    506508            debug("%s(%p, %li, %li, [%i]) = %li \"%c%c%c%c...", __func__, \
    507509                  ptr, (long int)size, (long int)nmemb, fd, \
     
    514516            debug("%s(%p, %li, %li, [%i]) = %li", __func__, ptr, \
    515517                  (long int)size, (long int)nmemb, fd, (long int)ret); \
    516         debug_stream("new", stream); \
    517518    } while(0)
    518519
     
    548549        if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \
    549550            return ORIG(myfgetc)(arg); \
    550         debug_stream("old", s); \
     551        debug_stream("before", s); \
    551552        oldpos = MYFTELL(s); \
    552553        oldoff = get_stream_off(s); \
     
    564565            ret = ch; \
    565566        } \
    566         if (newpos > oldpos + oldcnt) \
     567        if (newpos >= oldpos + oldcnt) \
    567568        { \
    568569            /* Fuzz the internal stream buffer */ \
     
    572573        } \
    573574        _zz_setpos(fd, newpos); \
     575        debug_stream("after", s); \
    574576        if(ret == EOF) \
    575577            debug("%s([%i]) = EOF", __func__, fd); \
    576578        else \
    577579            debug("%s([%i]) = '%c'", __func__, fd, ret); \
    578         debug_stream("new", s); \
    579580    } while(0)
    580581
     
    643644        if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \
    644645            return ORIG(myfgets)(s, size, stream); \
    645         debug_stream("old", stream); \
     646        debug_stream("before", stream); \
    646647        oldpos = MYFTELL(stream); \
    647648        oldoff = get_stream_off(stream); \
     
    670671                    chr = ch; \
    671672                } \
    672                 if (newpos > oldpos + oldcnt) \
     673                if (newpos >= oldpos + oldcnt) \
    673674                { \
    674675                    /* Fuzz the internal stream buffer, if necessary */ \
     
    696697        } \
    697698        _zz_setpos(fd, newpos); \
     699        debug_stream("after", stream); \
    698700        debug("%s(%p, %i, [%i]) = %p", __func__, s, size, fd, ret); \
    699         debug_stream("new", stream); \
    700701    } while(0)
    701702
     
    725726        return ORIG(ungetc)(c, stream);
    726727
    727     debug_stream("old", stream);
     728    debug_stream("before", stream);
    728729    oldpos = MYFTELL(stream);
    729730    _zz_lock(fd);
     
    732733    _zz_setpos(fd, oldpos - 1);
    733734
     735    debug_stream("after", stream);
    734736    if(ret == EOF)
    735737        debug("%s(0x%02x, [%i]) = EOF", __func__, c, fd);
    736738    else
    737739        debug("%s(0x%02x, [%i]) = '%c'", __func__, c, fd, ret);
    738     debug_stream("new", stream);
    739740    return ret;
    740741}
     
    753754        return ORIG(fclose)(fp);
    754755
    755     debug_stream("old", fp);
     756    debug_stream("before", fp);
    756757    _zz_lock(fd);
    757758    ret = ORIG(fclose)(fp);
     
    780781        if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \
    781782            return ORIG(getdelim)(lineptr, n, delim, stream); \
    782         debug_stream("old", stream); \
     783        debug_stream("before", stream); \
    783784        oldpos = MYFTELL(stream); \
    784785        oldoff = get_stream_off(stream); \
     
    812813                chr = ch; \
    813814            } \
    814             if (newpos > oldpos + oldcnt) \
     815            if (newpos >= oldpos + oldcnt) \
    815816            { \
    816817                /* Fuzz the internal stream buffer, if necessary */ \
     
    839840        } \
    840841        _zz_setpos(fd, newpos); \
     842        debug_stream("after", stream); \
    841843        if(need_delim) \
    842844            debug("%s(%p, %p, '%c', [%i]) = %li", __func__, \
     
    845847            debug("%s(%p, %p, [%i]) = %li", __func__, \
    846848                  lineptr, n, fd, (long int)ret); \
    847         debug_stream("new", stream); \
    848849        break; \
    849850    } while(0)
     
    889890        return ORIG(fgetln)(stream, len);
    890891
    891     debug_stream("old", stream);
     892    debug_stream("before", stream);
    892893    oldpos = MYFTELL(stream);
    893894    oldoff = get_stream_off(stream);
     
    914915            chr = ch;
    915916        }
    916         if (newpos > oldpos + oldcnt)
     917        if (newpos >= oldpos + oldcnt)
    917918        {
    918919            /* Fuzz the internal stream buffer, if necessary */
     
    940941    ret = fuzz->tmp;
    941942
     943    debug_stream("after", stream);
    942944    debug("%s([%i], &%li) = %p", __func__, fd, (long int)*len, ret);
    943     debug_stream("new", stream);
    944945    return ret;
    945946}
     
    966967        if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \
    967968            return ORIG(myrefill)(fp); \
    968         debug_stream("old", fp); \
     969        debug_stream("before", fp); \
    969970        pos = _zz_getpos(fd); \
    970971        _zz_lock(fd); \
     
    10011002        } \
    10021003        _zz_setpos(fd, pos); /* FIXME: do we always need to do this? */ \
     1004        debug_stream("after", fp); \
    10031005        if (REFILL_RETURNS_INT) \
    10041006            debug("%s([%i]) = %i", __func__, fd, ret); \
     
    10071009        else \
    10081010            debug("%s([%i]) = '%c'", __func__, fd, ret); \
    1009         debug_stream("new", fp); \
    10101011    } \
    10111012    while(0)
Note: See TracChangeset for help on using the changeset viewer.