From f7cf76d4d31e5ee6f4392ff4f39d5eb5e539c9dc Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sat, 1 Jul 2017 20:46:47 +0200 Subject: [PATCH] pipe: check if command line arguments are malformed --- src/pipe.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pipe.c b/src/pipe.c index 2931907ab..a42125c06 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -200,13 +200,19 @@ int main(int argc, char *argv[]) sendd.enabled = false; // receive only break; case 'd': - level = atoi(optarg); - break; + level = strtoul(optarg, &endptr, 10); + goto check; case 'h': case '?': usage(); exit(c == '?' ? EXIT_FAILURE : EXIT_SUCCESS); } + + continue; + +check: if (optarg == endptr) + error("Failed to parse parse option argument '-%c %s'", c, optarg); + } if (argc != optind + 2) {