* Copyright (c) 2009-2014 Kazuho Oku, Tokuhiro Matsuno, Daisuke Murase,
* Shigeo Mitsunari
*
- * SPDX-License-Identifier: MIT
- *
* The software is licensed under either the MIT License (below) or the Perl
* license.
*
/* find non-printable char within the next 8 bytes, this is the hottest
* code; manually inlined */
while (likely(buf_end - buf >= 8)) {
-#define DOIT() \
- do { \
- if (unlikely(!IS_PRINTABLE_ASCII(*buf))) { \
- goto NonPrintable; \
- } \
- ++buf; \
+#define DOIT() \
+ do { \
+ if (unlikely(!IS_PRINTABLE_ASCII(*buf))) \
+ goto NonPrintable; \
+ ++buf; \
} while (0)
DOIT();
DOIT();
size_t *num_headers, size_t last_len) {
const char *buf = buf_start, *buf_end = buf_start + len;
size_t max_headers = *num_headers;
- int r = -1;
+ int r;
*method = NULL;
*method_len = 0;
enum {
CHUNKED_IN_CHUNK_SIZE,
CHUNKED_IN_CHUNK_EXT,
+ CHUNKED_IN_CHUNK_HEADER_EXPECT_LF,
CHUNKED_IN_CHUNK_DATA,
- CHUNKED_IN_CHUNK_CRLF,
+ CHUNKED_IN_CHUNK_DATA_EXPECT_CR,
+ CHUNKED_IN_CHUNK_DATA_EXPECT_LF,
CHUNKED_IN_TRAILERS_LINE_HEAD,
CHUNKED_IN_TRAILERS_LINE_MIDDLE
};
}
decoder->_hex_count = 0;
decoder->_state = CHUNKED_IN_CHUNK_EXT;
- /* fall through */
+ /* fallthru */
case CHUNKED_IN_CHUNK_EXT:
/* RFC 7230 A.2 "Line folding in chunk extensions is
* disallowed" */
if (src == bufsz) {
goto Exit;
}
- if (buf[src] == '\012') {
+ if (buf[src] == '\015') {
break;
+ } else if (buf[src] == '\012') {
+ ret = -1;
+ goto Exit;
}
}
++src;
+ decoder->_state = CHUNKED_IN_CHUNK_HEADER_EXPECT_LF;
+ /* fallthru */
+ case CHUNKED_IN_CHUNK_HEADER_EXPECT_LF:
+ if (src == bufsz) {
+ goto Exit;
+ }
+ if (buf[src] != '\012') {
+ ret = -1;
+ goto Exit;
+ }
+ ++src;
if (decoder->bytes_left_in_chunk == 0) {
if (decoder->consume_trailer) {
decoder->_state =
}
}
decoder->_state = CHUNKED_IN_CHUNK_DATA;
- /* fall through */
+ /* fallthru */
case CHUNKED_IN_CHUNK_DATA: {
size_t avail = bufsz - src;
if (avail < decoder->bytes_left_in_chunk) {
src += decoder->bytes_left_in_chunk;
dst += decoder->bytes_left_in_chunk;
decoder->bytes_left_in_chunk = 0;
- decoder->_state = CHUNKED_IN_CHUNK_CRLF;
+ decoder->_state = CHUNKED_IN_CHUNK_DATA_EXPECT_CR;
}
- /* fall through */
- case CHUNKED_IN_CHUNK_CRLF:
- for (;; ++src) {
- if (src == bufsz) {
- goto Exit;
- }
- if (buf[src] != '\015') {
- break;
- }
+ /* fallthru */
+ case CHUNKED_IN_CHUNK_DATA_EXPECT_CR:
+ if (src == bufsz) {
+ goto Exit;
+ }
+ if (buf[src] != '\015') {
+ ret = -1;
+ goto Exit;
+ }
+ ++src;
+ decoder->_state = CHUNKED_IN_CHUNK_DATA_EXPECT_LF;
+ /* fallthru */
+ case CHUNKED_IN_CHUNK_DATA_EXPECT_LF:
+ if (src == bufsz) {
+ goto Exit;
}
if (buf[src] != '\012') {
ret = -1;
goto Complete;
}
decoder->_state = CHUNKED_IN_TRAILERS_LINE_MIDDLE;
- /* fall through */
+ /* fallthru */
case CHUNKED_IN_TRAILERS_LINE_MIDDLE:
for (;; ++src) {
if (src == bufsz) {