Do value checking in parser

This commit is contained in:
akp 2023-10-06 23:01:09 +01:00
parent 4563b208a6
commit 91b17efc5c
No known key found for this signature in database
GPG key ID: CF8D58F3DEB20755

View file

@ -43,8 +43,6 @@ char* parse_ip(char* startptr, struct IP* ip) {
char* parse_rule(char line[], struct Rule* result) {
enum ParseState state = ParseState_ip1;
// TODO: check for invalid IP and port ranges where the second IP/port is smaller than the first.
result->ip.end = NULL;
result->port.end = NULL;
@ -121,6 +119,18 @@ char* parse_rule(char line[], struct Rule* result) {
break;
}
}
if (result->ip.end != NULL) {
if (compare_ip(&result->ip.start, result->ip.end) == 1) {
goto fail;
}
}
if (result->port.end != NULL) {
if (akpa_numcmp(result->port.start, *result->port.end) == 1) {
goto fail;
}
}
return line + ptr;