# HG changeset patch # User Guilhem Moulin # Date 1446825264 -28800 # Node ID 8b6cba29876807adf94ac1e8e7586f69ab7c3e0b # Parent 0a1891e23b180364ce58b0dcc1d21182e3291224 Enable bundling diff -r 0a1891e23b18 -r 8b6cba298768 svr-runopts.c --- a/svr-runopts.c Wed Nov 04 23:22:58 2015 +0800 +++ b/svr-runopts.c Fri Nov 06 23:54:24 2015 +0800 @@ -112,13 +112,14 @@ void svr_getopts(int argc, char ** argv) { - unsigned int i; + unsigned int i, j; char ** next = 0; int nextisport = 0; char* recv_window_arg = NULL; char* keepalive_arg = NULL; char* idle_timeout_arg = NULL; char* keyfile = NULL; + char c; /* see printhelp() for options */ @@ -168,33 +169,10 @@ #endif for (i = 1; i < (unsigned int)argc; i++) { - if (nextisport) { - addportandaddress(argv[i]); - nextisport = 0; - continue; - } - - if (next) { - *next = argv[i]; - if (*next == NULL) { - dropbear_exit("Invalid null argument"); - } - next = 0x00; + if (argv[i][0] != '-' || argv[i][1] == '\0') + dropbear_exit("Invalid argument: %s", argv[i]); - if (keyfile) { - addhostkey(keyfile); - keyfile = NULL; - } - continue; - } - - if (argv[i][0] == '-') { - char c = argv[i][1]; - if (strlen(argv[i]) != 2) { - /* We only handle one flag per hyphen */ - fprintf(stderr, "Warning, trailing '%s' of '%s' is ignored.\n", - &argv[i][2], argv[i]); - } + for (j = 1; (c = argv[i][j]) != '\0' && !next && !nextisport; j++) { switch (c) { case 'b': next = &svr_opts.bannerfile; @@ -284,12 +262,39 @@ exit(EXIT_SUCCESS); break; default: - fprintf(stderr, "Unknown argument %s\n", argv[i]); + fprintf(stderr, "Invalid option -%c\n", c); printhelp(argv[0]); exit(EXIT_FAILURE); break; } } + + if (!next && !nextisport) + continue; + + if (c == '\0') { + i++; + j = 0; + if (!argv[i]) { + dropbear_exit("Missing argument"); + } + } + + if (nextisport) { + addportandaddress(&argv[i][j]); + nextisport = 0; + } else if (next) { + *next = &argv[i][j]; + if (*next == NULL) { + dropbear_exit("Invalid null argument"); + } + next = 0x00; + + if (keyfile) { + addhostkey(keyfile); + keyfile = NULL; + } + } } /* Set up listening ports */