Skip to content

Commit 86f4b3a

Browse files
committed
fix: use size_t type for len related vars
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
1 parent 2fe3832 commit 86f4b3a

9 files changed

Lines changed: 35 additions & 28 deletions

File tree

apache2/apache2_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static void internal_log_ex(request_rec *r, directory_config *dcfg, modsec_rec *
238238
/* Construct the message. */
239239
apr_vsnprintf(str1, sizeof(str1), text, ap);
240240
if (fixup) {
241-
int len = strlen(str1);
241+
size_t len = strlen(str1);
242242

243243
/* Strip line ending. */
244244
if (len && str1[len - 1] == '\n') {

apache2/msc_crypt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ int do_hash_method(modsec_rec *msr, char *link, int type) {
700700
int hash_response_body_links(modsec_rec *msr) {
701701
int lsize = 0, fsize = 0, lcount = 0, fcount = 0, i;
702702
int isize = 0, icount = 0, frsize = 0, frcount = 0;
703-
int bytes = 0;
703+
size_t bytes = 0;
704704
xmlXPathContextPtr xpathCtx = NULL;
705705
xmlXPathObjectPtr xpathObj = NULL;
706706
xmlChar *content_option = NULL;

apache2/msc_logging.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ static void sanitize_request_line(modsec_rec *msr) {
300300
if (strcmp(arg->origin, "QUERY_STRING") == 0) {
301301
char *pat = NULL;
302302
char *p;
303-
int j, arg_min, arg_max;
303+
size_t j;
304+
int arg_min, arg_max;
304305

305306
/* Go to the beginning of the parameter. */
306307
p = qspos;
@@ -333,7 +334,7 @@ static void sanitize_request_line(modsec_rec *msr) {
333334
arg_max = 1;
334335
while((*pat != '\0')&&(j--)) {
335336
if(arg_max > mparm->pad_2) {
336-
int off = (strlen(mparm->value) - arg_max);
337+
size_t off = (strlen(mparm->value) - arg_max);
337338
int pos = (mparm->pad_1-1);
338339
if(off > pos) {
339340
*pat = '*';
@@ -668,7 +669,8 @@ void sec_audit_logger_json(modsec_rec *msr) {
668669
int wrote_response_body = 0;
669670
char *entry_filename, *entry_basename;
670671
apr_status_t rc;
671-
int i, limit, k, sanitized_partial, j;
672+
int i, limit, k, sanitized_partial;
673+
size_t j;
672674
char *buf = NULL, *pat = NULL;
673675
msc_parm *mparm = NULL;
674676
int arg_min, arg_max, sanitize_matched;
@@ -827,7 +829,7 @@ void sec_audit_logger_json(modsec_rec *msr) {
827829
arg_max = 1;
828830
while((*pat != '\0')&&(j--)) {
829831
if(arg_max > mparm->pad_2) {
830-
int off = strlen(mparm->value) - arg_max;
832+
size_t off = strlen(mparm->value) - arg_max;
831833
int pos = mparm->pad_1-1;
832834
if(off > pos) {
833835
*pat = '*';
@@ -1084,7 +1086,7 @@ void sec_audit_logger_json(modsec_rec *msr) {
10841086
arg_max = 1;
10851087
while((*pat != '\0')&&(j--)) {
10861088
if(arg_max > mparm->pad_2) {
1087-
int off = strlen(mparm->value) - arg_max;
1089+
size_t off = strlen(mparm->value) - arg_max;
10881090
int pos = mparm->pad_1-1;
10891091
if(off > pos) {
10901092
*pat = '*';
@@ -1547,7 +1549,8 @@ void sec_audit_logger_native(modsec_rec *msr) {
15471549
int wrote_response_body = 0;
15481550
char *entry_filename, *entry_basename;
15491551
apr_status_t rc;
1550-
int i, limit, k, sanitized_partial, j;
1552+
int i, limit, k, sanitized_partial;
1553+
size_t j;
15511554
char *buf = NULL, *pat = NULL;
15521555
msc_parm *mparm = NULL;
15531556
int arg_min, arg_max, sanitize_matched;
@@ -1683,7 +1686,7 @@ void sec_audit_logger_native(modsec_rec *msr) {
16831686
arg_max = 1;
16841687
while((*pat != '\0')&&(j--)) {
16851688
if(arg_max > mparm->pad_2) {
1686-
int off = strlen(mparm->value) - arg_max;
1689+
size_t off = strlen(mparm->value) - arg_max;
16871690
int pos = mparm->pad_1-1;
16881691
if(off > pos) {
16891692
*pat = '*';
@@ -1931,7 +1934,7 @@ void sec_audit_logger_native(modsec_rec *msr) {
19311934
arg_max = 1;
19321935
while((*pat != '\0')&&(j--)) {
19331936
if(arg_max > mparm->pad_2) {
1934-
int off = strlen(mparm->value) - arg_max;
1937+
size_t off = strlen(mparm->value) - arg_max;
19351938
int pos = mparm->pad_1-1;
19361939
if(off > pos) {
19371940
*pat = '*';

apache2/msc_multipart.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222

2323
void validate_quotes(modsec_rec *msr, char *data, char quote) {
2424
assert(msr != NULL);
25-
int i, len;
25+
int i;
26+
size_t len;
2627

2728
if(msr->mpd == NULL)
2829
return;
@@ -846,7 +847,7 @@ int multipart_init(modsec_rec *msr, char **error_msg) {
846847
char *p = NULL;
847848
char *b = NULL;
848849
int seen_semicolon = 0;
849-
int len = 0;
850+
size_t len = 0;
850851

851852
/* Check for extra characters before the boundary. */
852853
for (p = (char *)(msr->request_content_type + 19); p < msr->mpd->boundary; p++) {
@@ -1485,7 +1486,7 @@ int multipart_get_arguments(modsec_rec *msr, char *origin, apr_table_t *argument
14851486
char *multipart_reconstruct_urlencoded_body_sanitize(modsec_rec *msr) {
14861487
multipart_part **parts;
14871488
char *body;
1488-
unsigned int body_len;
1489+
size_t body_len;
14891490
int i;
14901491

14911492
if (msr->mpd == NULL) return NULL;

apache2/msc_status_engine.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@
5252
// Bese32 encode, based on:
5353
// https://code.google.com/p/google-authenticator/source/browse/libpam/base32.c
5454
int DSOLOCAL msc_status_engine_base32_encode(char *encoded,
55-
const char *data, int len) {
55+
const char *data, size_t len) {
5656
int buffer;
5757
int count = 0;
5858
char *result = encoded;
59-
int length = strlen(data);
59+
size_t length = strlen(data);
6060

6161
buffer = data[0];
6262

@@ -97,7 +97,7 @@ int DSOLOCAL msc_status_engine_base32_encode(char *encoded,
9797
}
9898

9999
int DSOLOCAL msc_status_engine_fill_with_dots(char *encoded_with_dots,
100-
const char *data, int len, int space)
100+
const char *data, size_t len, int space)
101101
{
102102
int i;
103103
int count = 0;

apache2/msc_util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ unsigned char is_netmask_v6(char *ip_strv6) {
274274
*
275275
* \retval string On Success
276276
*/
277-
char *parse_pm_content(const char *op_parm, unsigned short int op_len, msre_rule *rule, char **error_msg) {
277+
char *parse_pm_content(const char *op_parm, size_t op_len, msre_rule *rule, char **error_msg) {
278278
char *parm = NULL;
279279
char *content = NULL;
280280
unsigned short int offset = 0;
@@ -708,7 +708,7 @@ char *file_basename(apr_pool_t *mp, const char *filename) {
708708

709709
char *m_strcasestr(const char *haystack, const char *needle) {
710710
char aux, lower_aux;
711-
int length;
711+
size_t length;
712712

713713
if ((aux = *needle++) != 0) {
714714
aux = (char)tolower((unsigned char)aux);

apache2/msc_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int DSOLOCAL parse_boolean(const char *input);
6363

6464
char DSOLOCAL *remove_quotes(apr_pool_t *mptmp, const char *input, int input_len);
6565

66-
char DSOLOCAL *parse_pm_content(const char *op_parm, unsigned short int op_len, msre_rule *rule, char **error_msg);
66+
char DSOLOCAL *parse_pm_content(const char *op_parm, size_t op_len, msre_rule *rule, char **error_msg);
6767

6868
char DSOLOCAL *remove_escape(apr_pool_t *mptmp, const char *input, int input_len);
6969

apache2/re_operators.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ static int msre_op_rsub_param_init(msre_rule *rule, char **error_msg) {
387387
char *data = NULL;
388388
char delim;
389389
int ignore_case = 0;
390-
unsigned short int op_len = 0;
390+
size_t op_len = 0;
391391

392392
*error_msg = NULL;
393393

@@ -529,7 +529,8 @@ static int msre_op_rsub_execute(modsec_rec *msr, msre_rule *rule, msre_var *var,
529529
char *data_out = NULL;
530530
unsigned int size = 0;
531531
unsigned int maxsize=0;
532-
int output_body = 0, input_body = 0, sl;
532+
int output_body = 0, input_body = 0;
533+
size_t sl;
533534
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 0
534535
ap_regmatch_t pmatch[AP_MAX_REG_MATCH];
535536
#else
@@ -1315,7 +1316,7 @@ static int msre_op_pm_param_init(msre_rule *rule, char **error_msg) {
13151316
ACMP *p;
13161317
const char *phrase;
13171318
const char *next;
1318-
unsigned short int op_len;
1319+
size_t op_len;
13191320

13201321
if ((rule->op_param == NULL)||(strlen(rule->op_param) == 0)) {
13211322
*error_msg = apr_psprintf(rule->ruleset->mp, "Missing parameter for operator 'pm'.");
@@ -1794,15 +1795,16 @@ static int msre_op_gsbLookup_execute(modsec_rec *msr, msre_rule *rule, msre_var
17941795
int options = 0;
17951796
gsb_db *gsb = msr->txcfg->gsb;
17961797
const char *match = NULL;
1797-
unsigned int match_length;
1798-
unsigned int canon_length;
1798+
size_t match_length;
1799+
size_t canon_length;
17991800
int rv, i, ret, count_slash;
18001801
unsigned int j = 0;
18011802
unsigned int size = var->value_len;
18021803
char *base = NULL, *domain = NULL, *savedptr = NULL;
18031804
char *str = NULL, *canon = NULL, *dot = NULL;
18041805
char *data = NULL, *ptr = NULL, *url = NULL;
1805-
int capture, domain_len;
1806+
int capture;
1807+
size_t domain_len;
18061808
int d_pos = -1;
18071809
int s_pos = -1;
18081810

@@ -2672,7 +2674,7 @@ static int msre_op_strmatch_param_init(msre_rule *rule, char **error_msg) {
26722674
const apr_strmatch_pattern *compiled_pattern;
26732675
char *processed = NULL;
26742676
const char *pattern = rule->op_param;
2675-
unsigned short int op_len;
2677+
size_t op_len;
26762678

26772679
*error_msg = NULL;
26782680

@@ -4166,7 +4168,8 @@ static int msre_op_fuzzy_hash_init(msre_rule *rule, char **error_msg)
41664168
struct fuzzy_hash_chunk *chunk, *t;
41674169
FILE *fp;
41684170
char *file;
4169-
int param_len,threshold;
4171+
size_t param_len;
4172+
int threshold;
41704173
char line[1024];
41714174

41724175
char *data = NULL;

apache2/re_variables.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2484,7 +2484,7 @@ static int var_full_request_generate(modsec_rec *msr, msre_var *var,
24842484
char *full_request = NULL;
24852485
int full_request_length = 0;
24862486
int headers_length = 0;
2487-
int request_line_length = 0;
2487+
size_t request_line_length = 0;
24882488

24892489
arr = apr_table_elts(msr->request_headers);
24902490
headers_length = msc_headers_to_buffer(arr, NULL, 0);

0 commit comments

Comments
 (0)