From d54bada7e627581409107d19b452dde680c1331c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano?= Date: Sat, 31 Oct 2020 18:40:55 +0100 Subject: [PATCH] Open handles with O_CLOEXEC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit opustags’s only use of a sub-process is for spawning the EDITOR, and we don’t want it to access our file handles. --- src/cli.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cli.cc b/src/cli.cc index 261ada8..e4d8227 100644 --- a/src/cli.cc +++ b/src/cli.cc @@ -319,7 +319,7 @@ static ot::status edit_tags_interactively(ot::opus_tags& tags, const std::option } // Applying the new tags. - tags_file = fopen(tags_path.c_str(), "r"); + tags_file = fopen(tags_path.c_str(), "re"); if (tags_file == nullptr) return {ot::st::standard_error, "Error opening " + tags_path + ": " + strerror(errno)}; if ((rc = ot::read_comments(tags_file, tags.comments)) != ot::st::ok) { @@ -410,7 +410,7 @@ static ot::status run_single(const ot::options& opt, const std::string& path_in, ot::file input; if (path_in == "-") input = stdin; - else if ((input = fopen(path_in.c_str(), "r")) == nullptr) + else if ((input = fopen(path_in.c_str(), "re")) == nullptr) return {ot::st::standard_error, "Could not open '" + path_in + "' for reading: " + strerror(errno)}; ot::ogg_reader reader(input.get()); @@ -450,7 +450,7 @@ static ot::status run_single(const ot::options& opt, const std::string& path_in, /* The output file exists. */ if (!S_ISREG(output_info.st_mode)) { /* Special files are opened for writing directly. */ - if ((final_output = fopen(path_out->c_str(), "w")) == nullptr) + if ((final_output = fopen(path_out->c_str(), "we")) == nullptr) rc = {ot::st::standard_error, "Could not open '" + path_out.value() + "' for writing: " + strerror(errno)};