Blame SOURCES/0001-GVariant-text-fix-scan-of-positional-parameters.patch

807f2a
From cc0b8bdf124c47090d0b794c9b6e2e3852c860d9 Mon Sep 17 00:00:00 2001
807f2a
From: Hanno Boeck <hanno@hboeck.de>
807f2a
Date: Mon, 22 Feb 2016 07:46:17 -0500
807f2a
Subject: [PATCH] GVariant text: fix scan of positional parameters
807f2a
807f2a
The scanning to find the end of a positional parameter designator in
807f2a
GVariant text format (e.g. '%i') is currently broken in case the 'end'
807f2a
pointer is not specified.
807f2a
807f2a
The scan is controlled by a somewhat complicated loop that needs to deal
807f2a
properly with cases like (123, %(ii)) [where '%(ii)' is to be taken
807f2a
together, but the final ')' not].
807f2a
807f2a
This loop missed the case where a format string passed to
807f2a
g_variant_new_parsed() ended immediately after such a conversion, with a
807f2a
nul character.  In this case the 'end' pointer is NULL, so the only way
807f2a
we can find the end is by scanning for nul in the string.
807f2a
807f2a
In case of g_variant_new_parsed() [which is what this code was designed
807f2a
to be used for], the bug is somewhat unlikely in practice: the only way
807f2a
that a valid text-form GVariant could ever contain a positional
807f2a
parameter replacement at the end of the string is if this positional
807f2a
parameter were the only thing being returned.  In that case, the user
807f2a
would likely have opted for a more direct approach.
807f2a
807f2a
Unfortunately, this code is also active in the tokenisation phase of
807f2a
g_variant_parse(), before positional parameters are rejected as invalid
807f2a
for that case.  Anyone who calls this function with a nul-terminated
807f2a
string (and no end pointer) is vulnerable to a crash from malicious user
807f2a
input.  This can be seen, at the very least with many commandline tools:
807f2a
807f2a
  $ dconf write /x '%i'
807f2a
  Segmentation fault
807f2a
807f2a
We fix this problem by searching for the nul character in this case, in
807f2a
addition to comparing the end pointer.
807f2a
807f2a
This problem is almost certainly limited to being able to cause crashes.
807f2a
The loop in question only performs reads and, in the security-sensitive
807f2a
case, the token will be quickly rejected after the loop is finished
807f2a
(since it starts with '%' and the 'app' pointer is unset).  This is
807f2a
further mitigated by the fact that there are no known cases of GVariant
807f2a
text format being used as part of a protocol at a privilege barrier.
807f2a
---
807f2a
 glib/gvariant-parser.c | 2 +-
807f2a
 1 file changed, 1 insertion(+), 1 deletion(-)
807f2a
807f2a
diff --git a/glib/gvariant-parser.c b/glib/gvariant-parser.c
807f2a
index e7dab85..9f4bcc5 100644
807f2a
--- a/glib/gvariant-parser.c
807f2a
+++ b/glib/gvariant-parser.c
807f2a
@@ -237,7 +237,7 @@ token_stream_prepare (TokenStream *stream)
807f2a
        * Also: ] and > are never in format strings.
807f2a
        */
807f2a
       for (end = stream->stream + 1;
807f2a
-           end != stream->end && *end != ',' &&
807f2a
+           end != stream->end && *end != '\0' && *end != ',' &&
807f2a
            *end != ':' && *end != '>' && *end != ']' && !g_ascii_isspace (*end);
807f2a
            end++)
807f2a
 
807f2a
-- 
807f2a
1.8.3.1
807f2a