summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-05-16 14:11:07 +0200
committerThomas Haller <thaller@redhat.com>2017-05-17 10:56:45 +0200
commit95793ec8b647f23571c162221f29b86522909c5d (patch)
tree8e68fa2e295222413d5ec0a524890df836003238
parent1d3a56825e6b9c0bb0ee9629e3380b87f483c5a2 (diff)
downloadNetworkManager-th/sanitize-non-utf8.tar.gz
device: sanitze UTF-8 values for D-Busth/sanitize-non-utf8
ip link add name $'d\xccf\\c' type dummy Use nm_utils_str_utf8safe_escape() to sanitize non UTF-8 sequences before exposing them on D-Bus. The operation can be reverted client side via nm_utils_str_utf8safe_unescape() or g_strcompress(). Note that this preserves all valid UTF-8 sequences as is, with exception of the backslash escape character. Thus, this is a change in behavior if the values contained any backslash characters. Obviously, this changes behavior: - if the string contained invalid UTF-8 sequences, the bug is fixed by escaping them. Beware, that for the device's "Interface" property, the resulting name may well be longer then IFNAMSIZ. - for values that contain a '\\'. Such strings are changed to contain double backslash. Note that nmcli is not changed to somehow unescape the string before printing. As the string is not valid UTF-8 (or contains escaping characters), it is not printable data, and we don't want to output the text as binary.
-rw-r--r--introspection/org.freedesktop.NetworkManager.Device.xml12
-rw-r--r--src/devices/nm-device.c24
2 files changed, 29 insertions, 7 deletions
diff --git a/introspection/org.freedesktop.NetworkManager.Device.xml b/introspection/org.freedesktop.NetworkManager.Device.xml
index ee424101e6..9a13d8f9f6 100644
--- a/introspection/org.freedesktop.NetworkManager.Device.xml
+++ b/introspection/org.freedesktop.NetworkManager.Device.xml
@@ -28,6 +28,9 @@
Interface:
The name of the device's control (and often data) interface.
+ Note that non UTF-8 characters are backslash escaped, so the
+ resulting name may be longer then 15 characters. Use g_strcompress()
+ to revert the escaping.
-->
<property name="Interface" type="s" access="read"/>
@@ -38,6 +41,9 @@
not refer to the actual data interface until the device has successfully
established a data connection, indicated by the device's State becoming
ACTIVATED.
+ Note that non UTF-8 characters are backslash escaped, so the
+ resulting name may be longer then 15 characters. Use g_strcompress()
+ to revert the escaping.
-->
<property name="IpInterface" type="s" access="read"/>
@@ -45,6 +51,8 @@
Driver:
The driver handling the device.
+ Non-UTF-8 sequences are backslash escaped. Use g_strcompress()
+ to revert.
-->
<property name="Driver" type="s" access="read"/>
@@ -52,6 +60,8 @@
DriverVersion:
The version of the driver handling the device.
+ Non-UTF-8 sequences are backslash escaped. Use g_strcompress()
+ to revert.
-->
<property name="DriverVersion" type="s" access="read"/>
@@ -59,6 +69,8 @@
FirmwareVersion:
The firmware version for the device.
+ Non-UTF-8 sequences are backslash escaped. Use g_strcompress()
+ to revert.
-->
<property name="FirmwareVersion" type="s" access="read"/>
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 39106de9a0..10de535548 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -13944,25 +13944,35 @@ get_property (GObject *object, guint prop_id,
g_value_set_string (value, priv->udi);
break;
case PROP_IFACE:
- g_value_set_string (value, priv->iface);
+ g_value_take_string (value,
+ nm_utils_str_utf8safe_escape (priv->iface,
+ NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL));
break;
case PROP_IP_IFACE:
- if (ip_config_valid (priv->state))
- g_value_set_string (value, nm_device_get_ip_iface (self));
- else
+ if (ip_config_valid (priv->state)) {
+ g_value_take_string (value,
+ nm_utils_str_utf8safe_escape (nm_device_get_ip_iface (self),
+ NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL));
+ } else
g_value_set_string (value, NULL);
break;
case PROP_IFINDEX:
g_value_set_int (value, priv->ifindex);
break;
case PROP_DRIVER:
- g_value_set_string (value, priv->driver);
+ g_value_take_string (value,
+ nm_utils_str_utf8safe_escape (priv->driver,
+ NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL));
break;
case PROP_DRIVER_VERSION:
- g_value_set_string (value, priv->driver_version);
+ g_value_take_string (value,
+ nm_utils_str_utf8safe_escape (priv->driver_version,
+ NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL));
break;
case PROP_FIRMWARE_VERSION:
- g_value_set_string (value, priv->firmware_version);
+ g_value_take_string (value,
+ nm_utils_str_utf8safe_escape (priv->firmware_version,
+ NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL));
break;
case PROP_CAPABILITIES:
g_value_set_uint (value, (priv->capabilities & ~NM_DEVICE_CAP_INTERNAL_MASK));