]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpd: convert 'oui_info' member to dynamic array 109/head
authorAlexandru Ardelean <ardeleanalex@gmail.com>
Mon, 18 May 2015 07:01:56 +0000 (10:01 +0300)
committerAlexandru Ardelean <ardeleanalex@gmail.com>
Tue, 19 May 2015 06:55:11 +0000 (09:55 +0300)
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
src/daemon/client.c
src/daemon/protocols/lldp.c
src/lib/atoms/custom.c
src/lldpd-structs.c
src/lldpd-structs.h

index bc7c317c40b92f2c1d9c567887d93e3e63826185..7a328b7fa65a4cba0fb720004e44834b29ecc336 100644 (file)
@@ -379,7 +379,13 @@ client_handle_set_port(struct lldpd *cfg, enum hmsg_type *type,
                            log_debug("rpc", "requested custom TLV add");
                            if ((custom = malloc(sizeof(struct lldpd_custom)))) {
                                    memcpy(custom, set->custom, sizeof(struct lldpd_custom));
-                                   TAILQ_INSERT_TAIL(&port->p_custom_list, custom, next);
+                                   if ((custom->oui_info = malloc(custom->oui_info_len))) {
+                                           memcpy(custom->oui_info, set->custom->oui_info, custom->oui_info_len);
+                                           TAILQ_INSERT_TAIL(&port->p_custom_list, custom, next);
+                                   } else {
+                                           free(custom);
+                                           log_warn("rpc", "could not allocate memory for custom TLV info");
+                                   }
                            } else
                                    log_warn("rpc", "could not allocate memory for custom TLV");
                    }
@@ -409,7 +415,10 @@ set_port_finished:
        free(set->dot3_power);
 #endif
 #ifdef ENABLE_CUSTOM
-       free(set->custom);
+       if (set->custom) {
+               free(set->custom->oui_info);
+               free(set->custom);
+       }
 #endif
        return 0;
 }
index 7ff08fc0eea5a2858f5edea46e03d7be69df0fe7..5df6c42c34424e0a63de82274588a96824b2aa43 100644 (file)
@@ -1106,8 +1106,12 @@ lldp_decode(struct lldpd *cfg, char *frame, int s,
                                custom->oui_info_len = tlv_size > 4 ? tlv_size - 4 : 0;
                                memcpy(custom->oui, orgid, sizeof(custom->oui));
                                custom->subtype = tlv_subtype;
-                               if (custom->oui_info_len > 0)
+                               if (custom->oui_info_len > 0) {
+                                       custom->oui_info = malloc(custom->oui_info_len);
+                                       if (!custom->oui_info)
+                                               return ENOMEM;
                                        PEEK_BYTES(custom->oui_info, custom->oui_info_len);
+                               }
                                TAILQ_INSERT_TAIL(&port->p_custom_list, custom, next);
 #endif
                        }
index 0b22fa2117ff1c4b88f91836fed4a235c18b6e1f..9d6cdb7e0051b83cc00014f4e2910f235c27d4e6 100644 (file)
@@ -133,7 +133,7 @@ _lldpctl_atom_get_buffer_custom(lldpctl_atom_t *atom, lldpctl_key_t key, size_t
                return (const uint8_t *)&custom->tlv->oui;
        case lldpctl_k_custom_tlv_oui_info_string:
                *n = custom->tlv->oui_info_len;
-               return (const uint8_t *)&custom->tlv->oui_info;
+               return (const uint8_t *)custom->tlv->oui_info;
        default:
                SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
                return NULL;
@@ -157,7 +157,12 @@ _lldpctl_atom_set_buffer_custom(lldpctl_atom_t *atom, lldpctl_key_t key,
                        return NULL;
                }
                custom->tlv->oui_info_len = n;
-               memcpy(&custom->tlv->oui_info, buf, n);
+               if (!(custom->tlv->oui_info = _lldpctl_alloc_in_atom(atom, n))) {
+                       custom->tlv->oui_info_len = 0;
+                       SET_ERROR(atom->conn, LLDPCTL_ERR_NOMEM);
+                       return NULL;
+               }
+               memcpy(custom->tlv->oui_info, buf, n);
                return atom;
        default:
                SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
index f983b7c2ed221f7cb45bf531b1eba9531cd4ccb1..6e85f9a70d81a5598c73247e7db32211142dfccf 100644 (file)
@@ -112,6 +112,7 @@ lldpd_custom_list_cleanup(struct lldpd_port *port)
            custom != NULL;
            custom = custom_next) {
                custom_next = TAILQ_NEXT(custom, next);
+               free(custom->oui_info);
                free(custom);
        }
        TAILQ_INIT(&port->p_custom_list);
index a892fd6a979372762e8c024f2969dc67911db6a3..a96801ab32c6778d1e533ef4b90a4c886c7d21ea 100644 (file)
@@ -224,12 +224,13 @@ struct lldpd_custom {
        /* Organizationally Defined Subtype */
        u_int8_t                subtype;
        /* Organizationally Defined Information String; for now/simplicity static array */
-       u_int8_t                oui_info[LLDP_TLV_ORG_OUI_INFO_MAXLEN];
+       u_int8_t                *oui_info;
        /* Organizationally Defined Information String length */
        int                     oui_info_len;
 };
 MARSHAL_BEGIN(lldpd_custom)
 MARSHAL_TQE(lldpd_custom, next)
+MARSHAL_FSTR(lldpd_custom, oui_info, oui_info_len)
 MARSHAL_END(lldpd_custom);
 #endif