summaryrefslogtreecommitdiffstats
path: root/daemon/device.c
diff options
context:
space:
mode:
authorGravatar Hector Martin2010-02-01 18:29:37 +0100
committerGravatar Hector Martin2010-02-01 18:29:37 +0100
commit003e72659b579e4376d099767f2e757e80d8f2a4 (patch)
tree1c8559a59a764d63c0462f4beb103cb72deb3d12 /daemon/device.c
parent9932ebe49a47c929c8345625a907e5d4e73fe3d5 (diff)
downloadusbmuxd-003e72659b579e4376d099767f2e757e80d8f2a4.tar.gz
usbmuxd-003e72659b579e4376d099767f2e757e80d8f2a4.tar.bz2
Don't crash on TCP junk during device init
Diffstat (limited to 'daemon/device.c')
-rw-r--r--daemon/device.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/daemon/device.c b/daemon/device.c
index 759cb91..824edac 100644
--- a/daemon/device.c
+++ b/daemon/device.c
@@ -461,12 +461,18 @@ static void device_version_input(struct mux_device *dev, struct version_header *
static void device_tcp_input(struct mux_device *dev, struct tcphdr *th, unsigned char *payload, uint32_t payload_length)
{
- usbmuxd_log(LL_DEBUG, "[IN] dev=%d sport=%d dport=%d seq=%d ack=%d flags=0x%x window=%d[%d] len=%d",
- dev->id, ntohs(th->th_sport), ntohs(th->th_dport), ntohl(th->th_seq), ntohl(th->th_ack), th->th_flags, ntohs(th->th_win) << 8, ntohs(th->th_win), payload_length);
-
uint16_t sport = ntohs(th->th_dport);
uint16_t dport = ntohs(th->th_sport);
struct mux_connection *conn = NULL;
+
+ usbmuxd_log(LL_DEBUG, "[IN] dev=%d sport=%d dport=%d seq=%d ack=%d flags=0x%x window=%d[%d] len=%d",
+ dev->id, dport, sport, ntohl(th->th_seq), ntohl(th->th_ack), th->th_flags, ntohs(th->th_win) << 8, ntohs(th->th_win), payload_length);
+
+ if(dev->state != MUXDEV_ACTIVE) {
+ usbmuxd_log(LL_ERROR, "Received TCP packet from device %d but the device isn't active yet, discarding\n", dev->id);
+ return;
+ }
+
FOREACH(struct mux_connection *lconn, &dev->connections) {
if(lconn->sport == sport && lconn->dport == dport) {
conn = lconn;