[vlc-commits] http: add stream error reporting for chunked transfer encoding
Rémi Denis-Courmont
git at videolan.org
Tue Aug 30 15:12:59 CEST 2016
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Aug 30 15:23:33 2016 +0300| [b4a029773c11ecd13925a47b6791db488749fbf4] | committer: Rémi Denis-Courmont
http: add stream error reporting for chunked transfer encoding
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b4a029773c11ecd13925a47b6791db488749fbf4
---
modules/access/http/chunked.c | 13 +++++++++++--
modules/access/http/chunked_test.c | 26 ++++++++++++++++++++++++--
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/modules/access/http/chunked.c b/modules/access/http/chunked.c
index b97e19f..ca20e63 100644
--- a/modules/access/http/chunked.c
+++ b/modules/access/http/chunked.c
@@ -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 */
diff --git a/modules/access/http/chunked_test.c b/modules/access/http/chunked_test.c
index b22a765..0f13466 100644
--- a/modules/access/http/chunked_test.c
+++ b/modules/access/http/chunked_test.c
@@ -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;
}
More information about the vlc-commits
mailing list