Repository navigation
harden output file handling against race conditions and symlink attacks - #4640
metsw24-max wants to merge 2 commits into
Conversation
Fold the open flag construction into the declaration initialiser so it stays C89-compliant (-Wdeclaration-after-statement was tripping -Werror on the FreeBSD job). Also mark the new cli-test executable so the runner can launch it.
|
Pushed a fix for the FreeBSD job. The open flags were being built with a couple of statements between the two declarations, which trips -Wdeclaration-after-statement under -Werror on that build. Folded them back into the initialiser so it stays C89-clean, and marked the new cli-test executable so the runner picks it up. |
|
any update? |
|
Thank you for this PR, and sorry for the long wait. You are right that the output could be written through a symbolic link: a dangling link at the output path was followed, even without
#4906 creates new files with Regards |
This change hardens the CLI output file creation path by eliminating race-prone patterns and preventing symlink-based overwrite attacks.
The update replaces the existing unlink-and-recreate workflow with atomic file creation semantics and introduces additional safety checks for output file handling
Replace non-atomic
unlink() + open()pattern with atomic open usingO_EXCLfor non-overwrite modePrevent symlink traversal during output file creation using
O_NOFOLLOWAdd
O_CLOEXECto reduce file descriptor leakage across exec boundariesIntroduce explicit handling of
EEXISTandELOOPfor clearer and safer error reporting