avformat/http: Check for truncated buffers in http_connect()

Reported-by: SleepProgger <security@gnutp.com>
Reviewed-by: Steven Liu <lingjiujianke@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 8fa18e042a)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer 2017-02-13 12:47:49 +01:00
parent 01308b492a
commit 9ebbce5113
1 changed files with 10 additions and 1 deletions

View File

@ -686,6 +686,7 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
int len = 0; int len = 0;
const char *method; const char *method;
int send_expect_100 = 0; int send_expect_100 = 0;
int ret;
/* send http header */ /* send http header */
post = h->flags & AVIO_FLAG_WRITE; post = h->flags & AVIO_FLAG_WRITE;
@ -776,7 +777,7 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
if (s->headers) if (s->headers)
av_strlcpy(headers + len, s->headers, sizeof(headers) - len); av_strlcpy(headers + len, s->headers, sizeof(headers) - len);
snprintf(s->buffer, sizeof(s->buffer), ret = snprintf(s->buffer, sizeof(s->buffer),
"%s %s HTTP/1.1\r\n" "%s %s HTTP/1.1\r\n"
"%s" "%s"
"%s" "%s"
@ -792,6 +793,14 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
av_log(h, AV_LOG_DEBUG, "request: %s\n", s->buffer); av_log(h, AV_LOG_DEBUG, "request: %s\n", s->buffer);
if (strlen(headers) + 1 == sizeof(headers) ||
ret >= sizeof(s->buffer)) {
av_log(h, AV_LOG_ERROR, "overlong headers\n");
err = AVERROR(EINVAL);
goto done;
}
if ((err = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0) if ((err = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0)
goto done; goto done;