diff options
author | Laurent Ghigonis <laurent@p1sec.com> | 2012-07-22 01:51:51 +0200 |
---|---|---|
committer | Laurent Ghigonis <laurent@p1sec.com> | 2012-07-22 01:51:51 +0200 |
commit | 31b6c26303f7c85aae215a472861450590d29ce6 (patch) | |
tree | 367f08d07b7fd4439d6c0f7311363cc89b136756 /glougloud | |
parent | tweak (diff) | |
download | glouglou-31b6c26303f7c85aae215a472861450590d29ce6.tar.xz glouglou-31b6c26303f7c85aae215a472861450590d29ce6.zip |
fix some pointer arithmetic when mixing pointers with integers : always
cast pointers to (u_char *) before the operation !
Diffstat (limited to 'glougloud')
-rw-r--r-- | glougloud/user.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/glougloud/user.c b/glougloud/user.c index 38caae7..998f666 100644 --- a/glougloud/user.c +++ b/glougloud/user.c @@ -202,7 +202,7 @@ user_init(int fd[2], pcap_t *pcap) * 'pend' is a pointer to the end of the captured IP packet * 'wirelen' is the size of the IP packet off the wire */ -#define NOTCAPTURED(v) ((u_char *)v > pend - sizeof(*v)) +#define NOTCAPTURED(v) ((u_char *)v > (u_char *)pend - sizeof(*v)) #define NOTRECEIVED(v) (wirelen < sizeof(v)) static void ip_handle(struct ip *ip, const u_char *pend, u_int wirelen) @@ -218,7 +218,8 @@ ip_handle(struct ip *ip, const u_char *pend, u_int wirelen) struct conn *c, *conn; if (NOTCAPTURED(ip)) { - log_pinvalid("user: ip truncated"); + log_pinvalid("user: ip truncated (ip %x pend %x sizeof(ip) %d", + ip, pend, sizeof(ip)); cap->ptruncated++; return; } @@ -568,6 +569,7 @@ phandler_ether(u_char *user, const struct pcap_pkthdr *h, const u_char *p) pend = p + h->caplen; len = h->len - sizeof(struct ether_header); + ether_type = ntohs(ep->ether_type); if (ether_type <= ETHERMTU) log_tmp("llc packet !"); @@ -575,7 +577,7 @@ phandler_ether(u_char *user, const struct pcap_pkthdr *h, const u_char *p) switch (ether_type) { case ETHERTYPE_IP: log_tmp("ether IP"); - ip = (struct ip *)(ep + sizeof(struct ether_header)); + ip = (struct ip *)((u_char *)ep + sizeof(struct ether_header)); ip_handle(ip, pend, len); break; default: @@ -625,8 +627,8 @@ phandler_loop(u_char *user, const struct pcap_pkthdr *h, const u_char *p) switch (ether_type) { case ETHERTYPE_IP: log_tmp("loop family AF_LINK IP"); - ip = (struct ip *)(ep + sizeof(*ep)); - len -= NULL_HDRLEN + sizeof (*ep); + ip = (struct ip *)((u_char *)ep + sizeof(*ep)); + len -= NULL_HDRLEN + sizeof(*ep); ip_handle(ip, pend, len); break; default: |