diff options
author | Sander Vrijders <[email protected]> | 2017-11-15 13:05:30 +0100 |
---|---|---|
committer | Dimitri Staessens <[email protected]> | 2017-11-15 13:14:41 +0100 |
commit | ed08e360f59885c6ddb72254cd58c5945fc86cec (patch) | |
tree | 2beceaa22510cd4c6f5568ca113a77ea2928d7b1 /src/tools/irm/irm_bind_api.c | |
parent | c4102940e59584bb5cc45bdce2fa360dc543fe2f (diff) | |
download | ouroboros-ed08e360f59885c6ddb72254cd58c5945fc86cec.tar.gz ouroboros-ed08e360f59885c6ddb72254cd58c5945fc86cec.zip |
tools: Check process id when binding a process
This adds a check that the passed process id is in fact a number and
not gibberish.
Signed-off-by: Sander Vrijders <[email protected]>
Signed-off-by: Dimitri Staessens <[email protected]>
Diffstat (limited to 'src/tools/irm/irm_bind_api.c')
-rw-r--r-- | src/tools/irm/irm_bind_api.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/tools/irm/irm_bind_api.c b/src/tools/irm/irm_bind_api.c index a9ca8efe..d441852d 100644 --- a/src/tools/irm/irm_bind_api.c +++ b/src/tools/irm/irm_bind_api.c @@ -36,8 +36,12 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define _POSIX_C_SOURCE 200112L + #include <stdio.h> #include <stdlib.h> +#include <sys/types.h> +#include <signal.h> #include <ouroboros/irm.h> #include <ouroboros/errno.h> @@ -54,6 +58,7 @@ int do_bind_api(int argc, char ** argv) { pid_t api = -1; char * name = NULL; + char * t; while (argc > 1) { if (matches(*argv, "name") == 0) { @@ -61,7 +66,12 @@ int do_bind_api(int argc, char ** argv) ++argv; --argc; } else if (matches(*argv, "api") == 0) { - api = strtol(*(argv + 1), NULL, 10); + api = strtol(*(argv + 1), &t, 10); + if (*(argv + 1) == t || *t != '\0' || kill(api, 0)) { + printf("\"%s\" is not a valid process id.\n", + *(argv + 1)); + return -1; + } ++argv; --argc; } else { |