Skip to content

Commit 7f2013e

Browse files
committed
fix: remove unused argument and add validation
1 parent 6102d0d commit 7f2013e

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

fw/http_match.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ map_op_to_str_eq_flags(tfw_http_match_op_t op)
9191
}
9292

9393
bool
94-
tfw_match_regex(tfw_match_t op, const char *cstr, size_t len, const TfwStr *arg)
94+
tfw_match_regex(const char *cstr, const TfwStr *arg)
9595
{
9696
bool result;
9797
int r;
@@ -117,7 +117,7 @@ tfw_rule_str_match(const TfwStr *str, const char *cstr,
117117
cstr, cstr_len, flags);
118118

119119
if (op == TFW_HTTP_MATCH_O_REGEX)
120-
return tfw_match_regex(op, cstr, cstr_len, str);
120+
return tfw_match_regex(cstr, str);
121121

122122
return tfw_str_eq_cstr(str, cstr, cstr_len, flags);
123123
}
@@ -371,7 +371,7 @@ __cmp_hdr_raw_value(const TfwStr *chunk, const TfwStr *end, const TfwStr *hdr,
371371
rhdr.chunks += cnum;
372372
rhdr.nchunks -= cnum;
373373
rhdr.len -= name_len;
374-
return tfw_match_regex(rule->op, p_val, p_val_len, &rhdr);
374+
return tfw_match_regex(p_val, &rhdr);
375375
}
376376

377377
return __cmp_hdr_raw_value_str(chunk, end, p_val, p_val_len, flags,
@@ -830,8 +830,23 @@ write_regex(const char *arg)
830830
int len = strlen(arg);
831831
int len1;
832832

833-
if (len < sizeof(unsigned short)) {
834-
T_ERR_NL("String of regex too short\n");
833+
/*
834+
* Length of regexp string must be greater or equal to sizeof(number_of_regex)
835+
* because we use memory allocated for this string for storing id
836+
* of the regexp.
837+
*/
838+
if (len < sizeof(number_of_regex)) {
839+
T_ERR_NL("String of regex too short.\n");
840+
return -EINVAL;
841+
}
842+
843+
if (number_of_db_regex == USHRT_MAX) {
844+
T_ERR_NL("Maximum number of regular expression databases has been reached.\n");
845+
return -EINVAL;
846+
}
847+
848+
if (number_of_regex == USHRT_MAX) {
849+
T_ERR_NL("Maximum number of regular expressions has been reached.\n");
835850
return -EINVAL;
836851
}
837852

fw/http_match.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ int tfw_http_search_cookie(const char *cstr, unsigned long clen,
173173

174174
int write_regex(const char *arg);
175175

176-
bool tfw_match_regex(tfw_match_t op, const char *cstr, size_t len,
177-
const TfwStr *arg);
176+
bool tfw_match_regex(const char *cstr, const TfwStr *arg);
178177

179178
#define tfw_http_chain_rules_for_each(chain, func) \
180179
({ \

fw/vhost.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ extern int bpf_scan_bytes(const void *, __u32, struct rex_scan_attr *);
191191
static bool
192192
__tfw_match_regex(tfw_match_t op, const char *cstr, size_t len, TfwStr *arg)
193193
{
194-
return tfw_match_regex(op, cstr, len, arg);
194+
return tfw_match_regex(cstr, arg);
195195
}
196196

197197
typedef bool (*__tfw_match_fn)(tfw_match_t, const char *, size_t, TfwStr *);

0 commit comments

Comments
 (0)