|
|
|
|
@ -842,8 +842,7 @@ static int DetectPortParseInsertString(DetectPort **head, char *s) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* handle the not case, we apply the negation
|
|
|
|
|
* then insert the part(s) */
|
|
|
|
|
/* handle the not case, we apply the negation then insert the part(s) */
|
|
|
|
|
if (ad->flags & PORT_FLAG_NOT) {
|
|
|
|
|
DetectPort *ad2 = NULL;
|
|
|
|
|
|
|
|
|
|
@ -851,15 +850,15 @@ static int DetectPortParseInsertString(DetectPort **head, char *s) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* normally a 'not' will result in two ad's
|
|
|
|
|
* unless the 'not' is on the start or end
|
|
|
|
|
* of the address space (e.g. 0.0.0.0 or
|
|
|
|
|
* 255.255.255.255). */
|
|
|
|
|
/* normally a 'not' will result in two ad's unless the 'not' is on the
|
|
|
|
|
* start or end of the address space(e.g. 0.0.0.0 or 255.255.255.255) */
|
|
|
|
|
if (ad2 != NULL) {
|
|
|
|
|
if (DetectPortParseInsert(head, ad2) < 0)
|
|
|
|
|
if (DetectPortParseInsert(head, ad2) < 0) {
|
|
|
|
|
if (ad2 != NULL) free(ad2);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r = DetectPortParseInsert(head, ad);
|
|
|
|
|
if (r < 0)
|
|
|
|
|
@ -879,12 +878,13 @@ static int DetectPortParseInsertString(DetectPort **head, char *s) {
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
printf("DetectPortParseInsertString error\n");
|
|
|
|
|
/* XXX cleanup */
|
|
|
|
|
if (ad != NULL) free(ad);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* XXX error handling */
|
|
|
|
|
static int DetectPortParseDo(DetectPort **head, DetectPort **nhead, char *s,int negate) {
|
|
|
|
|
static int DetectPortParseDo(DetectPort **head, DetectPort **nhead, char *s,
|
|
|
|
|
int negate) {
|
|
|
|
|
int i, x;
|
|
|
|
|
int o_set = 0, n_set = 0;
|
|
|
|
|
int range = 0;
|
|
|
|
|
@ -898,9 +898,8 @@ static int DetectPortParseDo(DetectPort **head, DetectPort **nhead, char *s,int
|
|
|
|
|
address[x] = s[i];
|
|
|
|
|
x++;
|
|
|
|
|
|
|
|
|
|
if (s[i] == ':') {
|
|
|
|
|
if (s[i] == ':')
|
|
|
|
|
range = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (range == 1 && s[i] == '!') {
|
|
|
|
|
printf("Can't have a negated value in a range.\n");
|
|
|
|
|
@ -917,7 +916,7 @@ static int DetectPortParseDo(DetectPort **head, DetectPort **nhead, char *s,int
|
|
|
|
|
} else if (s[i] == ']') {
|
|
|
|
|
if (depth == 1) {
|
|
|
|
|
address[x - 1] = '\0';
|
|
|
|
|
SCLogDebug("%s", address);
|
|
|
|
|
SCLogDebug("Parsed port from DetectPortParseDo - %s", address);
|
|
|
|
|
x = 0;
|
|
|
|
|
|
|
|
|
|
DetectPortParseDo(head, nhead, address, negate? negate: n_set);
|
|
|
|
|
@ -930,7 +929,7 @@ static int DetectPortParseDo(DetectPort **head, DetectPort **nhead, char *s,int
|
|
|
|
|
o_set = 0;
|
|
|
|
|
} else {
|
|
|
|
|
address[x - 1] = '\0';
|
|
|
|
|
SCLogDebug("%s", address);
|
|
|
|
|
SCLogDebug("Parsed port from DetectPortParseDo - %s", address);
|
|
|
|
|
|
|
|
|
|
if (negate == 0 && n_set == 0) {
|
|
|
|
|
DetectPortParseInsertString(head, address);
|
|
|
|
|
@ -1084,26 +1083,25 @@ error:
|
|
|
|
|
int DetectPortParse(DetectPort **head, char *str) {
|
|
|
|
|
int r;
|
|
|
|
|
|
|
|
|
|
SCLogDebug("str %s", str);
|
|
|
|
|
SCLogDebug("Port string to be parsed - str %s", str);
|
|
|
|
|
|
|
|
|
|
/* negate port list */
|
|
|
|
|
DetectPort *nhead = NULL;
|
|
|
|
|
|
|
|
|
|
r = DetectPortParseDo(head, &nhead, str,/* start with negate no */0);
|
|
|
|
|
if (r < 0) {
|
|
|
|
|
if (r < 0)
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCLogDebug("head %p %p, nhead %p", head, *head, nhead);
|
|
|
|
|
|
|
|
|
|
/* merge the 'not' address groups */
|
|
|
|
|
if (DetectPortParseMergeNotPorts(head,&nhead) < 0) {
|
|
|
|
|
if (DetectPortParseMergeNotPorts(head, &nhead) < 0)
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* free the temp negate head */
|
|
|
|
|
DetectPortFree(nhead);
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
DetectPortFree(nhead);
|
|
|
|
|
return -1;
|
|
|
|
|
@ -1131,7 +1129,7 @@ DetectPort *PortParse(char *str) {
|
|
|
|
|
/* see if the address is an ipv4 or ipv6 address */
|
|
|
|
|
if ((port2 = strchr(port, ':')) != NULL) {
|
|
|
|
|
/* 80:81 range format */
|
|
|
|
|
port[port2 - port] = '\0';
|
|
|
|
|
port2[0] = '\0';
|
|
|
|
|
port2++;
|
|
|
|
|
|
|
|
|
|
if(DetectPortIsValidRange(port))
|
|
|
|
|
@ -1148,10 +1146,9 @@ DetectPort *PortParse(char *str) {
|
|
|
|
|
dp->port2 = 65535;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* a>b is illegal, a=b is ok */
|
|
|
|
|
/* a > b is illegal, a == b is ok */
|
|
|
|
|
if (dp->port > dp->port2)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
if (strcasecmp(port,"any") == 0) {
|
|
|
|
|
dp->port = 0;
|
|
|
|
|
|