From c3b33a2cfd3d91f9dbb9e75cdf0602eedaeab46d Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Tue, 7 Mar 2017 11:59:48 -0600 Subject: [PATCH] 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. --- src/wiphy.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/wiphy.c b/src/wiphy.c index ff644dc8..6a751bda 100644 --- a/src/wiphy.c +++ b/src/wiphy.c @@ -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. 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; }