aboutsummaryrefslogtreecommitdiffstats
path: root/libglouglou/libglouglou.c
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2012-11-29 22:56:17 +0100
committerLaurent Ghigonis <laurent@p1sec.com>2012-11-29 22:56:17 +0100
commit3e85e0c64855c7b5b424a3d2915aca8ab39d6ecd (patch)
treeff08f9ffcfa83f3629e2de7c5196b9d1611b116f /libglouglou/libglouglou.c
parentuse user_send() instead of directly sendto() (diff)
downloadglouglou-3e85e0c64855c7b5b424a3d2915aca8ab39d6ecd.tar.xz
glouglou-3e85e0c64855c7b5b424a3d2915aca8ab39d6ecd.zip
don't go into packet decoding if the user did not set a handle_packet callback.
this makes probes that runs as root less exposed if they don't register this callback.
Diffstat (limited to 'libglouglou/libglouglou.c')
-rw-r--r--libglouglou/libglouglou.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/libglouglou/libglouglou.c b/libglouglou/libglouglou.c
index 743bc53..275e033 100644
--- a/libglouglou/libglouglou.c
+++ b/libglouglou/libglouglou.c
@@ -71,9 +71,9 @@ gg_server_start(struct event_base *ev_base, char *ip, int port,
sizeof(sock_addr)) != 0)
goto err;
- ev = event_new(ev_base, s, EV_READ|EV_PERSIST, cb_srv_receive, srv);
- event_add(ev, NULL);
- srv->ev = ev;
+ ev = event_new(ev_base, s, EV_READ|EV_PERSIST, cb_srv_receive, srv);
+ event_add(ev, NULL);
+ srv->ev = ev;
return srv;
@@ -156,14 +156,15 @@ void cb_srv_receive(evutil_socket_t fd, short what, void *arg)
user_del(srv, usr);
return;
}
- buf_p = buf;
- buf_len = len;
- while (buf_len > 0 && (pkt = pkt_decode(&buf_p, &buf_len)))
- if (srv->handle_packet)
+ if (srv->handle_packet) {
+ buf_p = buf;
+ buf_len = len;
+ while (buf_len > 0 && (pkt = pkt_decode(&buf_p, &buf_len)))
srv->handle_packet(srv, usr, pkt);
- if (buf_len > 0) {
- /* XXX store incomplete packet for next recv */
- printf("srv: incomplete packet, dropped %d bytes !\n", buf_len);
+ if (buf_len > 0) {
+ /* XXX store incomplete packet for next recv */
+ printf("srv: incomplete packet, dropped %d bytes !\n", buf_len);
+ }
}
}
}
@@ -260,9 +261,9 @@ gg_client_connect(struct event_base *ev_base, char *ip, int port,
sock_addr.sin_port=htons(port);
addrcpy(&cli->addr, &sock_addr);
- ev = event_new(ev_base, s, EV_READ|EV_PERSIST, cb_cli_receive, cli);
- event_add(ev, NULL);
- cli->ev = ev;
+ ev = event_new(ev_base, s, EV_READ|EV_PERSIST, cb_cli_receive, cli);
+ event_add(ev, NULL);
+ cli->ev = ev;
ev = evtimer_new(ev_base, cb_cli_timer, cli);
cli->ev_timer = ev;
@@ -355,14 +356,15 @@ void cb_cli_receive(evutil_socket_t fd, short what, void *arg)
return;
}
printf("cli: Incoming data !\n");
- buf_p = buf;
- buf_len = len;
- while (buf_len > 0 && (pkt = pkt_decode(&buf_p, &buf_len)))
- if (cli->handle_packet)
+ if (cli->handle_packet) {
+ buf_p = buf;
+ buf_len = len;
+ while (buf_len > 0 && (pkt = pkt_decode(&buf_p, &buf_len)))
cli->handle_packet(cli, pkt);
- if (buf_len > 0) {
- /* XXX store incomplete packet for next recv */
- printf("cli: incomplete packet, dropped %d bytes !\n", buf_len);
+ if (buf_len > 0) {
+ /* XXX store incomplete packet for next recv */
+ printf("cli: incomplete packet, dropped %d bytes !\n", buf_len);
+ }
}
break;
}