Commit b4a02977 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

http: add stream error reporting for chunked transfer encoding

parent 1b5d9785
......@@ -23,6 +23,7 @@
#endif
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
......@@ -50,7 +51,7 @@ static_assert(offsetof(struct vlc_chunked_stream, stream) == 0, "Cast error");
static void *vlc_chunked_fatal(struct vlc_chunked_stream *s)
{
s->error = true;
return NULL;
return vlc_http_error;
}
static struct vlc_http_msg *vlc_chunked_wait(struct vlc_http_stream *stream)
......@@ -66,15 +67,20 @@ static block_t *vlc_chunked_read(struct vlc_http_stream *stream)
struct vlc_chunked_stream *s = (struct vlc_chunked_stream *)stream;
block_t *block = NULL;
if (s->eof || s->error)
if (s->eof)
return NULL;
if (s->error)
return vlc_http_error;
/* Read chunk size (hexadecimal length) */
if (s->chunk_length == 0)
{ /* NOTE: This accepts LF in addition to CRLF. No big deal. */
char *line = vlc_tls_GetLine(s->tls);
if (line == NULL)
{
errno = EPROTO;
return vlc_chunked_fatal(s);
}
int end;
......@@ -85,7 +91,10 @@ static block_t *vlc_chunked_read(struct vlc_http_stream *stream)
free(line);
if (s->chunk_length == UINTMAX_MAX)
{
errno = EPROTO;
return vlc_chunked_fatal(s);
}
}
/* Read chunk data */
......
......@@ -138,6 +138,25 @@ static void test_good(void)
vlc_http_stream_close(s, false);
}
static void test_empty(void)
{
struct vlc_http_stream *s;
block_t *b;
stream_content = "0\r\n";
stream_length = 3;
stream_bad = true;
s = vlc_chunked_open(&chunked_stream, &chunked_tls);
assert(s != NULL);
b = vlc_http_stream_read(s);
assert(b == NULL);
b = vlc_http_stream_read(s);
assert(b == NULL);
vlc_http_stream_close(s, false);
}
static void test_bad(const char *payload)
{
struct vlc_http_stream *s;
......@@ -150,8 +169,11 @@ static void test_bad(const char *payload)
s = vlc_chunked_open(&chunked_stream, &chunked_tls);
assert(s != NULL);
while ((b = vlc_http_stream_read(s)) != NULL)
while ((b = vlc_http_stream_read(s)) != vlc_http_error)
{
assert(b != NULL);
block_Release(b);
}
vlc_http_stream_close(s, false);
}
......@@ -159,10 +181,10 @@ static void test_bad(const char *payload)
int main(void)
{
test_good();
test_empty();
test_bad("");
test_bad("A\r\n" "123456789");
test_bad("Z\r\n" "123456789");
test_bad("0\r\n");
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment