Changeset 1747


Ignore:
Timestamp:
Feb 19, 2007, 11:25:54 AM (13 years ago)
Author:
Sam Hocevar
Message:
  • Check mmap() return value.
  • Don't pass offsets to mmap() that are not page aligned.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/test/zzcat.c

    r1746 r1747  
    113113        for(i = 0; i < 128; i++)
    114114        {
    115             int moff = myrand() % len;
    116             int mlen = myrand() % (len - moff);
    117             char *map = mmap(NULL, mlen, PROT_READ, MAP_PRIVATE, fd, moff);
     115            char *map;
     116            int moff, mlen, pgsz = len + 1;
     117#ifdef HAVE_GETPAGESIZE
     118            pgsz = getpagesize();
     119#endif
     120            moff = len < pgsz ? 0 : (myrand() % (len / pgsz)) * pgsz;
     121            mlen = 1 + (myrand() % (len - moff));
     122            map = mmap(NULL, mlen, PROT_READ, MAP_PRIVATE, fd, moff);
     123            if(map == MAP_FAILED)
     124                return EXIT_FAILURE;
    118125            for(j = 0; j < 128; j++)
    119126            {
    120127                int x = myrand() % mlen;
    121                 data[moff + x] = data[x];
     128                data[moff + x] = map[x];
    122129            }
    123130            munmap(map, mlen);
     
    125132#endif
    126133        close(fd);
     134        break;
     135    default:
     136        return EXIT_FAILURE;
    127137    }
    128138
Note: See TracChangeset for help on using the changeset viewer.