[FFmpeg-devel] [PATCH v4] Parse cookies more correctly

Scott Moak scott.moak at mybrainoncode.com
Fri Feb 21 07:42:55 CET 2014


Cookies with an Expires directive do not get parsed (and ignored)
correctly, so we need to fix that.

Signed-off-by: Scott Moak <scott.moak at mybrainoncode.com>
---
 libavformat/http.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index 69c4d6d..3d9563b 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -484,8 +484,16 @@ static int get_cookies(HTTPContext *s, char **cookies, const char *path,
         char *param, *next_param, *cdomain = NULL, *cpath = NULL, *cvalue = NULL;
         set_cookies = NULL;
 
-        while ((param = av_strtok(cookie, "; ", &next_param))) {
+        while ((param = av_strtok(cookie, ";", &next_param))) {
             cookie = NULL;
+            /* skip leading spaces */
+            param += strspn(param, " ");
+            /* skip trailing spaces */
+            if (strlen(param) > 0) {
+                while (0x20 == param[strlen(param) - 1]) {
+                    param[strlen(param) - 1] = 0;
+                }
+            }
             if        (!av_strncasecmp("path=",   param, 5)) {
                 av_free(cpath);
                 cpath = av_strdup(&param[5]);
@@ -498,8 +506,9 @@ static int get_cookies(HTTPContext *s, char **cookies, const char *path,
             } else if (!av_strncasecmp("secure",  param, 6) ||
                        !av_strncasecmp("comment", param, 7) ||
                        !av_strncasecmp("max-age", param, 7) ||
-                       !av_strncasecmp("version", param, 7)) {
-                // ignore Comment, Max-Age, Secure and Version
+                       !av_strncasecmp("version", param, 7) ||
+                       !av_strncasecmp("expires", param, 7)) {
+                // ignore Comment, Max-Age, Secure, Version and Expires
             } else {
                 av_free(cvalue);
                 cvalue = av_strdup(param);
-- 
1.8.5.4



More information about the ffmpeg-devel mailing list