Define a macro for max regex matches, so we don't have typos.
authoraland <aland>
Thu, 9 Sep 2004 14:25:58 +0000 (14:25 +0000)
committeraland <aland>
Thu, 9 Sep 2004 14:25:58 +0000 (14:25 +0000)
Bug found by "Mitchell, Michael"

src/include/radiusd.h
src/main/valuepair.c
src/main/xlat.c

index 9865730..7a361d9 100644 (file)
@@ -49,6 +49,7 @@ typedef pid_t child_pid_t;
 typedef struct request_data_t request_data_t;
 
 #define REQUEST_DATA_REGEX (0xadbeef00)
+#define REQUEST_MAX_REGEX (8)
 
 typedef struct auth_req {
 #ifndef NDEBUG
index e20f4d0..b73fb77 100644 (file)
@@ -371,13 +371,14 @@ int paircmp(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check, VALUE_PAIR **r
                                        REG_EXTENDED);
                                compare = regexec(&reg,
                                                  (char *)auth_item->strvalue,
-                                                 16, rxmatch, 0);
+                                                 REQUEST_MAX_REGEX + 1,
+                                                 rxmatch, 0);
                                regfree(&reg);
 
                                /*
                                 *      Add %{0}, %{1}, etc.
                                 */
-                               for (i = 0; i <= 8; i++) {
+                               for (i = 0; i <= REQUEST_MAX_REGEX; i++) {
                                        char *p;
                                        char buffer[sizeof(check_item->strvalue)];
 
index e1127a8..3ad808a 100644 (file)
@@ -56,6 +56,10 @@ static const char *internal_xlat[] = {"check",
                                      "proxy-request",
                                      "proxy-reply",
                                      NULL};
+
+#if REQUEST_MAX_REGEX > 8
+#error Please fix the following line
+#endif
 static int xlat_inst[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };        /* up to 8 for regex */
 
 
@@ -378,7 +382,7 @@ int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance)
                 *      Register xlat's for regexes.
                 */
                buffer[1] = '\0';
-               for (i = 0; i <= 8; i++) {
+               for (i = 0; i <= REQUEST_MAX_REGEX; i++) {
                        buffer[0] = '0' + i;
                        xlat_register(buffer, xlat_regex, &xlat_inst[i]);
                        c = xlat_find(buffer);