From c7bb23d49c89908b8270aa581b6aba3393e3eb27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Huguet?= Date: Wed, 4 Dec 2024 14:24:38 +0100 Subject: [PATCH] libnmc: fix bug checking VersionInfo's capabilities Remove the `+ 31u` that was making that it would search for bit 1 at array's element 1, instead of element 0. Fixed comparison >len that shoudl be >=len. Fix a few typos. Fixes: bc6098d44106 ('libnm: add internal nmc_client_has_{version_info_v,version_info_capability,capability}() helper') (cherry picked from commit 5a65170b49d38f5195da900f63710c847ce3364e) (cherry picked from commit a53349fa9c8e529462b606fa3deb7dcac92952d3) (cherry picked from commit e6a29232bc93ae3e6f3f71a21c5d172c289d9331) (cherry picked from commit bb018b72f08419912953cbd4810b8323d11c63e5) --- src/libnm-client-aux-extern/nm-libnm-aux.c | 11 ++++------- src/libnm-client-impl/nm-client.c | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/libnm-client-aux-extern/nm-libnm-aux.c b/src/libnm-client-aux-extern/nm-libnm-aux.c index 5855bc299b..77f4a19559 100644 --- a/src/libnm-client-aux-extern/nm-libnm-aux.c +++ b/src/libnm-client-aux-extern/nm-libnm-aux.c @@ -169,14 +169,11 @@ nmc_client_has_version_info_capability(NMClient *nmc, NMVersionInfoCapability ca len--; ver++; - idx = (gsize) capability; - if (idx >= G_MAXSIZE - 31u) - return FALSE; + idx = (gsize) capability; + idx_hi = idx / 32u; + idx_lo = idx % 32u; - idx_hi = ((idx + 31u) / 32u); - idx_lo = (idx % 32u); - - if (idx_hi > len) + if (idx_hi >= len) return FALSE; return NM_FLAGS_ANY(ver[idx_hi], (1ull << idx_lo)); diff --git a/src/libnm-client-impl/nm-client.c b/src/libnm-client-impl/nm-client.c index f3ab6d69e0..74eedf563e 100644 --- a/src/libnm-client-impl/nm-client.c +++ b/src/libnm-client-impl/nm-client.c @@ -6314,7 +6314,7 @@ nm_client_get_capabilities(NMClient *client, gsize *length) * * If available, the first element in the array is NM_VERSION which * encodes the daemon version as "(major << 16 | minor << 8 | micro)". - * The following elements are a bitfield of %NMVersionInfoCapabilities + * The following elements are a bitfield of %NMVersionInfoCapability * that indicate that the daemon supports a certain capability. * * Returns: (transfer none) (array length=length): the @@ -8311,7 +8311,7 @@ nm_client_class_init(NMClientClass *client_class) * Expose version info and capabilities of NetworkManager. If non-empty, * the first element is NM_VERSION, which encodes the version of the * daemon as "(major << 16 | minor << 8 | micro)". The following elements - * is a bitfields of %NMVersionInfoCapabilities. If a bit is set, then + * is a bitfields of %NMVersionInfoCapability. If a bit is set, then * the running NetworkManager has the respective capability. * * Since: 1.42