Skip to content

Commit

Permalink
Added patch to sanitize external solver criteria.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdicosmo authored and AltGr committed Jan 17, 2014
1 parent 6473af8 commit 7cf1e5c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src_ext/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $(DOSE).tar.gz:

dose.stamp: $(DOSE).tar.gz
tar xfz $(DOSE).tar.gz
cd $(DOSE) && patch -p1 < ../dose-pcre2re.diff && patch -p1 < ../dose-mktemp.diff && cd ..
cd $(DOSE) && patch -p1 < ../dose-pcre2re.diff && patch -p1 < ../dose-mktemp.diff && patch -p1 < ../dose-quotecriteria.diff && cd ..
rm -rf dose
mv $(DOSE) dose
@touch $@
Expand Down
33 changes: 33 additions & 0 deletions src_ext/dose-quotecriteria.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/common/cudfSolver.ml b/common/cudfSolver.ml
index 9bfda7e..548ee12 100644
--- a/common/cudfSolver.ml
+++ b/common/cudfSolver.ml
@@ -53,10 +53,14 @@ let rec input_all_lines acc chan =
(** Solver "exec:" line. Contains three named wildcards to be interpolated:
"$in", "$out", and "$pref"; corresponding to, respectively, input CUDF
document, output CUDF universe, user preferences. *)
+
+(* quote string for the shell, after removing all characters disallowed in criteria *)
+let sanitize s = Printf.sprintf "\"%s\"" (Pcre.substitute ~rex:(Pcre.regexp "[^+()a-z,\"-]") ~subst:(fun _ -> "") s);;
+
let interpolate_solver_pat exec cudf_in cudf_out pref =
let _, exec = String.replace ~str:exec ~sub:"$in" ~by:cudf_in in
let _, exec = String.replace ~str:exec ~sub:"$out" ~by:cudf_out in
- let _, exec = String.replace ~str:exec ~sub:"$pref" ~by:pref in
+ let _, exec = String.replace ~str:exec ~sub:"$pref" ~by:(sanitize pref) in
exec
;;

diff --git a/common/cudfSolver.ml b/common/cudfSolver.ml
index 548ee12..2caf76a 100644
--- a/common/cudfSolver.ml
+++ b/common/cudfSolver.ml
@@ -55,7 +55,7 @@ let rec input_all_lines acc chan =
document, output CUDF universe, user preferences. *)

(* quote string for the shell, after removing all characters disallowed in criteria *)
-let sanitize s = Printf.sprintf "\"%s\"" (Pcre.substitute ~rex:(Pcre.regexp "[^+()a-z,\"-]") ~subst:(fun _ -> "") s);;
+let sanitize s = Printf.sprintf "\"%s\"" (Re_pcre.substitute ~rex:(Re_pcre.regexp "[^+()a-z,\"-]") ~subst:(fun _ -> "") s);;

let interpolate_solver_pat exec cudf_in cudf_out pref =
let _, exec = String.replace ~str:exec ~sub:"$in" ~by:cudf_in in

0 comments on commit 7cf1e5c

Please sign in to comment.