diff options
author | John Estabrook <jestabro@vyos.io> | 2025-05-13 15:27:22 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-13 15:27:22 -0500 |
commit | 176163e5a6911e88ca790e503ed501d5aceaff34 (patch) | |
tree | 314fd8c7b29de28ef063e1686c0b877047359686 | |
parent | 08e0d27887d073dc4b8e452af0a137cd8d30a7ac (diff) | |
parent | c6cb5ce2724a52b3b7b3741323c4466c87953c6a (diff) | |
download | vyos-utils-176163e5a6911e88ca790e503ed501d5aceaff34.tar.gz vyos-utils-176163e5a6911e88ca790e503ed501d5aceaff34.zip |
Merge pull request #33 from dmbaturin/T7450-use-pcre2
validators: T7450: use PCRE2 instead of the outdated original PCRE
-rw-r--r-- | debian/control | 3 | ||||
-rw-r--r-- | src/completion/list_interfaces/list_interfaces.ml | 14 | ||||
-rw-r--r-- | src/dune | 8 | ||||
-rw-r--r-- | src/validate_value.ml | 6 | ||||
-rw-r--r-- | src/validators/numeric.ml | 6 | ||||
-rw-r--r-- | src/validators/url.ml | 30 |
6 files changed, 34 insertions, 33 deletions
diff --git a/debian/control b/debian/control index 4ae87ca..4aa2d73 100644 --- a/debian/control +++ b/debian/control @@ -3,8 +3,7 @@ Section: contrib/net Priority: extra Maintainer: VyOS Package Maintainers <maintainers@vyos.net> Build-Depends: debhelper (>= 9), - quilt, - libpcre3-dev, + quilt Standards-Version: 3.9.6 Package: vyos-utils diff --git a/src/completion/list_interfaces/list_interfaces.ml b/src/completion/list_interfaces/list_interfaces.ml index 58d0693..f3db6bd 100644 --- a/src/completion/list_interfaces/list_interfaces.ml +++ b/src/completion/list_interfaces/list_interfaces.ml @@ -44,10 +44,10 @@ let type_to_prefix it = (* filter_section to match the constraint of python.vyos.ifconfig.section *) -let rx = Pcre.regexp {|\d(\d|v|\.)*$|} +let rx = Pcre2.regexp {|\d(\d|v|\.)*$|} let filter_section s = - let r = Pcre.qreplace_first ~rex:rx ~templ:"" s in + let r = Pcre2.qreplace_first ~rex:rx ~templ:"" s in match r with |"bond"|"br"|"dum"|"eth"|"gnv"|"ifb"|"l2tpeth"|"lo"|"macsec" -> true |"peth"|"pppoe"|"sstpc"|"tun"|"veth"|"vti"|"vtun"|"vxlan"|"wg"|"wlan"|"wwan" -> true @@ -57,7 +57,7 @@ let filter_from_prefix p s = let pattern = Printf.sprintf "^%s(.*)$" p in try - let _ = Pcre.exec ~pat:pattern s in + let _ = Pcre2.exec ~pat:pattern s in true with Not_found -> false @@ -71,7 +71,7 @@ let filter_broadcast s = let pattern = {|^(bond|br|tun|vtun|eth|gnv|peth|macsec|vxlan|wwan|wlan)(.*)$|} in try - let _ = Pcre.exec ~pat:pattern s in + let _ = Pcre2.exec ~pat:pattern s in true with Not_found -> false @@ -79,7 +79,7 @@ let filter_bridgeable s = let pattern = {|^(bond|eth|gnv|l2tpeth|lo|tun|veth|vtun|vxlan|wlan)(.*)$|} in try - let _ = Pcre.exec ~pat:pattern s in + let _ = Pcre2.exec ~pat:pattern s in true with Not_found -> false @@ -87,7 +87,7 @@ let filter_bondable s = let pattern = {|^(eth)(.*)$|} in try - let _ = Pcre.exec ~pat:pattern s in + let _ = Pcre2.exec ~pat:pattern s in true with Not_found -> false @@ -95,7 +95,7 @@ let filter_no_vlan s = let pattern = {|^([^.]+)(\.\d+)+$|} in try - let _ = Pcre.exec ~pat:pattern s in + let _ = Pcre2.exec ~pat:pattern s in false with Not_found -> true @@ -4,13 +4,13 @@ (name numeric) (public_name numeric) (modules numeric) - (libraries pcre)) + (libraries pcre2)) (executable (name url) (public_name url) (modules url) - (libraries pcre)) + (libraries pcre2)) (executable (name file_path) @@ -22,13 +22,13 @@ (name validate_value) (public_name validate-value) (modules validate_value) - (libraries pcre unix containers)) + (libraries pcre2 unix containers)) (executable (name list_interfaces) (public_name list_interfaces) (modules func list_interfaces) - (libraries pcre) + (libraries pcre2) (foreign_stubs (language c) (names iface))) diff --git a/src/validate_value.ml b/src/validate_value.ml index 05d62b1..fd9f3d9 100644 --- a/src/validate_value.ml +++ b/src/validate_value.ml @@ -12,14 +12,16 @@ let rec validate_value buf value_constraint value = | Group l -> List.for_all (fun c -> validate_value buf c value) l | Regex s -> - (try let _ = Pcre.exec ~pat:(Printf.sprintf "^%s$" s) value in true + (try let _ = Pcre2.exec ~pat:(Printf.sprintf "^%s$" s) value in true with Not_found -> false) | Exec c -> (* XXX: Unix.open_process_in is "shelling out", which is a bad idea on multiple levels, especially when the input comes directly from the user... We should do something about it. *) - let chan = Unix.open_process_in (Printf.sprintf "%s \'%s\' 2>&1" c value) in + let cmd = Printf.sprintf "%s \'%s\' 2>&1" c value in + let () = Printf.printf "COMMAND: %s" cmd in + let chan = Unix.open_process_in cmd in let out = try CCIO.read_all chan with _ -> "" in let result = Unix.close_process_in chan in match result with diff --git a/src/validators/numeric.ml b/src/validators/numeric.ml index 0c75f83..e6caddc 100644 --- a/src/validators/numeric.ml +++ b/src/validators/numeric.ml @@ -65,11 +65,11 @@ let check_positive opts m = failwith "option '--positive does' not apply to a range value" let looks_like_number value = - try let _ = Pcre.exec ~pat:"^(\\-?)[0-9]+(\\.[0-9]+)?$" value in true + try let _ = Pcre2.exec ~pat:"^(\\-?)[0-9]+(\\.[0-9]+)?$" value in true with Not_found -> false let is_relative value = - try let _ = Pcre.exec ~pat:"^[+-][0-9]+$" value in true + try let _ = Pcre2.exec ~pat:"^[+-][0-9]+$" value in true with Not_found -> false let number_string_drop_modifier value = @@ -170,7 +170,7 @@ let check_argument_type opts m = else Printf.ksprintf failwith "Value must be a number, not a range" let is_range_val s = - try let _ = Pcre.exec ~pat:"^[0-9]+-[0-9]+$" s in true + try let _ = Pcre2.exec ~pat:"^[0-9]+-[0-9]+$" s in true with Not_found -> false let var_numeric_str s = diff --git a/src/validators/url.ml b/src/validators/url.ml index 3d77544..7ba5dcf 100644 --- a/src/validators/url.ml +++ b/src/validators/url.ml @@ -9,9 +9,9 @@ *) let split_scheme url = let aux url = - let res = Pcre.exec ~pat:{|^([a-zA-Z0-9\.\-]+):(.*)$|} url in - let scheme = Pcre.get_substring res 1 in - let uri = Pcre.get_substring res 2 in + let res = Pcre2.exec ~pat:{|^([a-zA-Z0-9\.\-]+):(.*)$|} url in + let scheme = Pcre2.get_substring res 1 in + let uri = Pcre2.get_substring res 2 in (String.lowercase_ascii scheme, uri) in try Ok (aux url) @@ -24,17 +24,17 @@ let is_scheme_allowed allowed_schemes scheme = let regex_matches regex s = try - let _ = Pcre.exec ~rex:regex s in + let _ = Pcre2.exec ~rex:regex s in true with Not_found -> false let host_path_format = - Pcre.regexp + Pcre2.regexp {|^//(?:[^/?#]+(?::[^/?#]*)?@)?([a-zA-Z0-9\-\._~]+|\[[a-zA-Z0-9:\.]+\])(?::([0-9]+))?(/.*)?$|} -let host_name_format = Pcre.regexp {|^[a-zA-Z0-9]+([\-\._~]{1}[a-zA-Z0-9]+)*$|} -let ipv4_addr_format = Pcre.regexp {|^(([1-9]\d{0,2}|0)\.){3}([1-9]\d{0,2}|0)$|} -let ipv6_addr_format = Pcre.regexp {|^\[([a-z0-9:\.]+|[A-Z0-9:\.]+)\]$|} +let host_name_format = Pcre2.regexp {|^[a-zA-Z0-9]+([\-\._~]{1}[a-zA-Z0-9]+)*$|} +let ipv4_addr_format = Pcre2.regexp {|^(([1-9]\d{0,2}|0)\.){3}([1-9]\d{0,2}|0)$|} +let ipv6_addr_format = Pcre2.regexp {|^\[([a-z0-9:\.]+|[A-Z0-9:\.]+)\]$|} let is_port s = try @@ -58,8 +58,8 @@ let is_ipv6_segment s = with Failure _ -> false let is_ipv4_addr s = - let res = Pcre.exec ~rex:ipv4_addr_format s in - let ipv4_addr_str = Pcre.get_substring res 0 in + let res = Pcre2.exec ~rex:ipv4_addr_format s in + let ipv4_addr_str = Pcre2.get_substring res 0 in let ipv4_addr_l = String.split_on_char '.' ipv4_addr_str in List.for_all is_ipv4_octet ipv4_addr_l @@ -83,10 +83,10 @@ let is_ipv6_dual_addr s = List.for_all is_ipv6_segment seg_str_l let is_ipv6_addr s = - let res = Pcre.exec ~rex:ipv6_addr_format s in - let ipv6_addr_str = Pcre.get_substring res 1 in + let res = Pcre2.exec ~rex:ipv6_addr_format s in + let ipv6_addr_str = Pcre2.get_substring res 1 in try - let typo = Pcre.exec ~pat:{|:::|} ipv6_addr_str in + let typo = Pcre2.exec ~pat:{|:::|} ipv6_addr_str in match typo with | _ -> false with Not_found -> @@ -94,8 +94,8 @@ let is_ipv6_addr s = let host_path_matches s = try - let res = Pcre.exec ~rex:host_path_format s in - let substr = Pcre.get_substrings ~full_match:false res in + let res = Pcre2.exec ~rex:host_path_format s in + let substr = Pcre2.get_substrings ~full_match:false res in let port_str = Array.get substr 1 in if String.length port_str > 0 && not (is_port port_str) then false else |