remove_chunked_transfer_coding(): Refuse to de-chunk invalid data
authorFabian Keil <fk@fabiankeil.de>
Wed, 31 Mar 2021 10:14:36 +0000 (12:14 +0200)
committerFabian Keil <fk@fabiankeil.de>
Fri, 6 May 2022 10:40:01 +0000 (12:40 +0200)
Previously the data could get corrupted even further.
Now we simply pass the unmodified data to the client.

filters.c

index baaaea5..21ee44d 100644 (file)
--- a/filters.c
+++ b/filters.c
@@ -2317,6 +2317,18 @@ static jb_err remove_chunked_transfer_coding(char *buffer, size_t *size)
    assert(buffer);
    from_p = to_p = buffer;
 
+#ifndef FUZZ
+   /*
+    * Refuse to de-chunk invalid or incomplete data unless we're fuzzing.
+    */
+   if (!chunked_data_is_complete(buffer, *size, 0))
+   {
+      log_error(LOG_LEVEL_ERROR,
+         "Chunk-encoding appears to be invalid. Content can't be filtered.");
+      return JB_ERR_PARSE;
+   }
+#endif
+
    if (sscanf(buffer, "%x", &chunksize) != 1)
    {
       log_error(LOG_LEVEL_ERROR, "Invalid first chunksize while stripping \"chunked\" transfer coding");