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");
}
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;
}
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
}
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;
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);
custom != NULL;
custom = custom_next) {
custom_next = TAILQ_NEXT(custom, next);
+ free(custom->oui_info);
free(custom);
}
TAILQ_INIT(&port->p_custom_list);
/* 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