Skip to content

Commit 7af8363

Browse files
allanrbovictorhora
authored andcommitted
Less strict multipart parsing
1 parent b600669 commit 7af8363

File tree

1 file changed

+20
-33
lines changed

1 file changed

+20
-33
lines changed

apache2/msc_multipart.c

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -695,42 +695,29 @@ static int multipart_boundary_characters_valid(char *boundary) {
695695

696696
if (p == NULL) return -1;
697697

698-
while((c = *p) != '\0') {
699-
/* Control characters and space not allowed. */
700-
if (c < 32) {
698+
while ((c = *p) != '\0') {
699+
// Check against allowed list defined in RFC2046 page 21
700+
if (!(
701+
('0' <= c && c <= '9')
702+
|| ('A' <= c && c <= 'Z')
703+
|| ('a' <= c && c <= 'z')
704+
|| (c == ' ' && *(p + 1) != '\0') // space allowed, but not as last character
705+
|| c == '\''
706+
|| c == '('
707+
|| c == ')'
708+
|| c == '+'
709+
|| c == '_'
710+
|| c == ','
711+
|| c == '-'
712+
|| c == '.'
713+
|| c == '/'
714+
|| c == ':'
715+
|| c == '='
716+
|| c == '?'
717+
)) {
701718
return 0;
702719
}
703720

704-
/* Non-ASCII characters not allowed. */
705-
if (c > 126) {
706-
return 0;
707-
}
708-
709-
switch(c) {
710-
/* Special characters not allowed. */
711-
case '(' :
712-
case ')' :
713-
case '<' :
714-
case '>' :
715-
case '@' :
716-
case ',' :
717-
case ';' :
718-
case ':' :
719-
case '\\' :
720-
case '"' :
721-
case '/' :
722-
case '[' :
723-
case ']' :
724-
case '?' :
725-
case '=' :
726-
return 0;
727-
break;
728-
729-
default :
730-
/* Do nothing. */
731-
break;
732-
}
733-
734721
p++;
735722
}
736723

0 commit comments

Comments
 (0)