From: Alan T. DeKok Date: Tue, 3 Jul 2018 17:28:08 +0000 (-0400) Subject: move vararg check to before check for valid name X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=beb2610e3de73845bdd529b1e86eb4aeec2b4e9d;p=thirdparty%2Ffreeradius-server.git move vararg check to before check for valid name --- diff --git a/src/main/command.c b/src/main/command.c index f3671304c0c..7efadc650d4 100644 --- a/src/main/command.c +++ b/src/main/command.c @@ -53,6 +53,14 @@ struct fr_cmd_t { }; +/* + * Hacks for simplicity. These data types aren't allowed as + * parameters, so we can re-use them for something else. + */ +//#define FR_TYPE_ALTERNATE FR_TYPE_GROUP +//#define FR_TYPE_OPTIONAL FR_TYPE_ABINARY + + /** Find a command * * @param head the head of the list @@ -276,42 +284,46 @@ int fr_command_add(TALLOC_CTX *talloc_ctx, fr_cmd_t **head, char const *name, vo bool lowercase = false; bool uppercase = false; - if (!fr_command_valid_name(argv[i])) { - return -1; - } - - for (p = argv[i]; *p != '\0'; p++) { - if (isupper((int) *p)) uppercase = true; - if (islower((int) *p)) lowercase = true; - } - /* - * No alphabetical characters, that's a - * problem, except for varargs. + * Check for varargs. Which MUST NOT be + * the first argument, and MUST be the + * last argument, and MUST be preceded by + * a known data type. */ - if (!uppercase && !lowercase) { - if (strcmp(argv[i], "...") != 0) { + if (strcmp(argv[i], "...") == 0) { + if ((i == 0) || (i != (argc - 1))) { invalid: fr_strerror_printf("Syntax command %d does not contain alphabetical characters", i); return -1; } - /* - * Varargs MUST NOT be the first - * one, and MUST be the last one - * in the list. - */ - if ((i == 0) || (i != (argc - 1))) goto invalid; - /* * The thing BEFORE the varags - * MUST be a data type. + * MUST be a known data type. */ if (types[i - 1] == FR_TYPE_INVALID) goto invalid; varargs = true; + break; + } + + if (!fr_command_valid_name(argv[i])) { + return -1; + } + + types[i] = FR_TYPE_INVALID; + + for (p = argv[i]; *p != '\0'; p++) { + if (isupper((int) *p)) uppercase = true; + if (islower((int) *p)) lowercase = true; } + /* + * No alphabetical characters, that's a + * problem. + */ + if (!uppercase && !lowercase) goto invalid; + /* * Mixed case is not allowed in a syntax. */ @@ -341,8 +353,6 @@ int fr_command_add(TALLOC_CTX *talloc_ctx, fr_cmd_t **head, char const *name, vo } types[i] = type; - } else { - types[i] = FR_TYPE_INVALID; } }