From 78243478dcec865486b387cf361783dc137015b5 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 14 Jul 2020 07:16:47 +0200 Subject: [PATCH] lib: remove limit on system description length The limit was introduced in 9c49cedf8e75 while fixing a memory leak. The state data is used to ensure we don't interleave operations. We need to handle the case where the value is truncated because it is larger than the allocated size. Fix #408. --- src/lib/atom.c | 4 ++-- tests/integration/test_lldpcli.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/atom.c b/src/lib/atom.c index 39ea5f87..55a1b679 100644 --- a/src/lib/atom.c +++ b/src/lib/atom.c @@ -331,7 +331,7 @@ _lldpctl_do_something(lldpctl_conn_t *conn, conn->state_data[0] = 0; } if (conn->state == state_send && - (state_data == NULL || !strncmp(conn->state_data, state_data, sizeof(conn->state_data)))) { + (state_data == NULL || !strncmp(conn->state_data, state_data, sizeof(conn->state_data) - 1))) { /* We need to send the currently built message */ rc = lldpctl_send(conn); if (rc < 0) @@ -339,7 +339,7 @@ _lldpctl_do_something(lldpctl_conn_t *conn, conn->state = state_recv; } if (conn->state == state_recv && - (state_data == NULL || !strncmp(conn->state_data, state_data, sizeof(conn->state_data)))) { + (state_data == NULL || !strncmp(conn->state_data, state_data, sizeof(conn->state_data) - 1))) { /* We need to receive the answer */ while ((rc = ctl_msg_recv_unserialized(&conn->input_buffer, &conn->input_buffer_len, diff --git a/tests/integration/test_lldpcli.py b/tests/integration/test_lldpcli.py index 273777a3..6a9ee801 100644 --- a/tests/integration/test_lldpcli.py +++ b/tests/integration/test_lldpcli.py @@ -588,6 +588,12 @@ def test_return_code(lldpd1, lldpcli, namespaces): ("configure system interface promiscuous", "iface-promisc", "yes"), ("configure system bond-slave-src-mac-type fixed", "bond-slave-src-mac-type", "fixed"), + ("configure system description " + "1234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890", + "description", + "1234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890"), ("configure lldp agent-type nearest-customer-bridge", "lldp-agent-type", "nearest customer bridge")]) def test_config_change(lldpd1, lldpcli, namespaces, command, name, expected): -- 2.39.5