diff options
author | cflip <cflip@cflip.net> | 2022-09-20 11:08:11 -0600 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2022-09-20 11:10:47 -0600 |
commit | ce173bd3d1c66f937a958419a2c82786404e0d2e (patch) | |
tree | 3a3ae72125c42ade78ee29e14009dd612713772e /src/CGIScript.cpp | |
parent | 08a43acee041e6de83c5b9e8c16265fa2de0983e (diff) |
Validate CGI script paths before starting up the server
This still doesn't throw up an error when attepting to run scripts
without the leading './', but it's a start
Diffstat (limited to 'src/CGIScript.cpp')
-rw-r--r-- | src/CGIScript.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/CGIScript.cpp b/src/CGIScript.cpp index 8731023..3ef1f3f 100644 --- a/src/CGIScript.cpp +++ b/src/CGIScript.cpp @@ -1,8 +1,11 @@ #include "CGIScript.h" #include <cstdlib> +#include <filesystem> +#include <iostream> #include <sstream> #include <string> +#include <unistd.h> CGIScript::CGIScript(const std::string& script_path) : m_script_path(script_path) @@ -49,3 +52,18 @@ std::string CGIScript::read_output() return sstream.str(); } + +void CGIScript::validate_path(const std::string& script_path) +{ + namespace fs = std::filesystem; + + if (!fs::exists(script_path)) { + std::cerr << "cfws: Script not found: " << script_path << std::endl; + exit(1); + } + + if (access(script_path.c_str(), X_OK)) { + std::cerr << "cfws: Script does not have execute permissions: " << script_path << std::endl; + exit(1); + } +} |