From 897a049513a2aa3a7629d980726b152f04c20447 Mon Sep 17 00:00:00 2001 From: aland Date: Thu, 9 Sep 2004 14:25:58 +0000 Subject: [PATCH] Define a macro for max regex matches, so we don't have typos. Bug found by "Mitchell, Michael" --- src/include/radiusd.h | 1 + src/main/valuepair.c | 5 +++-- src/main/xlat.c | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/include/radiusd.h b/src/include/radiusd.h index 9865730..7a361d9 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -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 diff --git a/src/main/valuepair.c b/src/main/valuepair.c index e20f4d0..b73fb77 100644 --- a/src/main/valuepair.c +++ b/src/main/valuepair.c @@ -371,13 +371,14 @@ int paircmp(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check, VALUE_PAIR **r REG_EXTENDED); compare = regexec(®, (char *)auth_item->strvalue, - 16, rxmatch, 0); + REQUEST_MAX_REGEX + 1, + rxmatch, 0); regfree(®); /* * 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)]; diff --git a/src/main/xlat.c b/src/main/xlat.c index e1127a8..3ad808a 100644 --- a/src/main/xlat.c +++ b/src/main/xlat.c @@ -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); -- 2.1.4