Fix urilen keyword pcre_get_substring issue.

remotes/origin/master-1.1.x
Victor Julien 14 years ago
parent f52b54f63e
commit 1740c3a7c7

@ -42,7 +42,7 @@
/** /**
* \brief Regex for parsing our urilen * \brief Regex for parsing our urilen
*/ */
#define PARSE_REGEX "^\\s*(<|>)?\\s*([0-9]{1,5})\\s*(?:(<>)\\s*([0-9]{1,5}))?\\s*$" #define PARSE_REGEX "^(?:\\s*)(<|>)?(?:\\s*)([0-9]{1,5})(?:\\s*)(?:(<>)(?:\\s*)([0-9]{1,5}))?(?:\\s*)$"
static pcre *parse_regex; static pcre *parse_regex;
static pcre_extra *parse_regex_study; static pcre_extra *parse_regex_study;
@ -183,6 +183,8 @@ DetectUrilenData *DetectUrilenParse (char *urilenstr)
} }
const char *str_ptr; const char *str_ptr;
SCLogDebug("ret %d", ret);
res = pcre_get_substring((char *)urilenstr, ov, MAX_SUBSTRINGS, 1, &str_ptr); res = pcre_get_substring((char *)urilenstr, ov, MAX_SUBSTRINGS, 1, &str_ptr);
if (res < 0) { if (res < 0) {
SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed"); SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
@ -199,6 +201,7 @@ DetectUrilenData *DetectUrilenParse (char *urilenstr)
arg2 = (char *) str_ptr; arg2 = (char *) str_ptr;
SCLogDebug("Arg2 \"%s\"", arg2); SCLogDebug("Arg2 \"%s\"", arg2);
if (ret > 3) {
res = pcre_get_substring((char *)urilenstr, ov, MAX_SUBSTRINGS, 3, &str_ptr); res = pcre_get_substring((char *)urilenstr, ov, MAX_SUBSTRINGS, 3, &str_ptr);
if (res < 0) { if (res < 0) {
SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed"); SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
@ -207,6 +210,7 @@ DetectUrilenData *DetectUrilenParse (char *urilenstr)
arg3 = (char *) str_ptr; arg3 = (char *) str_ptr;
SCLogDebug("Arg3 \"%s\"", arg3); SCLogDebug("Arg3 \"%s\"", arg3);
if (ret > 4) {
res = pcre_get_substring((char *)urilenstr, ov, MAX_SUBSTRINGS, 4, &str_ptr); res = pcre_get_substring((char *)urilenstr, ov, MAX_SUBSTRINGS, 4, &str_ptr);
if (res < 0) { if (res < 0) {
SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed"); SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
@ -214,6 +218,8 @@ DetectUrilenData *DetectUrilenParse (char *urilenstr)
} }
arg4 = (char *) str_ptr; arg4 = (char *) str_ptr;
SCLogDebug("Arg4 \"%s\"", arg4); SCLogDebug("Arg4 \"%s\"", arg4);
}
}
urilend = SCMalloc(sizeof (DetectUrilenData)); urilend = SCMalloc(sizeof (DetectUrilenData));
if (urilend == NULL) if (urilend == NULL)
@ -221,11 +227,14 @@ DetectUrilenData *DetectUrilenParse (char *urilenstr)
urilend->urilen1 = 0; urilend->urilen1 = 0;
urilend->urilen2 = 0; urilend->urilen2 = 0;
if (arg1[0] == '<') urilend->mode = DETECT_URILEN_LT; if (arg1[0] == '<')
else if (arg1[0] == '>') urilend->mode = DETECT_URILEN_GT; urilend->mode = DETECT_URILEN_LT;
else urilend->mode = DETECT_URILEN_EQ; else if (arg1[0] == '>')
urilend->mode = DETECT_URILEN_GT;
else
urilend->mode = DETECT_URILEN_EQ;
if (strcmp("<>", arg3) == 0) { if (arg3 != NULL && strcmp("<>", arg3) == 0) {
if (strlen(arg1) != 0) { if (strlen(arg1) != 0) {
SCLogError(SC_ERR_INVALID_ARGUMENT,"Range specified but mode also set"); SCLogError(SC_ERR_INVALID_ARGUMENT,"Range specified but mode also set");
goto error; goto error;
@ -240,7 +249,7 @@ DetectUrilenData *DetectUrilenParse (char *urilenstr)
} }
/** set the second urilen value if specified */ /** set the second urilen value if specified */
if (strlen(arg4) > 0) { if (arg4 != NULL && strlen(arg4) > 0) {
if (urilend->mode != DETECT_URILEN_RA) { if (urilend->mode != DETECT_URILEN_RA) {
SCLogError(SC_ERR_INVALID_ARGUMENT,"Multiple urilen values specified" SCLogError(SC_ERR_INVALID_ARGUMENT,"Multiple urilen values specified"
" but mode is not range"); " but mode is not range");
@ -260,18 +269,27 @@ DetectUrilenData *DetectUrilenParse (char *urilenstr)
} }
} }
if (arg1 != NULL)
SCFree(arg1); SCFree(arg1);
if (arg2 != NULL)
SCFree(arg2); SCFree(arg2);
if (arg3 != NULL)
SCFree(arg3); SCFree(arg3);
if (arg4 != NULL)
SCFree(arg4); SCFree(arg4);
return urilend; return urilend;
error: error:
if (urilend) SCFree(urilend); if (urilend)
if (arg1) SCFree(arg1); SCFree(urilend);
if (arg2) SCFree(arg2); if (arg1 != NULL)
if (arg3) SCFree(arg3); SCFree(arg1);
if (arg4) SCFree(arg4); if (arg2 != NULL)
SCFree(arg2);
if (arg3 != NULL)
SCFree(arg3);
if (arg4 != NULL)
SCFree(arg4);
return NULL; return NULL;
} }

Loading…
Cancel
Save