From patchwork Sun Feb 12 03:04:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Micah Galizia X-Patchwork-Id: 2514 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp334099vsb; Sat, 11 Feb 2017 19:10:50 -0800 (PST) X-Received: by 10.223.140.18 with SMTP id z18mr13795239wra.6.1486869050405; Sat, 11 Feb 2017 19:10:50 -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 65si8113512wrb.336.2017.02.11.19.10.50; Sat, 11 Feb 2017 19:10:50 -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 5FC93689D9D; Sun, 12 Feb 2017 05:10:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f196.google.com (mail-io0-f196.google.com [209.85.223.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4ED0F689B99 for ; Sun, 12 Feb 2017 05:10:37 +0200 (EET) Received: by mail-io0-f196.google.com with SMTP id 101so9417385iom.0 for ; Sat, 11 Feb 2017 19:10:41 -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=ZJAqCq5/4R7bQVF/pFqp3b8qfL0/tDNa7gGOJLH7c5Q=; b=lO3mzOwbf4j8P6wfculn5cRJJjJMGhtv4Dmm31hmDDhiLH94hKKmseyees5SDDcRWw dSEvfGqAuRLbZ/ApQ3KL6ndXKTWIXe68VKsak+rfl2ahVHxIHRxTDAbv4m3aIGaMaIYw T+X08sXuShYIpf5Q6jyuW2m8RDg5GW38oCn60l6EpjFLEZQEdDBoC2yX1SamWVR4vnCP Jpg8E5nyyeRuPXaYnMauakD8qlp0OaXsRDerZVL+2F+yvlN9PMHkMETQpe/oqC+4kVJH aLNKkE1dZaRIYZQynkrQa4E9dey8BjMEotGFhH/ehjcNdG8lW7qK2gxO8Rp/prUMxwhK k8Lw== 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=ZJAqCq5/4R7bQVF/pFqp3b8qfL0/tDNa7gGOJLH7c5Q=; b=Ku/SMj8y5k6+YkuucuUqCnoi4EtQ0MOGPmeg/PKkBQ2Wj4hgB7Rs3BnbkrvJ5Rrn5x ZV81+RYkohw+ZQzzs9/lzqGJ673Peg4PAH40Q1EG/l708q9M/seeLTL9iMYQaxLPNPqb 0D2qs/7sNoZS3lzAPmyDttsxpRg5XBzM7Ge9VnqG+2TaB6fhIkF6fXB93YjFo/BQxtls 57a8j4G/9kZqiu8Mmxma175Pi01EgQmykH7nPt+xiVhYWt4lN2tZSWVofJFczpa3nOzB oX8N2CSna/c/XgDjja8XrCeQx2tEPrqe5P/I4c9y5dj7kSCuu+cXE5fsD6Br4HJL72qk sktQ== X-Gm-Message-State: AMke39mCBp/W5jpjgv4u81Abx2sheSAD4nlIEB7w5gyl1NitsUBM9JfZfCy9Tdp7xhm4sQ== X-Received: by 10.107.19.169 with SMTP id 41mr16716749iot.209.1486868660848; Sat, 11 Feb 2017 19:04:20 -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 x100sm2471784ita.12.2017.02.11.19.04.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Feb 2017 19:04:20 -0800 (PST) From: Micah Galizia To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 Feb 2017 22:04:10 -0500 Message-Id: <20170212030410.23881-2-micahgalizia@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170212030410.23881-1-micahgalizia@gmail.com> References: <20170212030410.23881-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" Signed-off-by: Micah Galizia --- libavformat/http.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/libavformat/http.c b/libavformat/http.c index 944a6cf..e7b8ac3 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -682,12 +682,44 @@ 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); + 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); + return AVERROR(EINVAL); + } + } + // add the cookie to the dictionary av_dict_set(cookies, name, eql, AV_DICT_DONT_STRDUP_KEY);