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: bc6098d441 ('libnm: add internal nmc_client_has_{version_info_v,version_info_capability,capability}() helper')
This commit is contained in:
Íñigo Huguet
2024-12-04 14:24:38 +01:00
committed by Íñigo Huguet
parent 38d1bcee3b
commit 5a65170b49
2 changed files with 6 additions and 9 deletions

View File

@@ -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));

View File

@@ -6316,7 +6316,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
@@ -8313,7 +8313,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