From 6dc848b2c31b4cc57d6ebd753ffdd22fbba22a2b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 4 Aug 2020 11:08:50 +1000 Subject: [PATCH] libei: add a few comments and extra checks Signed-off-by: Peter Hutterer --- src/libei-device.c | 7 +++++++ src/libei-private.h | 1 + src/libei.c | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libei-device.c b/src/libei-device.c index 8aad544..9ac0ed4 100644 --- a/src/libei-device.c +++ b/src/libei-device.c @@ -46,6 +46,7 @@ OBJECT_IMPLEMENT_PARENT(ei_device, ei); _public_ struct ei* ei_device_get_context(struct ei_device *device) { + assert(device); return ei_device_parent(device); } @@ -53,6 +54,8 @@ _public_ struct ei_device * ei_device_new(struct ei *ei) { + /* device IDs are managed by the client, the server merely accepts + * them and fails where they're being reused. */ static uint32_t deviceid = 0; struct ei_device *device = ei_device_create(&ei->object); @@ -67,6 +70,9 @@ _public_ bool ei_device_configure_capability(struct ei_device *device, enum ei_device_capability cap) { + if (device->state != EI_DEVICE_STATE_NEW) + return false; + switch (cap) { case EI_DEVICE_CAP_POINTER: case EI_DEVICE_CAP_POINTER_ABSOLUTE: @@ -83,6 +89,7 @@ _public_ void ei_device_add(struct ei_device *device) { ei_add_device(device); + device->state = EI_DEVICE_STATE_CONNECTING; } _public_ void diff --git a/src/libei-private.h b/src/libei-private.h index f0cb0f1..891553d 100644 --- a/src/libei-private.h +++ b/src/libei-private.h @@ -55,6 +55,7 @@ struct ei { enum ei_device_state { EI_DEVICE_STATE_NEW, + EI_DEVICE_STATE_CONNECTING, EI_DEVICE_STATE_ACCEPTED, EI_DEVICE_STATE_REMOVED, }; diff --git a/src/libei.c b/src/libei.c index 747a27d..d31dc4a 100644 --- a/src/libei.c +++ b/src/libei.c @@ -82,7 +82,6 @@ message_free(struct message *msg) DEFINE_TRIVIAL_CLEANUP_FUNC(struct message*, message_free); - static struct ei_event* ei_event_ref(struct ei_event *event); static void @@ -700,6 +699,12 @@ ei_set_connection(struct ei *ei, int fd) _public_ void ei_configure_name(struct ei *ei, const char *name) { + if (ei->state != EI_STATE_NEW) + return; + + if (strlen(name) > 1024) + return; + free(ei->name); ei->name = xstrdup(name); }