]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move vararg check to before check for valid name
authorAlan T. DeKok <aland@freeradius.org>
Tue, 3 Jul 2018 17:28:08 +0000 (13:28 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 3 Jul 2018 18:54:27 +0000 (14:54 -0400)
src/main/command.c

index f3671304c0ce88e2be9283a277bab211a673b387..7efadc650d49021638ee4e17db32d366b0effae5 100644 (file)
@@ -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;
                        }
                }