OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
ProcessSpawn.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <vector>
6#include "utils_export.h"
7
8namespace Utils
9{
10 // Security-audit F001: spawn an external tool with an argv array, never a
11 // shell command string. Every argument travels to the child as a single
12 // argv entry, so metacharacters inside archive-derived paths (';', '$',
13 // backticks, spaces...) are data, not syntax. This is the only sanctioned
14 // way to run an external process on untrusted-derived inputs.
15 //
16 // program: searched on PATH when it contains no path separator.
17 // args: argv[1..n] passed verbatim to the child.
18 // discardOutput: when true the child's stdin/stdout/stderr are connected
19 // to the null device instead of this process's streams.
20 //
21 // Returns the child's exit code, or -1 when the process could not be
22 // started (program not found, exec failure, etc.). The return type is
23 // 64-bit so Windows crash codes (e.g. 0xC0000005) stay POSITIVE and are
24 // reported as command failures, not confused with the -1 spawn-failure
25 // sentinel; a child killed by a signal returns 128+signal (shell
26 // convention), also distinct from -1.
27 std::int64_t run_process(const std::string& program, const std::vector<std::string>& args, bool discardOutput = true);
28}
std::int64_t run_process(const std::string &program, const std::vector< std::string > &args, bool discardOutput)