aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-03-25 18:43:07 +0100
committerdec05eba <dec05eba@protonmail.com>2024-03-25 18:43:07 +0100
commit9bc8cbbdcafa0cb3748d092d01d7bdf73c7b44e8 (patch)
tree092cb0eb82d67d6b02dad9c4e181cde5c93cbe1a /src
parentc691c7213798e6aeec09c44da1cce4f2725a1964 (diff)
Check if -sc is executable at start, allow relative filename
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 8e1723d..c2417ee 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -978,18 +978,25 @@ static AVStream* create_stream(AVFormatContext *av_format_context, AVCodecContex
}
static void run_recording_saved_script_async(const char *script_file, const char *video_file, const char *type) {
+ char script_file_full[PATH_MAX];
+ script_file_full[0] = '\0';
+ if(!realpath(script_file, script_file_full)) {
+ fprintf(stderr, "Error: script file not found: %s\n", script_file);
+ return;
+ }
+
const char *args[6];
const bool inside_flatpak = getenv("FLATPAK_ID") != NULL;
if(inside_flatpak) {
args[0] = "flatpak-spawn";
args[1] = "--host";
- args[2] = script_file;
+ args[2] = script_file_full;
args[3] = video_file;
args[4] = type;
args[5] = NULL;
} else {
- args[0] = script_file;
+ args[0] = script_file_full;
args[1] = video_file;
args[2] = type;
args[3] = NULL;
@@ -997,7 +1004,7 @@ static void run_recording_saved_script_async(const char *script_file, const char
pid_t pid = fork();
if(pid == -1) {
- perror(script_file);
+ perror(script_file_full);
return;
} else if(pid == 0) { // child
setsid();
@@ -1006,7 +1013,7 @@ static void run_recording_saved_script_async(const char *script_file, const char
pid_t second_child = fork();
if(second_child == 0) { // child
execvp(args[0], (char* const*)args);
- perror(script_file);
+ perror(script_file_full);
_exit(127);
} else if(second_child != -1) { // parent
_exit(0);
@@ -1769,6 +1776,11 @@ int main(int argc, char **argv) {
fprintf(stderr, "Error: Script \"%s\" either doesn't exist or it's not a file\n", recording_saved_script);
usage();
}
+
+ if(!(buf.st_mode & S_IXUSR)) {
+ fprintf(stderr, "Error: Script \"%s\" is not executable\n", recording_saved_script);
+ usage();
+ }
}
PixelFormat pixel_format = PixelFormat::YUV420;