X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flibsystemd-network%2Ftest-lldp.c;h=f81284e2a7572cd2c78e47d3d7dbdb55a5f72539;hp=e9d5d7bb60e0c72db6fd96cfe79dd39dc46c73eb;hb=804138a08c1fd6a4a3c19ead91eeb8ef312c36a0;hpb=ad1ad5c8e36ea795034fcdac660b15d7c141d55b diff --git a/src/libsystemd-network/test-lldp.c b/src/libsystemd-network/test-lldp.c index e9d5d7bb6..f81284e2a 100644 --- a/src/libsystemd-network/test-lldp.c +++ b/src/libsystemd-network/test-lldp.c @@ -45,13 +45,13 @@ static struct ether_addr mac_addr = { static int lldp_build_tlv_packet(tlv_packet **ret) { _cleanup_tlv_packet_free_ tlv_packet *m = NULL; const uint8_t lldp_dst[] = LLDP_MULTICAST_ADDR; - struct ether_header ether; + struct ether_header ether = { + .ether_type = htons(ETHERTYPE_LLDP), + }; /* Append ethernet header */ - memset(ðer, 0, sizeof(ether)); memcpy(ðer.ether_dhost, lldp_dst, ETHER_ADDR_LEN); memcpy(ðer.ether_shost, &mac_addr, ETHER_ADDR_LEN); - ether.ether_type = htons(ETHERTYPE_LLDP); assert_se(tlv_packet_new(&m) >= 0); @@ -143,8 +143,8 @@ static int lldp_parse_port_id_tlv(tlv_packet *m) { case LLDP_PORT_SUBTYPE_INTERFACE_NAME: assert_se(tlv_packet_read_string(m, &str, &length) >= 0); - p = malloc0(length + 1); - strncpy(p, str, length-1); + p = strndup(str, length-1); + assert_se(p); assert_se(streq(p, TEST_LLDP_PORT) == 1); break; @@ -164,8 +164,8 @@ static int lldp_parse_system_name_tlv(tlv_packet *m) { assert_se(lldp_tlv_packet_enter_container(m, LLDP_TYPE_SYSTEM_NAME) >= 0); assert_se(tlv_packet_read_string(m, &str, &length) >= 0); - p = malloc0(length + 1); - strncpy(p, str, length); + p = strndup(str, length); + assert_se(p); assert_se(streq(p, TEST_LLDP_TYPE_SYSTEM_NAME) == 1); @@ -181,8 +181,8 @@ static int lldp_parse_system_desc_tlv(tlv_packet *m) { assert_se(lldp_tlv_packet_enter_container(m, LLDP_TYPE_SYSTEM_DESCRIPTION) >= 0); assert_se(tlv_packet_read_string(m, &str, &length) >= 0); - p = malloc0(length + 1); - strncpy(p, str, length); + p = strndup(str, length); + assert_se(p); assert_se(streq(p, TEST_LLDP_TYPE_SYSTEM_DESC) == 1);