From 64630f57a2f5cf48e1010d2976065dcd46427609 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 28 Jan 2022 21:20:05 +0100 Subject: [PATCH] device/wwan: ensure capabilities are suitable 32 bit flags The properties NM_DEVICE_MODEM_CAPABILITIES and NM_DEVICE_MODEM_CURRENT_CAPABILITIES are uint, with a range from zero to G_MAXUINT32. nm_modem_get_capabilities() passes the "untrusted" flags from ModemManager. Ensure that they fit into 32 bit, and don't cause an assertion failure due to the range check. Yes, in practice, on all platforms where we build (known to me), guint is always the same as guint32. So this has little effect. Also, cast to guint. Previously, this was just a C enum NMDeviceModemCapabilities, which theoretically has implementation defined sizes. Yes, in practice, they too are of size guint, and this was not an actual bug. But be specific about converting between different integer types. --- src/core/devices/wwan/nm-device-modem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/devices/wwan/nm-device-modem.c b/src/core/devices/wwan/nm-device-modem.c index 4a0d9e4435..ef802a44f2 100644 --- a/src/core/devices/wwan/nm-device-modem.c +++ b/src/core/devices/wwan/nm-device-modem.c @@ -762,9 +762,9 @@ nm_device_modem_new(NMModem *modem) NM_DEVICE_MODEM_MODEM, modem, NM_DEVICE_MODEM_CAPABILITIES, - caps, + (guint) ((guint32) caps), NM_DEVICE_MODEM_CURRENT_CAPABILITIES, - current_caps, + (guint) ((guint32) current_caps), NM_DEVICE_MODEM_DEVICE_ID, nm_modem_get_device_id(modem), NULL);