[systemd-commits] 3 commits - src/libsystemd-network
Lennart Poettering
lennart at kemper.freedesktop.org
Tue Feb 10 12:17:41 PST 2015
src/libsystemd-network/test-lldp.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
New commits:
commit 332560792c6ef0b5c3d9719801b64d0d5f374639
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Feb 10 21:17:26 2015 +0100
test-lldp: fix minor OOM
diff --git a/src/libsystemd-network/test-lldp.c b/src/libsystemd-network/test-lldp.c
index f81284e..ee74ebd 100644
--- a/src/libsystemd-network/test-lldp.c
+++ b/src/libsystemd-network/test-lldp.c
@@ -131,7 +131,8 @@ static int lldp_parse_chassis_tlv(tlv_packet *m, uint8_t *type) {
}
static int lldp_parse_port_id_tlv(tlv_packet *m) {
- char *str = NULL, *p;
+ _cleanup_free_ char *p = NULL;
+ char *str = NULL;
uint16_t length;
uint8_t subtype;
@@ -158,7 +159,8 @@ static int lldp_parse_port_id_tlv(tlv_packet *m) {
}
static int lldp_parse_system_name_tlv(tlv_packet *m) {
- char *str = NULL, *p;
+ _cleanup_free_ char *p = NULL;
+ char *str = NULL;
uint16_t length;
assert_se(lldp_tlv_packet_enter_container(m, LLDP_TYPE_SYSTEM_NAME) >= 0);
@@ -175,7 +177,8 @@ static int lldp_parse_system_name_tlv(tlv_packet *m) {
}
static int lldp_parse_system_desc_tlv(tlv_packet *m) {
- char *str = NULL, *p;
+ _cleanup_free_ char *p = NULL;
+ char *str = NULL;
uint16_t length;
assert_se(lldp_tlv_packet_enter_container(m, LLDP_TYPE_SYSTEM_DESCRIPTION) >= 0);
commit 804138a08c1fd6a4a3c19ead91eeb8ef312c36a0
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Feb 10 21:15:47 2015 +0100
test-lldp: initialize structs when we define them
diff --git a/src/libsystemd-network/test-lldp.c b/src/libsystemd-network/test-lldp.c
index 946f358..f81284e 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);
commit b762fbd128480426d225596b18604a45042339c5
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Feb 10 21:15:21 2015 +0100
test-lldp: use strndup() where possible
diff --git a/src/libsystemd-network/test-lldp.c b/src/libsystemd-network/test-lldp.c
index 2e6bf14..946f358 100644
--- a/src/libsystemd-network/test-lldp.c
+++ b/src/libsystemd-network/test-lldp.c
@@ -143,9 +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);
+ p = strndup(str, length-1);
assert_se(p);
- strncpy(p, str, length-1);
assert_se(streq(p, TEST_LLDP_PORT) == 1);
break;
@@ -165,9 +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);
+ p = strndup(str, length);
assert_se(p);
- strncpy(p, str, length);
assert_se(streq(p, TEST_LLDP_TYPE_SYSTEM_NAME) == 1);
@@ -183,9 +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);
+ p = strndup(str, length);
assert_se(p);
- strncpy(p, str, length);
assert_se(streq(p, TEST_LLDP_TYPE_SYSTEM_DESC) == 1);
More information about the systemd-commits
mailing list