@@ -255,7 +255,9 @@ def test_unpack_package_link_in_readonly_dir(tmpdir):
255255 assert os .path .commonpath ([real_temp_path , os .path .realpath (path )]) == real_temp_path
256256 assert os .listdir (outside_path ) == ['secret.c' ]
257257
258- def test_unpack_package_link_in_unreadable_dir (tmpdir ):
258+ # 0o311 cannot be listed, 0o644 can be listed but its entries cannot be told apart from links
259+ @pytest .mark .parametrize ('dirmode' , [0o311 , 0o644 ])
260+ def test_unpack_package_link_in_inaccessible_dir (tmpdir , dirmode ):
259261 work_path = str (tmpdir )
260262 outside_path = os .path .join (work_path , 'outside' )
261263 os .mkdir (outside_path )
@@ -267,15 +269,19 @@ def test_unpack_package_link_in_unreadable_dir(tmpdir):
267269 # redirected out of temp by the next member, like in test_unpack_package_link_redirected_later
268270 _add_tar_member (tf , 'pkg/q.h/l.h' , linkname = 'd.h/../../../outside' )
269271 _add_tar_member (tf , 'pkg/q.h/d.h' , linkname = '.' )
270- # a directory member with a header-like name makes the folder unlistable after the links exist
271- _add_tar_member (tf , 'pkg/q.h' , dirmode = 0o311 )
272+ # a directory member with a header-like name takes the read or search bit off the folder
273+ # that holds the links, after they have been extracted
274+ _add_tar_member (tf , 'pkg/q.h' , dirmode = dirmode )
272275
273276 temp_path , source_found = unpack_package (work_path , tgz )
274277 assert source_found
275278 assert os .path .isfile (os .path .join (temp_path , 'pkg' , 'main.c' ))
276279 real_temp_path = os .path .realpath (temp_path )
280+ # the folder has to be accessible to see whether an escaping link was left in it
281+ dir_path = os .path .join (temp_path , 'pkg' , 'q.h' )
282+ os .chmod (dir_path , 0o755 )
277283 for name in ('l.h' , 'd.h' ):
278- path = os .path .join (temp_path , 'pkg' , 'q.h' , name )
284+ path = os .path .join (dir_path , name )
279285 if os .path .lexists (path ):
280286 assert os .path .commonpath ([real_temp_path , os .path .realpath (path )]) == real_temp_path
281287 assert os .listdir (outside_path ) == ['secret.c' ]
0 commit comments