aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Engelhardt <[email protected]>2019-10-04 20:51:05 +0000
committerJan Engelhardt <[email protected]>2019-10-05 09:31:51 +0000
commitdf32418df5af976566e6eecb2777ccab7eadf5b3 (patch)
tree140cafe67e9d5d332d557f11e7a56c854c54c440 /src
parentReduce indent by 3 levels in findNextBoundary (diff)
downloadvmime-df32418df5af976566e6eecb2777ccab7eadf5b3.tar.gz
vmime-df32418df5af976566e6eecb2777ccab7eadf5b3.zip
Disregard whitespace between leading boundary hyphens and marker
The way I read the RFC is that whitespace is not allowed before the boundary marker, only afterwards, so the checks for leading WS are removed, and the missing check for trailing WS is added. See RFC 2046 ยง5.1.1: """The boundary delimiter line is then defined as a line consisting entirely of two hyphen characters ("-", decimal value 45) followed by the boundary parameter value from the Content-Type header field, optional linear whitespace, and a terminating CRLF."""
Diffstat (limited to 'src')
-rw-r--r--src/vmime/body.cpp35
1 files changed, 8 insertions, 27 deletions
diff --git a/src/vmime/body.cpp b/src/vmime/body.cpp
index b7f491a1..4103f328 100644
--- a/src/vmime/body.cpp
+++ b/src/vmime/body.cpp
@@ -78,30 +78,12 @@ size_t body::findNextBoundaryPosition(
continue;
}
- // Skip transport padding bytes (SPACE or HTAB), if any
- size_t advance = 0;
-
- while (pos != 0) {
-
- parser->seek(pos - advance - 1);
-
- const byte_t c = parser->peekByte();
-
- if (c == ' ' || c == '\t') {
- ++advance;
- } else {
- break;
- }
- }
-
// Ensure the bytes before boundary are "[LF]--": boundary should be
// at the beginning of a line, and should start with "--"
- if (pos - advance < 3) {
+ if (pos < 3) {
continue;
}
-
- parser->seek(pos - advance - 3);
-
+ parser->seek(pos - 3);
if (!parser->matchBytes("\n--", 3)) {
continue;
}
@@ -111,21 +93,20 @@ size_t body::findNextBoundaryPosition(
const byte_t next = parser->peekByte();
// Boundary should be followed by a new line or a dash
- if (next != '\r' && next != '\n' && next != '-') {
+ if (!isspace(next) && next != '-') {
continue;
}
// Get rid of the "[CR]" just before "[LF]--", if any
- if (pos - advance >= 4) {
-
- parser->seek(pos - advance - 4);
-
+ size_t backwards = 0;
+ if (pos >= 4) {
+ parser->seek(pos - 4);
if (parser->peekByte() == '\r') {
- advance++;
+ ++backwards;
}
}
- *boundaryStart = pos - advance - 3;
+ *boundaryStart = pos - backwards - 3;
*boundaryEnd = pos + boundary.length();
return pos;