3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-18 10:19:24 +01:00

wiphy: Make sure Name attribute is valid utf8

DBus strings must be valid utf8.  The kernel only enforces that the
wiphy name is null terminated string.  It does not validate or otherwise
check the contents in any way.  Thus it is possible to have
non-printable or non-utf8 characters inside.
This commit is contained in:
Denis Kenzior 2017-03-07 11:59:48 -06:00
parent 4703dd5200
commit c3b33a2cfd

View File

@ -720,8 +720,21 @@ static bool wiphy_property_get_name(struct l_dbus *dbus,
void *user_data)
{
struct wiphy *wiphy = user_data;
char buf[20];
l_dbus_message_builder_append_basic(builder, 's', wiphy->name);
if (l_utf8_validate(wiphy->name, strlen(wiphy->name), NULL)) {
l_dbus_message_builder_append_basic(builder, 's', wiphy->name);
return true;
}
/*
* In the highly unlikely scenario that the wiphy name is not utf8,
* we simply use the canonical name phy<index>. The kernel guarantees
* that this name cannot be taken by any other wiphy, so this should
* be safe enough.
*/
sprintf(buf, "phy%d", wiphy->id);
l_dbus_message_builder_append_basic(builder, 's', buf);
return true;
}