From 8ec0f4bf7ca3357f824c68eb3aa10c91b4057f32 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 30 Jul 2020 21:01:09 +1000 Subject: [PATCH] Send the trailing null byte for composed string messages The iobuf treats this as binary data but then we're using it as strings in the message parsing code. So make sure all messages have a trailing null byte. Signed-off-by: Peter Hutterer --- src/libei.c | 8 ++++---- src/libeis-client.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libei.c b/src/libei.c index 2c1269f..85a7495 100644 --- a/src/libei.c +++ b/src/libei.c @@ -222,7 +222,7 @@ connection_send_connect(struct ei *ei) ei->name ? ei->name : "unnamed")) return -ENOMEM; - return min(0, xwrite(source_get_fd(ei->source), buf, strlen(buf))); + return min(0, xwrite(source_get_fd(ei->source), buf, strlen(buf) + 1)); } static int @@ -246,7 +246,7 @@ connection_send_add(struct ei *ei, struct ei_device *device) if (!xsnprintf(buf, sizeof(buf), "add %d %d\n", device->id, device->capabilities)) return -ENOMEM; - return min(0, xwrite(source_get_fd(ei->source), buf, strlen(buf))); + return min(0, xwrite(source_get_fd(ei->source), buf, strlen(buf) + 1)); } static int @@ -260,7 +260,7 @@ connection_send_remove(struct ei *ei, struct ei_device *device) if (!xsnprintf(buf, sizeof(buf), "remove %d\n", device->id)) return -ENOMEM; - return min(0, xwrite(source_get_fd(ei->source), buf, strlen(buf))); + return min(0, xwrite(source_get_fd(ei->source), buf, strlen(buf) + 1)); } static int @@ -274,7 +274,7 @@ connection_send_rel(struct ei *ei, struct ei_device *device, int32_t x, int32_t if (!xsnprintf(buf, sizeof(buf), "rel %d %d %d\n", device->id, x, y)) return -ENOMEM; - return min(0, xwrite(source_get_fd(ei->source), buf, strlen(buf))); + return min(0, xwrite(source_get_fd(ei->source), buf, strlen(buf) + 1)); } static void diff --git a/src/libeis-client.c b/src/libeis-client.c index 0e361e0..6419e7b 100644 --- a/src/libeis-client.c +++ b/src/libeis-client.c @@ -141,7 +141,7 @@ client_send_accepted(struct eis_client *client, struct eis_device *device) if (!xsnprintf(buf, sizeof(buf), "accept %d\n", device->id)) return -ENOMEM; - return min(0, xwrite(source_get_fd(client->source), buf, strlen(buf))); + return min(0, xwrite(source_get_fd(client->source), buf, strlen(buf) + 1)); } static int @@ -152,7 +152,7 @@ client_send_removed(struct eis_client *client, struct eis_device *device) if (!xsnprintf(buf, sizeof(buf), "remove %d\n", device->id)) return -ENOMEM; - return min(0, xwrite(source_get_fd(client->source), buf, strlen(buf))); + return min(0, xwrite(source_get_fd(client->source), buf, strlen(buf) + 1)); } _public_ void