- Timestamp:
- Jan 9, 2007, 5:16:00 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/load-fd.c
r1635 r1637 200 200 return ret; 201 201 202 debug("read(%i, %p, %li) = %i", fd, buf, (long int)count, ret);203 202 if(ret > 0) 204 203 { 204 char *b = buf; 205 205 206 _zz_fuzz(fd, buf, ret); 206 207 _zz_addpos(fd, ret); 208 209 if(ret >= 4) 210 debug("read(%i, %p, %li) = %i \"%c%c%c%c...", fd, buf, 211 (long int)count, ret, b[0], b[1], b[2], b[3]); 212 else 213 debug("read(%i, %p, %li) = %i \"%c...", fd, buf, 214 (long int)count, ret, b[0]); 207 215 } 216 else 217 debug("read(%i, %p, %li) = %i", fd, buf, (long int)count, ret); 208 218 209 219 /* Sanity check, can be OK though (for instance with a character device) */ … … 259 269 if(!_zz_ready || !_zz_iswatched(fd) || _zz_disabled) \ 260 270 return ret; \ 261 if(ret ) \271 if(ret && length) \ 262 272 { \ 263 void *tmp= malloc(length); \273 char *b = malloc(length); \ 264 274 int i, oldpos; \ 265 275 for(i = 0; i < nbmaps; i += 2) \ … … 271 281 maps = realloc(maps, nbmaps * sizeof(void *)); \ 272 282 } \ 273 maps[i] = tmp; \283 maps[i] = b; \ 274 284 maps[i + 1] = ret; \ 275 285 oldpos = _zz_getpos(fd); \ 276 286 _zz_setpos(fd, offset); /* mmap() maps the fd at offset 0 */ \ 277 memcpy( tmp, ret, length); /* FIXME: get rid of this */ \278 _zz_fuzz(fd, tmp, length); \287 memcpy(b, ret, length); /* FIXME: get rid of this */ \ 288 _zz_fuzz(fd, (uint8_t *)b, length); \ 279 289 _zz_setpos(fd, oldpos); \ 280 ret = tmp; \ 290 ret = b; \ 291 if(length >= 4) \ 292 debug(STR(fn)"(%p, %li, %i, %i, %i, %lli) = %p \"%c%c%c%c...", \ 293 start, (long int)length, prot, flags, fd, \ 294 (long long int)offset, ret, b[0], b[1], b[2], b[3]); \ 295 else \ 296 debug(STR(fn)"(%p, %li, %i, %i, %i, %lli) = %p \"%c...", \ 297 start, (long int)length, prot, flags, fd, \ 298 (long long int)offset, ret, b[0]); \ 281 299 } \ 282 300 debug(STR(fn)"(%p, %li, %i, %i, %i, %lli) = %p", start, \ … … 332 350 return ret; 333 351 334 if(ret == 0 )352 if(ret == 0 && numbytes) 335 353 { 336 void *tmp = malloc(numbytes); 337 memcpy(tmp, (void *)*addr, numbytes); 338 _zz_fuzz(fd, tmp, numbytes); 339 *addr = (vm_offset_t)tmp; 354 /* FIXME: do we also have to rewind the filedescriptor like in mmap? */ 355 void *b = malloc(numbytes); 356 memcpy(b, (void *)*addr, numbytes); 357 _zz_fuzz(fd, b, numbytes); 358 *addr = (vm_offset_t)b; 340 359 /* FIXME: the map is never freed; there is no such thing as unmap_fd, 341 * but I suppose that kind of map should go when the filedesc iptor is360 * but I suppose that kind of map should go when the filedescriptor is 342 361 * closed (unlike mmap, which returns a persistent buffer). */ 362 363 if(numbytes >= 4) 364 debug("map_fd(%i, %lli, &%p, %i, %lli) = %i \"%c%c%c%c", fd, 365 (long long int)offset, (void *)*addr, (int)find_space, 366 (long long int)numbytes, ret, b[0], b[1], b[2], b[3]); 367 else 368 debug("map_fd(%i, %lli, &%p, %i, %lli) = %i \"%c", fd, 369 (long long int)offset, (void *)*addr, (int)find_space, 370 (long long int)numbytes, ret, b[0]); 343 371 } 344 345 debug("map_fd(%i, %lli, &%p, %i, %lli) = %i", fd, (long long int)offset,346 (void *)*addr, (int)find_space, (long long int)numbytes, ret);372 else 373 debug("map_fd(%i, %lli, &%p, %i, %lli) = %i", fd, (long long int)offset, 374 (void *)*addr, (int)find_space, (long long int)numbytes, ret); 347 375 348 376 return ret;
Note: See TracChangeset
for help on using the changeset viewer.