From 1549e0a614fb38ec3237c79debf85ae653d6dd28 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 12 Jul 2013 14:04:05 +0300 Subject: [PATCH] input: Fix rejecting connections from unknown devices --- profiles/input/device.c | 8 ++++++++ profiles/input/device.h | 1 + profiles/input/server.c | 14 ++++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/profiles/input/device.c b/profiles/input/device.c index a8d596402..652316121 100644 --- a/profiles/input/device.c +++ b/profiles/input/device.c @@ -930,6 +930,14 @@ error: return err; } +bool input_device_exists(const bdaddr_t *src, const bdaddr_t *dst) +{ + if (find_device(src, dst)) + return true; + + return false; +} + int input_device_set_channel(const bdaddr_t *src, const bdaddr_t *dst, int psm, GIOChannel *io) { diff --git a/profiles/input/device.h b/profiles/input/device.h index 39c642d7b..da2149cdc 100644 --- a/profiles/input/device.h +++ b/profiles/input/device.h @@ -32,6 +32,7 @@ void input_set_idle_timeout(int timeout); int input_device_register(struct btd_service *service); void input_device_unregister(struct btd_service *service); +bool input_device_exists(const bdaddr_t *src, const bdaddr_t *dst); int input_device_set_channel(const bdaddr_t *src, const bdaddr_t *dst, int psm, GIOChannel *io); int input_device_close_channels(const bdaddr_t *src, const bdaddr_t *dst); diff --git a/profiles/input/server.c b/profiles/input/server.c index 65631e6b8..21d4562b1 100644 --- a/profiles/input/server.c +++ b/profiles/input/server.c @@ -168,12 +168,15 @@ static void confirm_event_cb(GIOChannel *chan, gpointer user_data) goto drop; } + ba2str(&dst, addr); + if (server->confirm) { - char address[18]; + error("Refusing connection from %s: setup in progress", addr); + goto drop; + } - ba2str(&dst, address); - error("Refusing connection from %s: setup in progress", - address); + if (!input_device_exists(&src, &dst)) { + error("Refusing connection from %s: unknown device", addr); goto drop; } @@ -184,8 +187,7 @@ static void confirm_event_cb(GIOChannel *chan, gpointer user_data) if (ret != 0) return; - ba2str(&src, addr); - error("input: authorization for %s failed", addr); + error("input: authorization for device %s failed", addr); g_io_channel_unref(server->confirm); server->confirm = NULL; -- 2.47.3