monitor-config-store: Properly escape monitor spec

Makes sure that monitor specs which may be read from EDID data do not
contain characters that are invalid in XML. Makes it possible to restore
monitor configs of monitor models with characters such as '&' in them.

To make this change not break any tests, the sample monitor configs need
to be adjusted as well. Apostrophes don't strictly have to be escaped in
XML text elements. However, we now do escape the elements in
`<monitorspec>` specifically.

Closes: <https://gitlab.gnome.org/GNOME/mutter/-/issues/1011>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1685>
This commit is contained in:
Thomas Mühlbacher 2021-01-27 19:59:26 +01:00 committed by Marge Bot
parent c9aa43aa7a
commit 70cdd72040
28 changed files with 59 additions and 44 deletions

View File

@ -1138,19 +1138,34 @@ append_monitor_spec (GString *buffer,
MetaMonitorSpec *monitor_spec, MetaMonitorSpec *monitor_spec,
const char *indentation) const char *indentation)
{ {
char *escaped;
g_string_append_printf (buffer, "%s<monitorspec>\n", indentation); g_string_append_printf (buffer, "%s<monitorspec>\n", indentation);
escaped = g_markup_escape_text (monitor_spec->connector, -1);
g_string_append_printf (buffer, "%s <connector>%s</connector>\n", g_string_append_printf (buffer, "%s <connector>%s</connector>\n",
indentation, indentation,
monitor_spec->connector); escaped);
g_free (escaped);
escaped = g_markup_escape_text (monitor_spec->vendor, -1);
g_string_append_printf (buffer, "%s <vendor>%s</vendor>\n", g_string_append_printf (buffer, "%s <vendor>%s</vendor>\n",
indentation, indentation,
monitor_spec->vendor); escaped);
g_free (escaped);
escaped = g_markup_escape_text (monitor_spec->product, -1);
g_string_append_printf (buffer, "%s <product>%s</product>\n", g_string_append_printf (buffer, "%s <product>%s</product>\n",
indentation, indentation,
monitor_spec->product); escaped);
g_free (escaped);
escaped = g_markup_escape_text (monitor_spec->serial, -1);
g_string_append_printf (buffer, "%s <serial>%s</serial>\n", g_string_append_printf (buffer, "%s <serial>%s</serial>\n",
indentation, indentation,
monitor_spec->serial); escaped);
g_free (escaped);
g_string_append_printf (buffer, "%s</monitorspec>\n", indentation); g_string_append_printf (buffer, "%s</monitorspec>\n", indentation);
} }

View File

@ -8,7 +8,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>
@ -22,7 +22,7 @@
<disabled> <disabled>
<monitorspec> <monitorspec>
<connector>DP-2</connector> <connector>DP-2</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x654321</serial> <serial>0x654321</serial>
</monitorspec> </monitorspec>

View File

@ -8,7 +8,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>
@ -22,7 +22,7 @@
<disabled> <disabled>
<monitorspec> <monitorspec>
<connector>DP-2</connector> <connector>DP-2</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x654321</serial> <serial>0x654321</serial>
</monitorspec> </monitorspec>

View File

@ -2,7 +2,7 @@
<configuration> <configuration>
<clone>no</clone> <clone>no</clone>
<output name="DP-1"> <output name="DP-1">
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
<width>800</width> <width>800</width>
@ -18,7 +18,7 @@
<underscanning>no</underscanning> <underscanning>no</underscanning>
</output> </output>
<output name="DP-2"> <output name="DP-2">
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x654321</serial> <serial>0x654321</serial>
</output> </output>

View File

@ -12,7 +12,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -12,7 +12,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -2,7 +2,7 @@
<configuration> <configuration>
<clone>no</clone> <clone>no</clone>
<output name="DP-1"> <output name="DP-1">
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
<width>600</width> <width>600</width>

View File

@ -12,7 +12,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -12,7 +12,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -2,7 +2,7 @@
<configuration> <configuration>
<clone>no</clone> <clone>no</clone>
<output name="DP-1"> <output name="DP-1">
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
<width>600</width> <width>600</width>

View File

@ -11,7 +11,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>
@ -32,7 +32,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-2</connector> <connector>DP-2</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -8,7 +8,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -8,7 +8,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -7,7 +7,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -8,7 +8,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>eDP-1</connector> <connector>eDP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -7,7 +7,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>eDP-1</connector> <connector>eDP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>
@ -28,7 +28,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>
@ -52,7 +52,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>
@ -76,7 +76,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>eDP-1</connector> <connector>eDP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -7,7 +7,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>
@ -20,7 +20,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-2</connector> <connector>DP-2</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -7,7 +7,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-2</connector> <connector>DP-2</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -8,7 +8,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>
@ -22,7 +22,7 @@
<disabled> <disabled>
<monitorspec> <monitorspec>
<connector>DP-2</connector> <connector>DP-2</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x654321</serial> <serial>0x654321</serial>
</monitorspec> </monitorspec>

View File

@ -7,7 +7,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>
@ -25,7 +25,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-2</connector> <connector>DP-2</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -8,7 +8,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -7,7 +7,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>
@ -28,7 +28,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-2</connector> <connector>DP-2</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -7,7 +7,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>
@ -28,7 +28,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-2</connector> <connector>DP-2</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -7,7 +7,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -8,7 +8,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -8,7 +8,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -7,7 +7,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>

View File

@ -7,7 +7,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-1</connector> <connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>
@ -24,7 +24,7 @@
<monitor> <monitor>
<monitorspec> <monitorspec>
<connector>DP-2</connector> <connector>DP-2</connector>
<vendor>MetaProduct's Inc.</vendor> <vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product> <product>MetaMonitor</product>
<serial>0x123456</serial> <serial>0x123456</serial>
</monitorspec> </monitorspec>