From patchwork Sun Feb 12 03:26:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Micah Galizia X-Patchwork-Id: 2515 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp339135vsb; Sat, 11 Feb 2017 19:34:30 -0800 (PST) X-Received: by 10.223.164.85 with SMTP id e21mr15099852wra.111.1486870470592; Sat, 11 Feb 2017 19:34:30 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g65si7232053wmd.148.2017.02.11.19.34.30; Sat, 11 Feb 2017 19:34:30 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8F12C689C87; Sun, 12 Feb 2017 05:34:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f67.google.com (mail-it0-f67.google.com [209.85.214.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 91AD4689A4A for ; Sun, 12 Feb 2017 05:34:17 +0200 (EET) Received: by mail-it0-f67.google.com with SMTP id e137so8019838itc.0 for ; Sat, 11 Feb 2017 19:34:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2h6ymIG1ceZU+3do5y+HwpV2pjGzabZ1U4FtiOfTsJE=; b=T0oiix//TKnhyJm4eHDZBUIu2iRAOJMfXqU0AKS9E3CUZEikrYYk1Rgbh1xUjPR7RP rzn9YPbciBnWx49W4smpfcYEMip1R9EIeMpQhxK3zLTu6EjsFDqTG4VH726xTUtEyXvN EwfTBTbcoCzupYB11hjizJNnk7pZQ9Sm7YkS/hBH/KASMsWnZZYSysB4/RoxY/McFYW6 XdSjXN1DSGCuV4WYb/c+JiK7E5mVN0lCW9pgjQLy9CKq/1rQjTa8RyxcMTdn/X+eWh6d 5QWjDjdFA8EhYE+U9jn6UX18fPmF+GV4UpFEeCqJ3aQ8UMCcPyh8xsOaWzQbVVKANM7z 5hFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2h6ymIG1ceZU+3do5y+HwpV2pjGzabZ1U4FtiOfTsJE=; b=mPSWtfS8CszO7flnOAL4xWOTx5OUTRBMlTDPQ9CQCv1AJDYZSOPHwIgl7H6LTkVirT SLgpML5zkpApeMe5ojvMrIeLytkQPhu8VA1opRS7E4eU+uk+mvn7FIs5DETBY/UZQ2ta En96eD6AZDUuNJLlK/ZdIbLV4RtaPBp+hoddbmL20eCEw6Cejtl2pqFb8w2WrNKru9ga Dz1HQSuz+XC5vRSwVblzRnu/YdxJViGlOI3g7VlxNzaeREbqO2t3onOKCch2gqcARvtc 9kt3U3pku3zG2+q5nazz5lCQdw4W6YCtjbS0KktHtLqE86XY4xVoUk//mk7IWIrauuKp uHyA== X-Gm-Message-State: AMke39kaNqToEpzJLfQfTZYFGU/N8IQVbXPwyf4Qxlq5pcsCUx+7K0QMb+zdLFkRRuXiAQ== X-Received: by 10.36.51.68 with SMTP id k65mr15844050itk.4.1486870003533; Sat, 11 Feb 2017 19:26:43 -0800 (PST) Received: from localhost.localdomain (ip-24-54-73-138.user.start.ca. [24.54.73.138]) by smtp.gmail.com with ESMTPSA id c100sm2485183itd.20.2017.02.11.19.26.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Feb 2017 19:26:43 -0800 (PST) From: Micah Galizia To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 Feb 2017 22:26:35 -0500 Message-Id: <20170212032635.25824-2-micahgalizia@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170212032635.25824-1-micahgalizia@gmail.com> References: <20170212032635.25824-1-micahgalizia@gmail.com> Subject: [FFmpeg-devel] [PATCH] Ignore expired cookies X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Micah Galizia MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavformat/http.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/libavformat/http.c b/libavformat/http.c index 944a6cf..24368aa 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -682,12 +682,46 @@ static int parse_icy(HTTPContext *s, const char *tag, const char *p) static int parse_cookie(HTTPContext *s, const char *p, AVDictionary **cookies) { - char *eql, *name; + char *eql, *name, *expiry; // duplicate the cookie name (dict will dupe the value) if (!(eql = strchr(p, '='))) return AVERROR(EINVAL); if (!(name = av_strndup(p, eql - p))) return AVERROR(ENOMEM); + // ensure the expiry is sane + if ((expiry = strstr(eql, "Expires="))) { + struct tm tm_buf = {0}; + char *end; + + // get the start & the end of the expiry ('11 Feb 2017 09:41:35 GMT') + // this skips past the day of the week by finding the space following it + expiry += 8 * sizeof(char); + while (*expiry != ' ') expiry++; + expiry++; + end = expiry+1; + while (*end != ';') end++; + + // ensure the time is parsable + end = strptime(expiry, "%d %b %Y %H:%M:%S %Z", &tm_buf); + + // ensure neulion's different format is parsable + if (!end) end = strptime(expiry, "%d-%b-%Y %H:%M:%S %Z", &tm_buf); + + // if the expire is specified but unparsable, this cookie is invalid + if (!end) { + av_log(s, AV_LOG_ERROR, "Unable to parse expiry for cookie '%s'\n", p); + av_free(name); + return AVERROR(EINVAL); + } + + // no cookies from the past (neulion) + if (mktime(&tm_buf) < time(NULL)) { + av_log(s, AV_LOG_ERROR, "Ignoring cookie from the past '%s'\n", p); + av_free(name); + return AVERROR(EINVAL); + } + } + // add the cookie to the dictionary av_dict_set(cookies, name, eql, AV_DICT_DONT_STRDUP_KEY);