-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: strlen related variables should be of type size_t #3503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v2/master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -300,7 +300,8 @@ static void sanitize_request_line(modsec_rec *msr) { | |||||||||||||
| if (strcmp(arg->origin, "QUERY_STRING") == 0) { | ||||||||||||||
| char *pat = NULL; | ||||||||||||||
| char *p; | ||||||||||||||
| int j, arg_min, arg_max; | ||||||||||||||
| size_t j; | ||||||||||||||
| int arg_min, arg_max; | ||||||||||||||
|
|
||||||||||||||
| /* Go to the beginning of the parameter. */ | ||||||||||||||
| p = qspos; | ||||||||||||||
|
|
@@ -333,7 +334,7 @@ static void sanitize_request_line(modsec_rec *msr) { | |||||||||||||
| arg_max = 1; | ||||||||||||||
| while((*pat != '\0')&&(j--)) { | ||||||||||||||
| if(arg_max > mparm->pad_2) { | ||||||||||||||
| int off = (strlen(mparm->value) - arg_max); | ||||||||||||||
| int off = (int)strlen(mparm->value) - arg_max; | ||||||||||||||
| int pos = (mparm->pad_1-1); | ||||||||||||||
| if(off > pos) { | ||||||||||||||
|
Comment on lines
336
to
339
|
||||||||||||||
| *pat = '*'; | ||||||||||||||
|
|
@@ -668,7 +669,8 @@ void sec_audit_logger_json(modsec_rec *msr) { | |||||||||||||
| int wrote_response_body = 0; | ||||||||||||||
| char *entry_filename, *entry_basename; | ||||||||||||||
| apr_status_t rc; | ||||||||||||||
| int i, limit, k, sanitized_partial, j; | ||||||||||||||
| int i, limit, k, sanitized_partial; | ||||||||||||||
| size_t j; | ||||||||||||||
| char *buf = NULL, *pat = NULL; | ||||||||||||||
| msc_parm *mparm = NULL; | ||||||||||||||
| int arg_min, arg_max, sanitize_matched; | ||||||||||||||
|
||||||||||||||
| int arg_min, arg_max, sanitize_matched; | |
| size_t arg_min, arg_max; | |
| int sanitize_matched; |
Copilot
AI
Apr 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as earlier in this file: int off = (int)strlen(mparm->value) - arg_max; performs potentially truncating arithmetic on strlen() results. Keeping off/arg_max/pos in a consistent unsigned (or signed) width avoids truncation and signed/unsigned comparison problems.
| int off = (int)strlen(mparm->value) - arg_max; | |
| int pos = mparm->pad_1-1; | |
| if(off > pos) { | |
| size_t off = strlen(mparm->value) - (size_t)arg_max; | |
| int pos = mparm->pad_1-1; | |
| if((pos < 0) || (off > (size_t)pos)) { |
Copilot
AI
Apr 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In sec_audit_logger_native, j is now size_t but arg_min/arg_max remain int and are assigned from strlen()-derived values. This can truncate and may still trigger signed/unsigned warnings on some toolchains. Consider updating these related counters/lengths to size_t for consistency.
| int arg_min, arg_max, sanitize_matched; | |
| size_t arg_min, arg_max; | |
| int sanitize_matched; |
Copilot
AI
Apr 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same truncation risk here: int off = (int)strlen(mparm->value) - arg_max;. Since strlen() returns size_t, doing the math in int can overflow/truncate and makes the code less portable. Prefer using size_t (or ptrdiff_t) for off and adjust comparisons accordingly.
| int off = (int)strlen(mparm->value) - arg_max; | |
| int pos = mparm->pad_1-1; | |
| if(off > pos) { | |
| size_t off = strlen(mparm->value) - (size_t)arg_max; | |
| int pos = mparm->pad_1-1; | |
| if ((pos < 0) || (off > (size_t)pos)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
sanitize_request_line,jis nowsize_tbutarg_min/arg_maxremainint. A few lines laterarg_min = j;assigns the result ofstrlen()(size_t) into anint, which can truncate on 64-bit and may reintroduce signed/unsigned warnings. Consider makingarg_min/arg_max(and related computations)size_t(or removingarg_minif it’s unused outside the loop).