[augeas-devel] [PATCH 4/6] Fix escape sequences in bracket expressions

Michael Chapman mike at very.puzzling.org
Sat Oct 8 11:08:04 UTC 2011


With POSIX extended regexps, escape sequences are not recognised within
bracket expressions. Any escape sequences passed through by the
unescape() function would be misinterpreted. For instance, the regular
expression:

  /[\.-]/

matches any of the three characters backslash, dot or hyphen, when the
lens author most likely wanted dot or hyphen only.

This patch cleans up the bracket expressions in all lenses, with the
exception of \/ and \\ sequences. These needs to be handled by
unescape() directly.

Signed-off-by: Michael Chapman <mike at very.puzzling.org>
---
 lenses/aliases.aug        |    2 +-
 lenses/cgrules.aug        |    2 +-
 lenses/darkice.aug        |    2 +-
 lenses/debctrl.aug        |    6 +++---
 lenses/dhclient.aug       |    2 +-
 lenses/dhcpd.aug          |    2 +-
 lenses/dnsmasq.aug        |    2 +-
 lenses/exports.aug        |    2 +-
 lenses/fai_diskconfig.aug |    4 ++--
 lenses/gdm.aug            |    2 +-
 lenses/grub.aug           |    2 +-
 lenses/httpd.aug          |    4 ++--
 lenses/inetd.aug          |    6 +++---
 lenses/inifile.aug        |    2 +-
 lenses/iptables.aug       |    2 +-
 lenses/keepalived.aug     |    2 +-
 lenses/openvpn.aug        |    2 +-
 lenses/pg_hba.aug         |    2 +-
 lenses/phpvars.aug        |    2 +-
 lenses/properties.aug     |    2 +-
 lenses/rx.aug             |    2 +-
 lenses/solaris_system.aug |    2 +-
 lenses/spacevars.aug      |    2 +-
 lenses/sudoers.aug        |   16 ++++++++--------
 lenses/sysconfig.aug      |    2 +-
 lenses/xml.aug            |    4 ++--
 26 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/lenses/aliases.aug b/lenses/aliases.aug
index d5a3fef..99712da 100644
--- a/lenses/aliases.aug
+++ b/lenses/aliases.aug
@@ -9,7 +9,7 @@ module Aliases =
    (* Group: basic tokens *)
 
    (* Variable: word *)
-   let word = /[^\|", \t\n]+/
+   let word = /[^|", \t\n]+/
    (* Variable: name *)
    let name = /([^ \t\n#:|@]+|"[^"|\n]*")/ (* " make emacs calm down *)
 
diff --git a/lenses/cgrules.aug b/lenses/cgrules.aug
index e763bed..6917d1f 100644
--- a/lenses/cgrules.aug
+++ b/lenses/cgrules.aug
@@ -39,7 +39,7 @@ module Cgrules =
 
 (* Group: Generic primitive definitions *)
 (* Variable: name *)
-   let name       = /[^@%\# \t\n][^ \t\n]*/
+   let name       = /[^@%# \t\n][^ \t\n]*/
 (* Variable: ctrl_key *)
    let ctrl_key   = /[^ \t\n\/]+/
 (* Variable: ctrl_value *)
diff --git a/lenses/darkice.aug b/lenses/darkice.aug
index d267599..6a3a876 100644
--- a/lenses/darkice.aug
+++ b/lenses/darkice.aug
@@ -16,7 +16,7 @@ let comment  = IniFile.comment IniFile.comment_re IniFile.comment_default
 
 let sep      = IniFile.sep IniFile.sep_re IniFile.sep_default
 
-let entry_re = ( /[A-Za-z0-9][A-Za-z0-9\._-]*/ )
+let entry_re = ( /[A-Za-z0-9][A-Za-z0-9._-]*/ )
 let entry = IniFile.entry entry_re sep comment
 
 let title   = IniFile.title_label "target" IniFile.record_label_re
diff --git a/lenses/debctrl.aug b/lenses/debctrl.aug
index f073059..cdb7adc 100644
--- a/lenses/debctrl.aug
+++ b/lenses/debctrl.aug
@@ -62,18 +62,18 @@ let multi_line_array_entry (k:regexp) (v:lens) =
 let version_depends =
     [ label "version"
      . [   del / *\( */ " ( " . label "relation" . store /[<>=]+/ ]
-     . [   del_ws_spc . label "number" . store /[a-zA-Z0-9_\.\-]+/
+     . [   del_ws_spc . label "number" . store /[a-zA-Z0-9_.-]+/
          . del / *\)/ " )" ]
     ]
 
 let arch_depends =
     [ label "arch"
     . [  del / *\[ */ " [ " . label "prefix" . store /!?/ ]
-    . [ label "name" . store /[a-zA-Z0-9_\.\-]+/ . del / *\]/ " ]" ] ]
+    . [ label "name" . store /[a-zA-Z0-9_.-]+/ . del / *\]/ " ]" ] ]
 
 
 let package_depends
-  =  [ key ( /[a-zA-Z0-9_\-]+/ | /\$\{[a-zA-Z0-9:]+\}/ )
+  =  [ key ( /[a-zA-Z0-9_-]+/ | /\$\{[a-zA-Z0-9:]+\}/ )
         . ( version_depends | arch_depends ) * ]
 
 
diff --git a/lenses/dhclient.aug b/lenses/dhclient.aug
index bccacf2..d7c87e4 100644
--- a/lenses/dhclient.aug
+++ b/lenses/dhclient.aug
@@ -42,7 +42,7 @@ let word              = /[A-Za-z0-9_.-]+(\[[0-9]+\])?/
 (* Define fields *)
 
 (* TODO: there could be a " " in the middle of a value ... *)
-let sto_to_spc        = store /[^\\#,;\{\}" \t\n]+|"[^\\#"\n]+"/
+let sto_to_spc        = store /[^\\#,;{}" \t\n]+|"[^\\#"\n]+"/
 let sto_to_scl        = store /[^ \t][^;\n]+[^ \t]|[^ \t;\n]+/
 let rfc_code          = [ key "code" . sep_spc . store word ]
                       . sep_eq
diff --git a/lenses/dhcpd.aug b/lenses/dhcpd.aug
index 7738368..8cbc3db 100644
--- a/lenses/dhcpd.aug
+++ b/lenses/dhcpd.aug
@@ -81,7 +81,7 @@ let ip                = Rx.ipv4
 
 (* borrowed from sysconfig.aug *)
   (* Chars allowed in a bare string *)
-  let bchar = /[^ \t\n\"'\\{\}#,\(\)]|\\\\./
+  let bchar = /[^ \t\n"'\\{}#,()]|\\\\./
   let qchar = /["']/  (* " *)
 
   (* We split the handling of right hand sides into a few cases:
diff --git a/lenses/dnsmasq.aug b/lenses/dnsmasq.aug
index 8167795..b9d6833 100644
--- a/lenses/dnsmasq.aug
+++ b/lenses/dnsmasq.aug
@@ -29,7 +29,7 @@ let sto_to_eol = store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
  *                               ENTRIES
  *************************************************************************)
 
-let entry_re   = /[A-Za-z0-9\._-]+/
+let entry_re   = /[A-Za-z0-9._-]+/
 let entry      = [ key entry_re . (sep_eq . sto_to_eol)? . eol ]
 
 (************************************************************************
diff --git a/lenses/exports.aug b/lenses/exports.aug
index 088d273..722099e 100644
--- a/lenses/exports.aug
+++ b/lenses/exports.aug
@@ -76,7 +76,7 @@ About: Limitations
 module Exports =
   autoload xfm
 
-  let client_re = /[a-zA-Z0-9\.@\*\?\/\-]+/
+  let client_re = /[a-zA-Z0-9.@*?\/-]+/
 
   let eol = Util.eol
   let lbracket  = Util.del_str "("
diff --git a/lenses/fai_diskconfig.aug b/lenses/fai_diskconfig.aug
index 2c29a0d..bab1ef6 100644
--- a/lenses/fai_diskconfig.aug
+++ b/lenses/fai_diskconfig.aug
@@ -145,7 +145,7 @@ let name = [ label "name" . store /[^\/ \t\n]+/ ]
 let partition = [ label "partition" . Util.del_str "." . store /[0-9]+/ ]
 
 (* Variable: disk *)
-let disk = [ label "disk" . store /[^\., \t\n]+/ . partition? ]
+let disk = [ label "disk" . store /[^., \t\n]+/ . partition? ]
 
 (* Variable: vg_option
    An option for <volume_vg> *)
@@ -165,7 +165,7 @@ let spare_missing = tag /spare|missing/
 
 (* Variable: disk_with_opt
    A <disk> with a spare/missing option for raids *)
-let disk_with_opt = [ label "disk" . store /[^:\., \t\n]+/ . partition?
+let disk_with_opt = [ label "disk" . store /[^:., \t\n]+/ . partition?
                     . spare_missing* ]
 
 (* Variable: disk_list
diff --git a/lenses/gdm.aug b/lenses/gdm.aug
index 5ac0bf8..0b47683 100644
--- a/lenses/gdm.aug
+++ b/lenses/gdm.aug
@@ -18,7 +18,7 @@ let empty    = IniFile.empty
  *                        ENTRY
  * Entry keywords can be bare digits as well (the [server] section)
  *************************************************************************)
-let entry_re = ( /[A-Za-z0-9][A-Za-z0-9\._-]*/ )
+let entry_re = ( /[A-Za-z0-9][A-Za-z0-9._-]*/ )
 let entry    = IniFile.entry entry_re sep comment
 
 
diff --git a/lenses/grub.aug b/lenses/grub.aug
index b2ffad4..c978b04 100644
--- a/lenses/grub.aug
+++ b/lenses/grub.aug
@@ -93,7 +93,7 @@ module Grub =
 
     (* Parse the file name and args on a kernel or module line. *)
     let kernel_args =
-      let arg = /[A-Za-z0-9_.\$-]+/ - /type|no-mem-option/  in
+      let arg = /[A-Za-z0-9_.$-]+/ - /type|no-mem-option/  in
       store /(\([a-z0-9,]+\))?\/[^ \t\n]*/ .
             (spc . multiboot_arg)? .
             (spc . [ key arg . (eq. store /([^ \t\n])*/)?])* . eol
diff --git a/lenses/httpd.aug b/lenses/httpd.aug
index 8fbd4a3..958324f 100644
--- a/lenses/httpd.aug
+++ b/lenses/httpd.aug
@@ -50,8 +50,8 @@ let sep_spc    =  del /([ \t]+|[ \t]*\\\\\n[ \t]*)/ " "
 let sep_osp             = Sep.opt_space
 let sep_eq              = del /[ \t]*=[ \t]*/ "="
 
-let nmtoken             = /[a-zA-Z:_][a-zA-Z0-9:_\.-]*/
-let word                = /[a-zA-Z][a-zA-Z0-9\._\-]*/
+let nmtoken             = /[a-zA-Z:_][a-zA-Z0-9:_.-]*/
+let word                = /[a-zA-Z][a-zA-Z0-9._-]*/
 
 let comment             = Util.comment
 let eol                 = Util.eol
diff --git a/lenses/inetd.aug b/lenses/inetd.aug
index c2d0879..6cfbdd8 100644
--- a/lenses/inetd.aug
+++ b/lenses/inetd.aug
@@ -86,7 +86,7 @@ module Inetd =
 
 	let del_str = Util.del_str
 
-	let address = [ seq "addrseq" . store /([a-zA-Z0-9\.-]+|\*)/ ]
+	let address = [ seq "addrseq" . store /([a-zA-Z0-9.-]+|\*)/ ]
 	let address_list = ( counter "addrseq" . (address . del_str ",")* . address )
 
 	let argument = [ seq "argseq" . store /[^ \t\n]+/ ]
@@ -109,8 +109,8 @@ module Inetd =
 	             . [ del_str "." . label "max" . store /[0-9]+/ ]?
 	           )
 
-	let usergroup = ( [ label "user" . store /[^ \t\n:\.]+/ ]
-	                  . [ del /[:\.]/ ":" . label "group" . store /[^ \t\n:\.]+/ ]?
+	let usergroup = ( [ label "user" . store /[^ \t\n:.]+/ ]
+	                  . [ del /[:.]/ ":" . label "group" . store /[^ \t\n:.]+/ ]?
 	                )
 
 	let command = ( [ label "command" . store /[^ \t\n]+/ ]
diff --git a/lenses/inifile.aug b/lenses/inifile.aug
index b10652a..3be831a 100644
--- a/lenses/inifile.aug
+++ b/lenses/inifile.aug
@@ -177,7 +177,7 @@ let indented_entry (kw:regexp) (sep:lens) (comment:lens)
 Variable: entry_re
   Default regexp for <entry> keyword
 *)
-let entry_re           = ( /[A-Za-z][A-Za-z0-9\._-]+/ )
+let entry_re           = ( /[A-Za-z][A-Za-z0-9._-]+/ )
 
 
 (************************************************************************
diff --git a/lenses/iptables.aug b/lenses/iptables.aug
index 21c5f18..28e6bfe 100644
--- a/lenses/iptables.aug
+++ b/lenses/iptables.aug
@@ -51,7 +51,7 @@ let tcp_flags =
 let ipt_match =
   let any_key = /[a-zA-Z-][a-zA-Z-]+/ -
     /protocol|source|destination|jump|goto|in-interface|out-interface|fragment|match|tcp-flags/ in
-  let any_val = /([^\" \t\n!-][^ \t\n]*)|\"([^\"\\\n]|\\\\.)*\"/ in
+  let any_val = /([^" \t\n!-][^ \t\n]*)|"([^"\\\n]|\\\\.)*"/ in
   let any_param =
     [ [ spc . dels "!" . label "not" ]? .
       spc . dels "--" . key any_key . (spc . store any_val)? ] in
diff --git a/lenses/keepalived.aug b/lenses/keepalived.aug
index 771c32f..b5e1dc2 100644
--- a/lenses/keepalived.aug
+++ b/lenses/keepalived.aug
@@ -147,7 +147,7 @@ let prefixlen = [ label "prefixlen" . Util.del_str "/" . sto_num ]
 
 (* View: ipaddr
 An IP address or range with an optional mask *)
-let ipaddr = label "ipaddr" . store /[0-9\.-]+/ . prefixlen?
+let ipaddr = label "ipaddr" . store /[0-9.-]+/ . prefixlen?
 
 (* View: ipdev
 A device for IP addresses *)
diff --git a/lenses/openvpn.aug b/lenses/openvpn.aug
index 0685888..a759d00 100644
--- a/lenses/openvpn.aug
+++ b/lenses/openvpn.aug
@@ -176,7 +176,7 @@ let remote        = [ key "remote" . sep
 		    ]
 
 let http_proxy    = [ key "http-proxy" .
-                    ( sep . [ label "server" . store /[A-Za-z0-9\._-]+/ ] .
+                    ( sep . [ label "server" . store /[A-Za-z0-9._-]+/ ] .
 		    ( sep . [ label "port"   . num      ] )? )?
 		    . comment_or_eol
 		    ]
diff --git a/lenses/pg_hba.aug b/lenses/pg_hba.aug
index 052cd06..c960e3f 100644
--- a/lenses/pg_hba.aug
+++ b/lenses/pg_hba.aug
@@ -25,7 +25,7 @@ module Pg_Hba =
     let word    = Rx.neg1
     (* Variable: ipaddr
        CIDR or ip+netmask *)
-    let ipaddr   = /[0-9a-fA-F:\.]+(\/[0-9]+|[ \t]+[0-9\.]+)/
+    let ipaddr   = /[0-9a-fA-F:.]+(\/[0-9]+|[ \t]+[0-9.]+)/
 
     let comma_sep_list (l:string) =
         let lns = [ label l . store word ] in
diff --git a/lenses/phpvars.aug b/lenses/phpvars.aug
index 998fff5..932557b 100644
--- a/lenses/phpvars.aug
+++ b/lenses/phpvars.aug
@@ -27,7 +27,7 @@ let chr_blank = /[ \t]/
 let chr_nblank = /[^ \t\n]/
 let chr_any    = /./
 let chr_star   = /\*/
-let chr_nstar  = /[^\* \t\n]/
+let chr_nstar  = /[^* \t\n]/
 let chr_slash  = /\//
 let chr_nslash = /[^\/ \t\n]/
 
diff --git a/lenses/properties.aug b/lenses/properties.aug
index d8f4270..8400372 100644
--- a/lenses/properties.aug
+++ b/lenses/properties.aug
@@ -15,7 +15,7 @@ module Properties =
   let sepch        = del /[ \t]*=[ \t]*/ "="
   let value_to_eol = /[^ \t\n](.*[^ \t\n])?/
   let indent       = Util.indent
-  let entry        = /[A-Za-z][A-Za-z0-9\.]+/
+  let entry        = /[A-Za-z][A-Za-z0-9.]+/
 
   (* define comments and properties*)
   let comment     = Util.comment
diff --git a/lenses/rx.aug b/lenses/rx.aug
index f1f04ad..917e287 100644
--- a/lenses/rx.aug
+++ b/lenses/rx.aug
@@ -77,5 +77,5 @@ let device_name = /[a-zA-Z0-9_?.+:!-]+/
  * Variable: email_addr
  *    To be refined
  *)
-let email_addr = /[A-Za-z0-9_\+\.-]+@[A-Za-z0-9_\.-]+/
+let email_addr = /[A-Za-z0-9_+.-]+@[A-Za-z0-9_.-]+/
 
diff --git a/lenses/solaris_system.aug b/lenses/solaris_system.aug
index 03e277a..e350314 100644
--- a/lenses/solaris_system.aug
+++ b/lenses/solaris_system.aug
@@ -44,7 +44,7 @@ let modpath = [ seq "modpath" . store /[^ :\t\n]+/ ]
 
 (* Variable: set_operator
     Valid set operators: equals, bitwise AND and OR *)
-let set_operators = /[=&\|]/
+let set_operators = /[=&|]/
 
 (* View: set_value
     Sets an integer value or char pointer *)
diff --git a/lenses/spacevars.aug b/lenses/spacevars.aug
index ea0f5a3..fd7f4e0 100644
--- a/lenses/spacevars.aug
+++ b/lenses/spacevars.aug
@@ -22,7 +22,7 @@ let empty   = Util.empty
  *************************************************************************)
 
 
-let entry = Build.key_ws_value /[A-Za-z0-9\._-]+(\[[0-9]+\])?/
+let entry = Build.key_ws_value /[A-Za-z0-9._-]+(\[[0-9]+\])?/
 
 (************************************************************************
  *                                LENS
diff --git a/lenses/sudoers.aug b/lenses/sudoers.aug
index 494ab6a..376e590 100644
--- a/lenses/sudoers.aug
+++ b/lenses/sudoers.aug
@@ -83,15 +83,15 @@ let sep_dquote   = Util.del_str "\""
 
 (* Variable: sto_to_com_cmnd
 sto_to_com_cmnd does not begin or end with a space *)
-let sto_to_com_cmnd = store /([^,=:#() \t\n\\\\]([^,=:#()\n\\\\]|\\\\[=:,\\\\])*[^,=:#() \t\n\\\\])|[^,=:#() \t\n\\\\]/
+let sto_to_com_cmnd = store /([^,=:#() \t\n\\]([^,=:#()\n\\]|\\\\[=:,\\])*[^,=:#() \t\n\\])|[^,=:#() \t\n\\]/
 
 (* Variable: sto_to_com
 
 There could be a \ in the middle of a command *)
-let sto_to_com      = store /([^,=:#() \t\n\\\\][^,=:#()\n]*[^,=:#() \t\n\\\\])|[^,=:#() \t\n\\\\]/
+let sto_to_com      = store /([^,=:#() \t\n\\][^,=:#()\n]*[^,=:#() \t\n\\])|[^,=:#() \t\n\\]/
 
 (* Variable: sto_to_com_host *)
-let sto_to_com_host = store /[^,=:#() \t\n\\\\]+/
+let sto_to_com_host = store /[^,=:#() \t\n\\]+/
 
 
 (* Variable: sto_to_com_user
@@ -100,16 +100,16 @@ let sto_to_com_user = store ( /([^,=:#() \t\n]([^,=:#() \t\n]|(\\\\[ \t]))*[^,=:
                               - /(User|Runas|Host|Cmnd)_Alias|Defaults.*/ )
 
 (* Variable: sto_to_com_col *)
-let sto_to_com_col      = store /[^",=#() \t\n\\\\]+/ (* " relax emacs *)
+let sto_to_com_col      = store /[^",=#() \t\n\\]+/ (* " relax emacs *)
 
 (* Variable: sto_to_eq *)
-let sto_to_eq  = store /[^,=:#() \t\n\\\\]+/
+let sto_to_eq  = store /[^,=:#() \t\n\\]+/
 
 (* Variable: sto_to_spc *)
-let sto_to_spc = store /[^", \t\n\\\\]+|"[^", \t\n\\\\]+"/
+let sto_to_spc = store /[^", \t\n\\]+|"[^", \t\n\\]+"/
 
 (* Variable: sto_to_spc_no_dquote *)
-let sto_to_spc_no_dquote = store /[^",# \t\n\\\\]+/ (* " relax emacs *)
+let sto_to_spc_no_dquote = store /[^",# \t\n\\]+/ (* " relax emacs *)
 
 (* Variable: sto_integer *)
 let sto_integer = store /[0-9]+/
@@ -247,7 +247,7 @@ let alias = user_alias | runas_alias | host_alias | cmnd_alias
  *     >                  'Defaults' '>' Runas_List
  *************************************************************************)
 let default_type     =
-  let value = store /[@:>][^ \t\n\\\\]+/ in
+  let value = store /[@:>][^ \t\n\\]+/ in
   [ label "type" . value ]
 
 (************************************************************************
diff --git a/lenses/sysconfig.aug b/lenses/sysconfig.aug
index 9ee668e..2c7efaa 100644
--- a/lenses/sysconfig.aug
+++ b/lenses/sysconfig.aug
@@ -16,7 +16,7 @@ module Sysconfig =
   let nothing = del /(""|'')?/ "" . value ""
 
   (* Chars allowed in a bare string *)
-  let bchar = /[^ \t\n\"'\\]|\\\\./
+  let bchar = /[^ \t\n"'\\]|\\\\./
   let qchar = /["']/  (* " *)
 
   (* We split the handling of right hand sides into a few cases:
diff --git a/lenses/xml.aug b/lenses/xml.aug
index d153b9c..1bcdc6a 100644
--- a/lenses/xml.aug
+++ b/lenses/xml.aug
@@ -19,8 +19,8 @@ let sep_spc           = del /[ \t\n]+/ " "
 let sep_osp           = del /[ \t\n]*/ ""
 let sep_eq            = del /[ \t\n]*=[ \t\n]*/ "="
 
-let nmtoken             = /[a-zA-Z:_][a-zA-Z0-9:_\.-]*/
-let word                = /[a-zA-Z][a-zA-Z0-9\._\-]*/
+let nmtoken             = /[a-zA-Z:_][a-zA-Z0-9:_.-]*/
+let word                = /[a-zA-Z][a-zA-Z0-9._-]*/
 let char                = /.|\n/
 (* if we hide the quotes, then we can only accept single or double quotes *)
 (* otherwise a put ambiguity is raised *)
-- 
1.7.6.4




More information about the augeas-devel mailing list