]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
marshal: ensure we correctly handle signed result from serialization
authorVincent Bernat <vincent@bernat.im>
Wed, 3 Dec 2014 20:55:31 +0000 (21:55 +0100)
committerVincent Bernat <vincent@bernat.im>
Wed, 3 Dec 2014 21:00:28 +0000 (22:00 +0100)
We must handle correctly `ssize_t`. Try to not cast this to another
type, let alone a non signed type.

src/daemon/client.c
src/daemon/lldpd.c

index e8d2c1fa2fe4723b08f507744f71a1fa1870152f..6e8fdca631b4152fe2eb078d36093dc9ef13c781 100644 (file)
@@ -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++) {
index 4ccf4e005561bc92b01243e7c90538bc4275c0ff..33cb90cad3a4688df84c3c23cd21abe7dbe7782a 100644 (file)
@@ -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]