2 ms·
The crazy thing is that there is a correct escaping available: `escapeshellarg()`. With correct escaping, you don't even need to sanitize the user input here -
by mappu 7y ago
The crazy thing is that there is a correct escaping available: `escapeshellarg()`. With correct escaping, you don't even need to sanitize the user input here - the target command will parse the MAC address itself and report any errors.
The existing code is analogous to building SQL queries using string concatenation and forgetting the mysqli_real_escape_string() call. Really the solution is to use a parameterized interface (e.g. by calling pcntl_fork() + pcntl_exec(), that accepts an array of arguments instead of a string command-line).
Pcntl doesn't seem to have a wrapper for the posix_spawn syscall.
- kpcyrd 7y agoescapeshellarg is an ugly hack, php is passing everything through `sh -c` for no reason. The pcntl_exec function is the only one that has a reasonable interface, but is way too low level. php should simply accept this as a valid function call: exec(["sudo", "pihole", "-a", "addstaticdhcp", $mac, $ip, $hostname]);