File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1469,8 +1469,8 @@ def _write_exclusive_result(
14691469 and (after .st_dev , after .st_ino ) == created_identity ,
14701470 "qualification result output is unsafe" ,
14711471 )
1472- os . close ( descriptor )
1473- descriptor = - 1
1472+ # Pin this inode through validation and rollback. Otherwise unlinking
1473+ # the output can let a replacement reuse its device/inode identity.
14741474
14751475 _verify_output_parent (chain )
14761476 read_flags = os .O_RDONLY | os .O_NOFOLLOW
@@ -1522,17 +1522,17 @@ def _write_exclusive_result(
15221522 os .close (reader )
15231523 except OSError :
15241524 pass
1525- if descriptor >= 0 :
1526- try :
1527- os .close (descriptor )
1528- except OSError :
1529- pass
15301525 if created and not preserve :
15311526 _remove_created_result (
15321527 parent_descriptor ,
15331528 output .name ,
15341529 created_identity ,
15351530 )
1531+ if descriptor >= 0 :
1532+ try :
1533+ os .close (descriptor )
1534+ except OSError :
1535+ pass
15361536 _close_directory_chain (chain )
15371537
15381538
Original file line number Diff line number Diff line change @@ -1274,8 +1274,8 @@ def _write_exclusive(
12741274 and (after .st_dev , after .st_ino ) == created_identity ,
12751275 "evidence output is unsafe" ,
12761276 )
1277- os . close ( descriptor )
1278- descriptor = - 1
1277+ # Pin this inode through validation and rollback. Otherwise unlinking
1278+ # the output can let a replacement reuse its device/inode identity.
12791279 _verify_directory_chain (chain , "evidence output parent" )
12801280 read_flags = os .O_RDONLY | os .O_NOFOLLOW
12811281 if hasattr (os , "O_CLOEXEC" ):
@@ -1318,12 +1318,12 @@ def _write_exclusive(
13181318 except OSError as exc :
13191319 raise QualificationError ("evidence output could not be created safely" ) from exc
13201320 finally :
1321- if descriptor >= 0 :
1322- os .close (descriptor )
13231321 if reader >= 0 :
13241322 os .close (reader )
13251323 if created and not preserve :
13261324 _remove_created (parent_fd , output .name , created_identity )
1325+ if descriptor >= 0 :
1326+ os .close (descriptor )
13271327 _close_directory_chain (chain )
13281328
13291329
You can’t perform that action at this time.
0 commit comments