[FFmpeg-devel] [PATCH]Add one CRLF to http headers if necessary

Carl Eugen Hoyos cehoyos at ag.or.at
Thu Feb 26 16:28:54 CET 2015


On Thursday 26 February 2015 03:31:39 pm Derek Buitenhuis wrote:
> On 2/26/2015 2:09 PM, Carl Eugen Hoyos wrote:
> > +            snprintf(header, len + 3, "%s\r\n", s->headers);
>
> This does not necessarily work on windows. The C standard idctates that in
> text mode, \n is translated to the system's native newline.
>
> Use memcpy and 0x0D / 0X0A / 0x00.

New patch attached.

> This may also accidentally allow for headers to end with '\n\r\n',
> wouldn't it?

Yes, I don't know if this is a problem.

Thank you, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/http.c b/libavformat/http.c
index 55dcb6e..59e5acb 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -312,9 +312,17 @@ static int http_open(URLContext *h, const char *uri, int flags,
 
     if (s->headers) {
         int len = strlen(s->headers);
-        if (len < 2 || strcmp("\r\n", s->headers + len - 2))
+        if (len < 2 || strcmp("\r\n", s->headers + len - 2)) {
+            char *header = av_malloc(len + 3);
+            if (!header)
+                return AVERROR(ENOMEM);
+            memcpy(header, s->headers, len);
+            memcpy(header + len, "\r\n\0", 3);
+            av_free(s->headers);
+            s->headers = header;
             av_log(h, AV_LOG_WARNING,
-                   "No trailing CRLF found in HTTP header.\n");
+                   "No trailing CRLF found in HTTP header, added \\r\\n at the end.\n");
+        }
     }
 
     ret = http_open_cnx(h, options);


More information about the ffmpeg-devel mailing list