Mercurial > hg > index.cgi
comparison src/lwwire.c @ 9:a11b330771e0
Fix buffer pointer handling when logging received bytes
Actually save the read buffer pointer so we can log the actual protocol
bytes read in all cases correctly instead of displaying out of bounds memory
in the case where the packet arrives in multiple pieces.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sat, 30 Jul 2016 10:35:14 -0600 |
parents | cf915ece9e48 |
children | 36c4cda4b6c4 |
comparison
equal
deleted
inserted
replaced
8:cf915ece9e48 | 9:a11b330771e0 |
---|---|
383 byte. Otherwise, it will time out even on the first one. | 383 byte. Otherwise, it will time out even on the first one. |
384 | 384 |
385 */ | 385 */ |
386 int lwwire_readdata(void *buf, int len, int itimeout) | 386 int lwwire_readdata(void *buf, int len, int itimeout) |
387 { | 387 { |
388 char *obuf = buf; | |
388 int toread = len; | 389 int toread = len; |
389 int rv; | 390 int rv; |
390 fd_set fdset; | 391 fd_set fdset; |
391 struct timeval timeout; | 392 struct timeval timeout; |
392 | 393 |
461 } | 462 } |
462 // anything else here means we have more bytes to read | 463 // anything else here means we have more bytes to read |
463 } | 464 } |
464 fprintf(stderr, "Protocol bytes read (%d):", len); | 465 fprintf(stderr, "Protocol bytes read (%d):", len); |
465 for (rv = 0; rv < len; rv++) | 466 for (rv = 0; rv < len; rv++) |
466 fprintf(stderr, " %02X ", ((char *)(buf))[rv] & 0xff); | 467 fprintf(stderr, " %02X ", (obuf[rv]) & 0xff); |
467 fprintf(stderr, "\n"); | 468 fprintf(stderr, "\n"); |
468 return len; | 469 return len; |
469 } | 470 } |
470 | 471 |
471 /* | 472 /* |