}
}
-/* This function may be called only in HTTP_MSG_CHUNK_CRLF. It reads the CRLF or
- * a possible LF alone at the end of a chunk. The caller should adjust msg->next
+/* This function may be called only in HTTP_MSG_CHUNK_CRLF. It reads the CRLF
+ * at the end of a chunk. The caller should adjust msg->next
* in order to include this part into the next forwarding phase. Note that the
* caller must ensure that head+start points to the first byte to parse. It
* returns the number of bytes parsed on success, so the caller can set msg_state
if (stop <= start)
return 0;
+ if (unlikely(*ptr != '\r')) // negative position to stop
+ return ptr - __b_peek(buf, stop);
+
/* NB: we'll check data availability at the end. It's not a
* problem because whatever we match first will be checked
* against the correct length.
*/
- if (*ptr == '\r') {
- bytes++;
- ptr++;
- if (ptr >= b_wrap(buf))
- ptr = b_orig(buf);
- }
+ bytes++;
+ ptr++;
+ if (ptr >= b_wrap(buf))
+ ptr = b_orig(buf);
if (bytes > stop - start)
return 0;
dpos += chksz;
ridx += chksz;
- /* Parse CRLF or LF (always present) */
- if (likely(end[ridx] == '\r'))
- ++ridx;
+ /* Parse CRLF */
+ if (unlikely(end[ridx] != '\r')) {
+ h1m->state = H1_MSG_CHUNK_CRLF;
+ goto parsing_error;
+ }
+ ++ridx;
if (end[ridx] != '\n') {
h1m->state = H1_MSG_CHUNK_CRLF;
goto parsing_error;