From 8ea64a78d65807c8496e9d089f18af001aeb932d Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 16 Dec 2015 11:53:01 +0100 Subject: [PATCH 1/4] pki: Never print more than MAX_LINES of usage summary Print a warning if a registered command exceeds that limit. --- src/pki/command.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pki/command.c b/src/pki/command.c index 13e81404c..ce704dbb8 100644 --- a/src/pki/command.c +++ b/src/pki/command.c @@ -172,6 +172,15 @@ void command_register(command_t command) "options", '+', 1, "read command line options from file" }; } + for (i = 0; cmds[registered].line[i]; i++) + { + if (i == MAX_LINES - 1) + { + fprintf(stderr, "command '%s' specifies too many usage summary " + "lines, please increase MAX_LINES\n", command.cmd); + break; + } + } } registered++; } @@ -208,7 +217,7 @@ int command_usage(char *error) } else { - for (i = 0; cmds[active].line[i]; i++) + for (i = 0; i < MAX_LINES && cmds[active].line[i]; i++) { if (i == 0) { From 50e190e8add8c36da39865d604a96897786cb5d4 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 16 Dec 2015 11:55:14 +0100 Subject: [PATCH 2/4] pki: Increase MAX_LINES The --issue and --self commands both define 10 lines of usage summary text. --- src/pki/command.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pki/command.h b/src/pki/command.h index e55c579e4..449252eb8 100644 --- a/src/pki/command.h +++ b/src/pki/command.h @@ -34,7 +34,7 @@ /** * Maximum number of usage summary lines (+1) */ -#define MAX_LINES 10 +#define MAX_LINES 11 typedef struct command_t command_t; typedef struct command_option_t command_option_t; From b0f00b2a3cf5ca095a9a568dc02aaa4b66e76552 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 16 Dec 2015 11:56:44 +0100 Subject: [PATCH 3/4] swanctl: Never print more than MAX_LINES of usage summary Print a warning if a registered command exceeds that limit. --- src/swanctl/command.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/swanctl/command.c b/src/swanctl/command.c index 26c41346c..fd9bc0083 100644 --- a/src/swanctl/command.c +++ b/src/swanctl/command.c @@ -176,6 +176,15 @@ void command_register(command_t command) "uri", 'u', 1, "service URI to connect to" }; } + for (i = 0; cmds[registered].line[i]; i++) + { + if (i == MAX_LINES - 1) + { + fprintf(stderr, "command '%s' specifies too many usage summary " + "lines, please increase MAX_LINES\n", command.cmd); + break; + } + } } registered++; } @@ -217,7 +226,7 @@ int command_usage(char *error, ...) } else { - for (i = 0; cmds[active].line[i]; i++) + for (i = 0; i < MAX_LINES && cmds[active].line[i]; i++) { if (i == 0) { From 3f2c3052267662521383d8b0cdb1e33907073e0a Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 16 Dec 2015 12:20:35 +0100 Subject: [PATCH 4/4] swanctl: Slightly change usage summary for --list-certs --- src/swanctl/commands/list_certs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/swanctl/commands/list_certs.c b/src/swanctl/commands/list_certs.c index b2ff3b5c7..2c314d8b2 100644 --- a/src/swanctl/commands/list_certs.c +++ b/src/swanctl/commands/list_certs.c @@ -214,10 +214,9 @@ static void __attribute__ ((constructor))reg() { command_register((command_t) { list_certs, 'x', "list-certs", "list stored certificates", - {"[--subject ] " - "[--type x509|x509_ac|x509_crl|ocsp_response|pubkey]\n " - "[--flag none|ca|aa|ocsp|any] " - "[--pem] [--raw|--pretty|--short|--utc]"}, + {"[--subject ] [--pem]", + "[--type x509|x509_ac|x509_crl|ocsp_response|pubkey]", + "[--flag none|ca|aa|ocsp|any] [--raw|--pretty|--short|--utc]"}, { {"help", 'h', 0, "show usage information"}, {"subject", 's', 1, "filter by certificate subject"},