Blame SOURCES/0114-v2v-o-libvirt-Prevent-possible-XPath-injection.patch

ffd6ed
From 3815caab495ce2644eee574bb3564cddf886bebe Mon Sep 17 00:00:00 2001
ffd6ed
From: "Richard W.M. Jones" <rjones@redhat.com>
ffd6ed
Date: Sat, 20 Dec 2014 17:46:53 +0000
ffd6ed
Subject: [PATCH] v2v: -o libvirt: Prevent possible XPath injection.
ffd6ed
ffd6ed
Ensure the arch string is sane before using it in the following XPath
ffd6ed
expression.  Since the arch string can be derived from untrusted guest
ffd6ed
data [see src/filearch.c], this prevents a possible XPath injection
ffd6ed
vulnerability.
ffd6ed
ffd6ed
(cherry picked from commit 6c6ce85f94c36803fe2db35a98db436bff0c14b0)
ffd6ed
---
ffd6ed
 v2v/output_libvirt.ml | 6 ++++++
ffd6ed
 1 file changed, 6 insertions(+)
ffd6ed
ffd6ed
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
ffd6ed
index dc9466c..7f9a3a0 100644
ffd6ed
--- a/v2v/output_libvirt.ml
ffd6ed
+++ b/v2v/output_libvirt.ml
ffd6ed
@@ -30,9 +30,15 @@ module StringSet = Set.Make (String)
ffd6ed
 let string_set_of_list =
ffd6ed
   List.fold_left (fun set x -> StringSet.add x set) StringSet.empty
ffd6ed
 
ffd6ed
+let arch_sanity_re = Str.regexp "^[-_A-Za-z0-9]+$"
ffd6ed
+
ffd6ed
 let target_features_of_capabilities_doc doc arch =
ffd6ed
   let xpathctx = Xml.xpath_new_context doc in
ffd6ed
   let expr =
ffd6ed
+    (* Check the arch is sane.  It comes from untrusted input.  This
ffd6ed
+     * avoids XPath injection below.
ffd6ed
+     *)
ffd6ed
+    assert (Str.string_match arch_sanity_re arch 0);
ffd6ed
     (* NB: Pay attention to the square brackets.  This returns the
ffd6ed
      * <guest> nodes!
ffd6ed
      *)
ffd6ed
-- 
ffd6ed
1.8.3.1
ffd6ed