Skip to content

Commit da13845

Browse files
Fix header FSM in webserver, fix Windows uploads (#7805)
When a file upload ends in \r\n (i.e. a Windows formatted text file) the sequence of bytes on the wire is `\r\n\r\n----...boundary-marker...`. When the FSM in Webserver was evaluating the stream, that 2nd `\r` would be written as valid data and the FSM parser would be reset and see `\n` as the 1st character, which wouldn't match. This would a) add an extra `\r` to uploaded files, and b) cause uploads to hang. Fix by checking on a header FSM mismatch if the next character input could possibly match our marker, and if so handle it properly. Fixes #7803
1 parent 5b42e73 commit da13845

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

libraries/ESP8266WebServer/src/Parsing-impl.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,14 @@ bool ESP8266WebServerTemplate<ServerType>::_parseForm(ClientType& client, const
467467
for (int i = 0; i < boundaryPtr; i++) {
468468
_uploadWriteByte( fastBoundary[ i ] );
469469
}
470-
_uploadWriteByte( in );
471-
boundaryPtr = 0;
470+
if (in == fastBoundary[ 0 ]) {
471+
// This could be the start of the real end, mark it so and don't emit/skip it
472+
boundaryPtr = 1;
473+
} else {
474+
// Not the 1st char of our pattern, so emit and ignore
475+
_uploadWriteByte( in );
476+
boundaryPtr = 0;
477+
}
472478
}
473479
}
474480
// Found the boundary string, finish processing this file upload

0 commit comments

Comments
 (0)