From fdd72db7512ecd2410e9ddcb144abea23d67b2c7 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 16 Sep 2016 16:44:50 +0300 Subject: Audit all print_process()/process ctor for path_search() --- bpkg/archive.cxx | 10 ++++++---- bpkg/checksum.cxx | 42 +++++++++++++++++++++++++++--------------- bpkg/fetch.cxx | 48 ++++++++++++++++++++++++++++++------------------ bpkg/openssl.cxx | 10 ++++++---- bpkg/pkg-unpack.cxx | 10 ++++++---- 5 files changed, 75 insertions(+), 45 deletions(-) diff --git a/bpkg/archive.cxx b/bpkg/archive.cxx index e3b5f8b..da381a4 100644 --- a/bpkg/archive.cxx +++ b/bpkg/archive.cxx @@ -68,14 +68,16 @@ namespace bpkg args.push_back (nullptr); - if (verb >= 2) - print_process (args); - try { + process_path pp (process::path_search (args[0])); + + if (verb >= 2) + print_process (args); + // If err is false, then redirect STDERR to STDOUT. // - return process (args.data (), 0, -1, (err ? 2 : 1)); + return process (pp, args.data (), 0, -1, (err ? 2 : 1)); } catch (const process_error& e) { diff --git a/bpkg/checksum.cxx b/bpkg/checksum.cxx index 8940952..fc66ccb 100644 --- a/bpkg/checksum.cxx +++ b/bpkg/checksum.cxx @@ -28,12 +28,14 @@ namespace bpkg // const char* args[] = {prog.string ().c_str (), "-q", "-s", "", nullptr}; - if (verb >= 3) - print_process (args); - try { - process pr (args, 0, -1, 1); // Redirect STDOUT and STDERR to a pipe. + process_path pp (process::path_search (args[0])); + + if (verb >= 3) + print_process (args); + + process pr (pp, args, 0, -1, 1); // Redirect STDOUT and STDERR to a pipe. try { @@ -74,13 +76,15 @@ namespace bpkg args.push_back (nullptr); + process_path pp (process::path_search (args[0])); + if (verb >= 2) print_process (args); // Pipe both STDIN and STDOUT. Process exceptions must be handled by // the caller. // - return process (args.data (), -1, -1); + return process (pp, args.data (), -1, -1); } // sha256sum @@ -93,12 +97,14 @@ namespace bpkg // const char* args[] = {prog.string ().c_str (), "--version", nullptr}; - if (verb >= 3) - print_process (args); - try { - process pr (args, 0, -1); // Redirect STDOUT to a pipe. + process_path pp (process::path_search (args[0])); + + if (verb >= 3) + print_process (args); + + process pr (pp, args, 0, -1); // Redirect STDOUT to a pipe. try { @@ -136,13 +142,15 @@ namespace bpkg args.push_back (nullptr); + process_path pp (process::path_search (args[0])); + if (verb >= 2) print_process (args); // Pipe both STDIN and STDOUT. Process exceptions must be handled by // the caller. // - return process (args.data (), -1, -1); + return process (pp, args.data (), -1, -1); } // shasum @@ -155,12 +163,14 @@ namespace bpkg // const char* args[] = {prog.string ().c_str (), "--version", nullptr}; - if (verb >= 3) - print_process (args); - try { - process pr (args, 0, -1); // Redirect STDOUT to a pipe. + process_path pp (process::path_search (args[0])); + + if (verb >= 3) + print_process (args); + + process pr (pp, args, 0, -1); // Redirect STDOUT to a pipe. try { @@ -198,13 +208,15 @@ namespace bpkg args.push_back (nullptr); + process_path pp (process::path_search (args[0])); + if (verb >= 2) print_process (args); // Pipe both STDIN and STDOUT. Process exceptions must be handled by // the caller. // - return process (args.data (), -1, -1); + return process (pp, args.data (), -1, -1); } // The dispatcher. diff --git a/bpkg/fetch.cxx b/bpkg/fetch.cxx index 33753fb..0851950 100644 --- a/bpkg/fetch.cxx +++ b/bpkg/fetch.cxx @@ -36,12 +36,14 @@ namespace bpkg // const char* args[] = {prog.string ().c_str (), "--version", nullptr}; - if (verb >= 3) - print_process (args); - try { - process pr (args, 0, -1); // Redirect STDOUT to a pipe. + process_path pp (process::path_search (args[0])); + + if (verb >= 3) + print_process (args); + + process pr (pp, args, 0, -1); // Redirect STDOUT to a pipe. string l; @@ -155,6 +157,8 @@ namespace bpkg args.push_back (url.c_str ()); args.push_back (nullptr); + process_path pp (process::path_search (args[0])); + if (verb >= 2) print_process (args); @@ -164,8 +168,8 @@ namespace bpkg // report. Process exceptions must be handled by the caller. // return fo - ? process (out.directory ().string ().c_str (), args.data ()) - : process (args.data (), 0, -1); + ? process (out.directory ().string ().c_str (), pp, args.data ()) + : process (pp, args.data (), 0, -1); } // curl @@ -178,12 +182,14 @@ namespace bpkg // const char* args[] = {prog.string ().c_str (), "--version", nullptr}; - if (verb >= 3) - print_process (args); - try { - process pr (args, 0, -1); // Redirect STDOUT to a pipe. + process_path pp (process::path_search (args[0])); + + if (verb >= 3) + print_process (args); + + process pr (pp, args, 0, -1); // Redirect STDOUT to a pipe. try { @@ -260,6 +266,8 @@ namespace bpkg args.push_back (url.c_str ()); args.push_back (nullptr); + process_path pp (process::path_search (args[0])); + if (verb >= 2) print_process (args); else if (verb == 1 && fo) @@ -273,8 +281,8 @@ namespace bpkg // Process exceptions must be handled by the caller. // return fo - ? process (args.data ()) - : process (args.data (), 0, -1); + ? process (pp, args.data ()) + : process (pp, args.data (), 0, -1); } // fetch @@ -289,12 +297,14 @@ namespace bpkg // const char* args[] = {prog.string ().c_str (), nullptr}; - if (verb >= 3) - print_process (args); - try { - process pr (args, 0, -1, 1); // Redirect STDOUT and STDERR to a pipe. + process_path pp (process::path_search (args[0])); + + if (verb >= 3) + print_process (args); + + process pr (pp, args, 0, -1, 1); // Redirect STDOUT and STDERR to a pipe. try { @@ -363,6 +373,8 @@ namespace bpkg args.push_back (url.c_str ()); args.push_back (nullptr); + process_path pp (process::path_search (args[0])); + if (verb >= 2) print_process (args); @@ -372,8 +384,8 @@ namespace bpkg // report. Process exceptions must be handled by the caller. // return fo - ? process (out.directory ().string ().c_str (), args.data ()) - : process (args.data (), 0, -1); + ? process (out.directory ().string ().c_str (), pp, args.data ()) + : process (pp, args.data (), 0, -1); } // The dispatcher. diff --git a/bpkg/openssl.cxx b/bpkg/openssl.cxx index 4e795cb..a17ae73 100644 --- a/bpkg/openssl.cxx +++ b/bpkg/openssl.cxx @@ -34,16 +34,18 @@ namespace bpkg args.insert (args.end (), options.begin (), options.end ()); args.push_back (nullptr); - if (verb >= 2) - print_process (args); - try { + process_path pp (process::path_search (args[0])); + + if (verb >= 2) + print_process (args); + // If the caller is interested in reading STDOUT and STDERR, then // redirect STDERR to STDOUT, so both can be read from the same stream. // return process ( - args.data (), in ? -1 : 0, out ? -1 : 1, err ? (out ? 1 : -1): 2); + pp, args.data (), in ? -1 : 0, out ? -1 : 1, err ? (out ? 1 : -1): 2); } catch (const process_error& e) { diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx index 53c3faf..44ee7ba 100644 --- a/bpkg/pkg-unpack.cxx +++ b/bpkg/pkg-unpack.cxx @@ -188,12 +188,14 @@ namespace bpkg args.push_back (a.string ().c_str ()); args.push_back (nullptr); - if (verb >= 2) - print_process (args); - try { - process pr (args.data ()); + process_path pp (process::path_search (args[0])); + + if (verb >= 2) + print_process (args); + + process pr (pp, args.data ()); // While it is reasonable to assuming the child process issued // diagnostics, tar, specifically, doesn't mention the archive -- cgit v1.1