From 1d0e526b03d24847dcd3396cb5962efd19faa7d1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 26 Aug 2021 17:12:41 +0200 Subject: [PATCH] core: use larger buffer for string in commit_port_options() Use sizeof(queue_id_str), so we don't rely on _MAX_QUEUE_ID_STR_LEN being the correct size for the string. Also, let's create an excessively large buffer. True, the previous size should have always be enough, so in practice there is no difference. But what if it were not? Should we try to handle an error? How? Just asserting or report a failure? But we don't because the error cannot happen, can't it? Don't answer any of these questions, but by making the string buffer larger, it's even less likely that these questions become relevant. If for some reason nm_device_get_iface() gives a long string, then we don't care and let kernel reject the invalid interface name. --- src/core/devices/nm-device-bond.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/core/devices/nm-device-bond.c b/src/core/devices/nm-device-bond.c index 28b6d300ff..a2414a1bde 100644 --- a/src/core/devices/nm-device-bond.c +++ b/src/core/devices/nm-device-bond.c @@ -407,16 +407,10 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) return ret; } -/* - * The queue id format is '$interface_name:$queue_id' - * The max queue 65535 hold 5 chars. - */ -#define _MAX_QUEUE_ID_STR_LEN 5 + IFNAMSIZ + 1 + 1 - static void commit_port_options(NMDevice *bond_device, NMDevice *port, NMSettingBondPort *set_port) { - char queue_id_str[_MAX_QUEUE_ID_STR_LEN]; + char queue_id_str[IFNAMSIZ + NM_STRLEN(":") + 5 + 100]; /* * The queue-id of bond port is read only, we should modify bond interface using: @@ -424,7 +418,7 @@ commit_port_options(NMDevice *bond_device, NMDevice *port, NMSettingBondPort *se * Kernel allows parital editing, so no need to care about other bond ports. */ g_snprintf(queue_id_str, - _MAX_QUEUE_ID_STR_LEN, + sizeof(queue_id_str), "%s:%" G_GUINT32_FORMAT, nm_device_get_iface(port), set_port ? nm_setting_bond_port_get_queue_id(set_port) : NM_BOND_PORT_QUEUE_ID_DEF);