@@ -2,28 +2,14 @@ use std::{
22 collections:: { HashMap , HashSet } ,
33 ffi:: { OsStr , OsString } ,
44 os:: unix:: prelude:: OsStrExt ,
5- path:: Path ,
65} ;
76
87use crate :: common:: { CommandAndArguments , Context , Error } ;
98use crate :: sudoers:: Restrictions ;
10- use crate :: system:: PATH_MAX ;
9+ use crate :: system:: { audit :: zoneinfo_path , PATH_MAX } ;
1110
1211use super :: wildcard_match:: wildcard_match;
1312
14- fn path_zoneinfo ( ) -> Option < & ' static str > {
15- [
16- "/usr/share/zoneinfo" ,
17- "/usr/share/lib/zoneinfo" ,
18- "/usr/lib/zoneinfo" ,
19- "/usr/lib/zoneinfo" ,
20- ]
21- . into_iter ( )
22- // Note: We assume that /usr and all contents are only writable by root. If they
23- // aren't, you can trivially escalate to root anyway.
24- . find ( |p| Path :: new ( p) . exists ( ) )
25- }
26-
2713// TODO: use _PATH_STDPATH from paths.h
2814pub ( crate ) const PATH_DEFAULT : & str = "/usr/bin:/bin:/usr/sbin:/sbin" ;
2915
@@ -152,7 +138,7 @@ fn is_safe_tz(value: &[u8]) -> bool {
152138 } ;
153139
154140 if check_value. starts_with ( b"/" ) {
155- if let Some ( path_zoneinfo) = path_zoneinfo ( ) {
141+ if let Some ( path_zoneinfo) = zoneinfo_path ( ) {
156142 if !check_value. starts_with ( path_zoneinfo. as_bytes ( ) )
157143 || check_value. get ( path_zoneinfo. len ( ) ) != Some ( & b'/' )
158144 {
@@ -266,7 +252,7 @@ where
266252
267253#[ cfg( test) ]
268254mod tests {
269- use super :: { is_safe_tz, path_zoneinfo , should_keep } ;
255+ use super :: { is_safe_tz, should_keep , zoneinfo_path } ;
270256 use std:: { collections:: HashSet , ffi:: OsStr } ;
271257
272258 struct TestConfiguration {
@@ -328,7 +314,7 @@ mod tests {
328314 #[ allow( clippy:: bool_assert_comparison) ]
329315 #[ test]
330316 fn test_tzinfo ( ) {
331- let path_zoneinfo = path_zoneinfo ( ) . unwrap ( ) ;
317+ let path_zoneinfo = zoneinfo_path ( ) . unwrap ( ) ;
332318 assert_eq ! ( is_safe_tz( "Europe/Amsterdam" . as_bytes( ) ) , true ) ;
333319 assert_eq ! (
334320 is_safe_tz( format!( "{path_zoneinfo}/Europe/London" ) . as_bytes( ) ) ,
0 commit comments