From 324d73a32c0a14cacc7c95467370e9d32693a9ab Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 3 Dec 2014 21:55:31 +0100 Subject: [PATCH] marshal: ensure we correctly handle signed result from serialization We must handle correctly `ssize_t`. Try to not cast this to another type, let alone a non signed type. --- src/daemon/client.c | 22 +++++++++++----------- src/daemon/lldpd.c | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/daemon/client.c b/src/daemon/client.c index e8d2c1fa..6e8fdca6 100644 --- a/src/daemon/client.c +++ b/src/daemon/client.c @@ -18,7 +18,7 @@ #include "lldpd.h" #include "trace.h" -static int +static ssize_t client_handle_none(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len, void **output, int *subscribed) { @@ -28,7 +28,7 @@ client_handle_none(struct lldpd *cfg, enum hmsg_type *type, } /* Return the global configuration */ -static int +static ssize_t client_handle_get_configuration(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len, void **output, int *subscribed) { @@ -50,7 +50,7 @@ xstrdup(const char *str) } /* Change the global configuration */ -static int +static ssize_t client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len, void **output, int *subscribed) { @@ -187,13 +187,13 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, Input: nothing. Output: list of interface names (lldpd_interface_list) */ -static int +static ssize_t client_handle_get_interfaces(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len, void **output, int *subscribed) { struct lldpd_interface *iff, *iff_next; struct lldpd_hardware *hardware; - int output_len; + ssize_t output_len; /* Build the list of interfaces */ struct lldpd_interface_list ifs; @@ -230,7 +230,7 @@ client_handle_get_interfaces(struct lldpd *cfg, enum hmsg_type *type, Input: name of the interface (serialized) Output: Information about the interface (lldpd_hardware) */ -static int +static ssize_t client_handle_get_interface(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len, void **output, int *subscribed) { @@ -249,7 +249,7 @@ client_handle_get_interface(struct lldpd *cfg, enum hmsg_type *type, log_debug("rpc", "client request interface %s", name); TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) if (!strcmp(hardware->h_ifname, name)) { - int output_len = lldpd_hardware_serialize(hardware, output); + ssize_t output_len = lldpd_hardware_serialize(hardware, output); free(name); if (output_len <= 0) { *type = NONE; @@ -268,7 +268,7 @@ client_handle_get_interface(struct lldpd *cfg, enum hmsg_type *type, Input: name of the interface, policy/location/power setting to be modified Output: nothing */ -static int +static ssize_t client_handle_set_port(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len, void **output, int *subscribed) { @@ -369,7 +369,7 @@ set_port_finished: } /* Register subscribtion to neighbor changes */ -static int +static ssize_t client_handle_subscribe(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len, void **output, int *subscribed) { @@ -381,7 +381,7 @@ client_handle_subscribe(struct lldpd *cfg, enum hmsg_type *type, struct client_handle { enum hmsg_type type; const char *name; - int (*handle)(struct lldpd*, enum hmsg_type *, + ssize_t (*handle)(struct lldpd*, enum hmsg_type *, void *, int, void **, int *); }; @@ -403,7 +403,7 @@ client_handle_client(struct lldpd *cfg, int *subscribed) { struct client_handle *ch; - void *answer; size_t len, sent; + void *answer; ssize_t len, sent; log_debug("rpc", "handle client request"); for (ch = client_handles; ch->handle != NULL; ch++) { diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 4ccf4e00..33cb90ca 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -298,7 +298,7 @@ lldpd_reset_timer(struct lldpd *cfg) struct lldpd_port *port = &hardware->h_lport; u_int16_t cksum; u_int8_t *output = NULL; - size_t output_len; + ssize_t output_len; char save[offsetof(struct lldpd_port, p_id_subtype)]; memcpy(save, port, sizeof(save)); /* coverity[suspicious_sizeof] -- 2.39.5