summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthehxdev <hossein.khosravi.ce@gmail.com>2024-03-31 15:11:08 +0330
committerthehxdev <hossein.khosravi.ce@gmail.com>2024-03-31 15:11:08 +0330
commit03ab294b201cad77c73b6bc4fb46a95c36cd4957 (patch)
tree9b5e71074dcafb71e93454caaa0d41ff10afa363
parente4a65824c878ac009499924480cc48bb5be55481 (diff)
validate pid for -p option
-rw-r--r--src/utilities.c5
-rw-r--r--src/whatfiles.c1
2 files changed, 5 insertions, 1 deletions
diff --git a/src/utilities.c b/src/utilities.c
index c8b08b9..e183d5f 100644
--- a/src/utilities.c
+++ b/src/utilities.c
@@ -158,6 +158,11 @@ char *parse_flags(int argc, char *argv[], pid_t *pid, bool *stdout_override, boo
fprintf(stderr, "Bad PID %s given, must be integer.\n", optarg);
exit(1);
}
+ // check if the given `pid` is valid
+ if (getpgid(*pid) < 0) {
+ fprintf(stderr, "Bad PID %s given. PID is not valid or does not exist.\n", optarg);
+ exit(1);
+ }
break;
case 's':
*stdout_override = true;
diff --git a/src/whatfiles.c b/src/whatfiles.c
index 0004308..c067ccf 100644
--- a/src/whatfiles.c
+++ b/src/whatfiles.c
@@ -224,7 +224,6 @@ int main(int argc, char* argv[])
/*
TODO:
-confirm process exists for -p flag
debug flag for use by hashdriver
more hashmap tests?
better allocator/destructor for String