mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Cleanup. MULTIPART_STRICT_ERROR now returns 1 on parsing error too.
This commit is contained in:
parent
323f9f81a0
commit
222f1f6f78
@ -569,7 +569,7 @@ int multipart_init(modsec_rec *msr, char **error_msg) {
|
||||
msr->mpd->flag_boundary_quoted = 1;
|
||||
|
||||
if (strstr(msr->mpd->boundary, "\"") != NULL) {
|
||||
*error_msg = apr_psprintf(msr->mp, "Invalid boundary (quote).");
|
||||
*error_msg = apr_psprintf(msr->mp, "Invalid boundary in C-T (quote).");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
@ -579,7 +579,7 @@ int multipart_init(modsec_rec *msr, char **error_msg) {
|
||||
if ( (*b == '"')
|
||||
|| ((len >= 2)&&(*(b + len - 1) == '"')) )
|
||||
{
|
||||
*error_msg = apr_psprintf(msr->mp, "Invalid boundary (quote).");
|
||||
*error_msg = apr_psprintf(msr->mp, "Invalid boundary in C-T (quote).");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -592,12 +592,12 @@ int multipart_init(modsec_rec *msr, char **error_msg) {
|
||||
log_escape_nq(msr->mp, msr->mpd->boundary));
|
||||
|
||||
if (strlen(msr->mpd->boundary) == 0) {
|
||||
*error_msg = apr_psprintf(msr->mp, "Multipart boundary empty.");
|
||||
*error_msg = apr_psprintf(msr->mp, "Multipart boundary in C-T empty.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*error_msg = apr_psprintf(msr->mp, "Multipart boundary not found or invalid.");
|
||||
*error_msg = apr_psprintf(msr->mp, "Multipart boundary in C-T not found or invalid.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -641,6 +641,7 @@ int multipart_process_chunk(modsec_rec *msr, const char *buf,
|
||||
}
|
||||
|
||||
if (msr->mpd->bufleft == 0) {
|
||||
msr->mpd->flag_error = 1;
|
||||
*error_msg = apr_psprintf(msr->mp,
|
||||
"Multipart: Internal error in process_chunk: no space left in the buffer");
|
||||
return -1;
|
||||
@ -689,6 +690,7 @@ int multipart_process_chunk(modsec_rec *msr, const char *buf,
|
||||
boundary_end += 2;
|
||||
|
||||
if (msr->mpd->is_complete != 0) {
|
||||
msr->mpd->flag_error = 1;
|
||||
*error_msg = apr_psprintf(msr->mp,
|
||||
"Multipart: Invalid boundary (final duplicate).");
|
||||
return -1;
|
||||
@ -707,6 +709,7 @@ int multipart_process_chunk(modsec_rec *msr, const char *buf,
|
||||
}
|
||||
|
||||
if (multipart_process_boundary(msr, (is_final ? 1 : 0), error_msg) < 0) {
|
||||
msr->mpd->flag_error = 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -718,6 +721,7 @@ int multipart_process_chunk(modsec_rec *msr, const char *buf,
|
||||
}
|
||||
else {
|
||||
/* error */
|
||||
msr->mpd->flag_error = 1;
|
||||
*error_msg = apr_psprintf(msr->mp,
|
||||
"Multipart: Invalid boundary: %s",
|
||||
log_escape_nq(msr->mp, msr->mpd->buf));
|
||||
@ -725,11 +729,12 @@ int multipart_process_chunk(modsec_rec *msr, const char *buf,
|
||||
}
|
||||
} else {
|
||||
if ( (msr->mpd->flag_boundary_quoted)
|
||||
&& (strlen(msr->mpd->buf) > strlen(msr->mpd->boundary) + 3)
|
||||
&& (strlen(msr->mpd->buf) >= strlen(msr->mpd->boundary) + 3)
|
||||
&& (((*(msr->mpd->buf) == '-'))&&(*(msr->mpd->buf + 1) == '-'))
|
||||
&& (*(msr->mpd->buf + 2) == '"')
|
||||
&& (strncmp(msr->mpd->buf + 3, msr->mpd->boundary, strlen(msr->mpd->boundary)) == 0)
|
||||
) {
|
||||
msr->mpd->flag_error = 1;
|
||||
*error_msg = apr_psprintf(msr->mp, "Multipart: Invalid boundary (quotes).");
|
||||
return -1;
|
||||
}
|
||||
@ -749,14 +754,22 @@ int multipart_process_chunk(modsec_rec *msr, const char *buf,
|
||||
/* part header lines must be shorter than
|
||||
* MULTIPART_BUF_SIZE bytes
|
||||
*/
|
||||
msr->mpd->flag_error = 1;
|
||||
*error_msg = apr_psprintf(msr->mp,
|
||||
"Multipart: Part header line over %i bytes long",
|
||||
MULTIPART_BUF_SIZE);
|
||||
return -1;
|
||||
}
|
||||
if (multipart_process_part_header(msr, error_msg) < 0) return -1;
|
||||
|
||||
if (multipart_process_part_header(msr, error_msg) < 0) {
|
||||
msr->mpd->flag_error = 1;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (multipart_process_part_data(msr, error_msg) < 0) return -1;
|
||||
if (multipart_process_part_data(msr, error_msg) < 0) {
|
||||
msr->mpd->flag_error = 1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +98,7 @@ struct multipart_data {
|
||||
int seen_data;
|
||||
int is_complete;
|
||||
|
||||
int flag_error;
|
||||
int flag_data_before;
|
||||
int flag_data_after;
|
||||
int flag_header_folding;
|
||||
|
@ -1295,7 +1295,8 @@ static int var_multipart_strict_error_generate(modsec_rec *msr, msre_var *var, m
|
||||
{
|
||||
if (msr->mpd != NULL) {
|
||||
/* Respond positive if at least one of the multipart flags is raised. */
|
||||
if ( (msr->mpd->flag_boundary_quoted != 0)
|
||||
if ( (msr->mpd->flag_error)
|
||||
||(msr->mpd->flag_boundary_quoted != 0)
|
||||
||(msr->mpd->flag_data_before != 0)
|
||||
||(msr->mpd->flag_data_after != 0)
|
||||
||(msr->mpd->flag_header_folding != 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user