Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit92d4fc3

Browse files
authored
Re-factored the code for supporting RFC 5987. (microsoft#41)
Re-wrote the logic to detect duplication `filename` and `filename*` attributes in Content-Disposition headers.Checking out the Appveyor build.
1 parentc505ca2 commit92d4fc3

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

‎apache2/msc_multipart.c‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include"modsecurity.h"
1616
#include<ctype.h>
1717
#include<sys/stat.h>
18+
#include<stdint.h>
1819

1920
#include"msc_multipart.h"
2021
#include"msc_util.h"
@@ -94,7 +95,8 @@ static int multipart_parse_content_disposition(modsec_rec *msr, char *c_d_value)
9495
if (*p!=';')return-2;
9596
p++;
9697

97-
intfilenamePresent=0;
98+
uint8_tfilename_present= FALSE;
99+
uint8_tfilename_ext_present= FALSE;
98100

99101
/* parse the appended parts */
100102
while(*p!='\0') {
@@ -206,7 +208,17 @@ static int multipart_parse_content_disposition(modsec_rec *msr, char *c_d_value)
206208

207209
if (strcmp(name,"filename*")==0)
208210
{
209-
// Make sure to turn of INVALID quoting since RFC 5987 expects quotes in the filename format.
211+
// We allow only one instance of `filename*` attribute to be present in the Content-Disposition header.
212+
if (filename_ext_present)
213+
{
214+
msr_log(msr,4,"Multipart: Warning: Duplicate Content-Disposition filename*: %s",
215+
log_escape_nq(msr->mp,decoded_filename));
216+
return-17;
217+
}
218+
219+
filename_ext_present= TRUE;
220+
221+
// Make sure to turn of INVALID quoting since RFC 5987 expects quotes in the filename format.
210222
msr->mpd->flag_invalid_quoting=0;
211223

212224
decoded_filename=rfc5987_decode(msr->mp,value);
@@ -218,34 +230,27 @@ static int multipart_parse_content_disposition(modsec_rec *msr, char *c_d_value)
218230
}
219231
msr->multipart_filename=decoded_filename;
220232

221-
222-
if (msr->mpd->mpp->filenameext!=NULL) {
223-
msr_log(msr,4,"Multipart: Warning: Duplicate Content-Disposition filename*: %s",
224-
log_escape_nq(msr->mp,decoded_filename));
225-
return-17;
226-
}
227-
228-
msr->mpd->mpp->filenameext=apr_pstrdup(msr->mp,decoded_filename);
229-
230233
// The `filename*` RCF 5987 encoded filename always overrides the `filename` parameter in content-disposition header.
231-
msr->mpd->mpp->filename=msr->mpd->mpp->filenameext;
234+
msr->mpd->mpp->filename=apr_pstrdup(msr->mp,decoded_filename);
232235

233236
// Re-run the validation check on the filename. We shouldn't be seeing quotes in the UTF-8 formatted filename either.
234237
validate_quotes(msr,msr->mpd->mpp->filename);
235238
}
236239
else
237240
{
238-
// Process the `filename` attribute in the content-disposition header only if `filename*` does not exist.
239-
filenamePresent++;
240-
if (filenamePresent>1)
241+
// We allow only one instance of `filename` attribute to be present in the Content-Disposition header.
242+
if (filename_present)
241243
{
242244
// Duplicate `filename` attributes are not allowed.
243245
msr_log(msr,4,"Multipart: Warning: Duplicate Content-Disposition filename: %s",
244246
log_escape_nq(msr->mp,decoded_filename));
245247
return-15;
246248
}
247249

248-
if (msr->mpd->mpp->filenameext==NULL)
250+
filename_present= TRUE;
251+
252+
// Process the `filename` attribute in the content-disposition header only if `filename*` does not exist.
253+
if (!filename_ext_present)
249254
{
250255
// "name == 'filename'"
251256
decoded_filename=value;

‎apache2/msc_multipart.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ struct multipart_part {
5353
/* files only, filename as supplied by the browser */
5454
char*filename;
5555

56-
/* files only, filename as supplied by the browser in RFC 5987 format */
57-
char*filenameext;
58-
5956
char*last_header_name;
6057
apr_table_t*headers;
6158

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp