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.
This commit is contained in:
Thomas Haller 2022-01-28 21:20:05 +01:00
parent d501e96857
commit 64630f57a2
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

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