From patchwork Wed Dec 13 00:35:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 6730 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp4767923jah; Tue, 12 Dec 2017 16:41:26 -0800 (PST) X-Google-Smtp-Source: ACJfBovs2KsFZjEzP2JwkS87soDiDqJWGpNEYRwa728PsdYESA0q49s0s/5FaVfW9CIGIyngCTH2 X-Received: by 10.28.169.194 with SMTP id s185mr399503wme.119.1513125686307; Tue, 12 Dec 2017 16:41:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513125686; cv=none; d=google.com; s=arc-20160816; b=EZFO3uaGyEpTuSBlBe+kSF3HK5l/Kck5t2XpSvg/OuB/QNjlYdpyzZRbYafjkV6PQ4 VB6xx3TMi7T7riW1g2jDq+01yJIsT44yFSsHEYC7ozBpPZLGEw6pzr1QmO+O1zVi/UVi fE9O5a1ccfGXmT7Uz2J1KMPOPCnfD3j8NeNSZKaZtc/v7tqx7CDnSleKnhwrw5qx9+yu XlZ4SgbCoLEDq02E22SqelQXs9KLsgTFMGN01h2rJncnX0zk/obkWiQ7/XfseiFMThWG CF+AUUog2Zpj9h1wx6Ql10xDtojWogzq/gEGYvo4sooV6dLURECaHYgnCPKyMB6MSvTS C9cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=nIV+r8QhFaf4ByXDHjcA1igHzwFBBM8y2yyzWd4MNDE=; b=SCz75tq9ZDQLBJBDGfxtM6fydE9PUNUVo4CbqY1ZAdVTpDKnz7jUbN7rhIY/22EHSg nWiwa77J9udvgim93ibvHGuk62IealkPPyLifpz7+kVpldQuH++o/i8Imu16nS+F4G8o YnPt/tmN5ToBpnI8Zc8tKLxLIkmLWWRmnGQPT0HsU3Ol9L0i0Bmr2aRLCruDeR52JoLz QQMkX9vln1sdeS+SVSf7Kx/cRnBfQY8iB8DTB4dxvXoAthUYLORGEkWor2VMHSYZ8uzp aMobluo+LZ7IJxcz4WVpsh/ZWi55LG9O/GSGwtdpB3zN/dm+qQKmqLYxD5Wq1JC83OY9 5hSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=C5nOvhpX; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q13si348339wra.151.2017.12.12.16.41.25; Tue, 12 Dec 2017 16:41:26 -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=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=C5nOvhpX; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C99E868A2BE; Wed, 13 Dec 2017 02:41:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f42.google.com (mail-pg0-f42.google.com [74.125.83.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DF2CF68A1D6 for ; Wed, 13 Dec 2017 02:41:09 +0200 (EET) Received: by mail-pg0-f42.google.com with SMTP id j9so517374pgc.11 for ; Tue, 12 Dec 2017 16:41:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tmm1-net.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=qtR5WuMSFQMBuak5u9kp6rTx60mW1N396W115Ho6V2c=; b=C5nOvhpXmrJsXs/ykl1t/ipQIOetpPqclOAekXutcafxZMRdqa7Ve8BZZSg1E1tYYU 42Dk6fGwA8Jh6lK4ZiKfSC3DCQeCTAtKNUC6GZt8vykZk7JmPjmjKz4dXVtxqEImqDEo jLCSj2/AstZD9lDqrh36OxkQXTmYgAfeq6M035TCL6gp9QeqLplYe1UJ/baefcrBOiwe det8QlQ9EF3+aAIYMgGLJbBx8Tdlnt+gqI1D1kpvxAmzRr5cvefQX54KrZmgwyImE00r Bg+eUI6v+zHnLrUkHWNEoFw/PCDyYxLetk7JcRewQixoyq5hfYevnVkZ2jfGmlz1Dy1R k2hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=qtR5WuMSFQMBuak5u9kp6rTx60mW1N396W115Ho6V2c=; b=L9n+dNn0/fOhD8PKA9JIHQIAiM1a0jEUq/IE7rFcZkLUY6sk4SHAEbgozOVp18UY+v yIs7Kl/KA4aNinw1oF0cr/vVWUGB5g+lag52WeJXFbHwfYde5h6IVVEJoehXoe8KgZ0b +A4R1bKoWUoeDk/89SybzMfCIWfOvZIyQWNbufFfJOuJjt+NQTaVOxBYBgrFW7v9iHUN g0u0bJVr+gjQYknwpAaTTXqB1S1eWQF6BwDPrgkcglKCCiTfbXV5bPhWV0ASJPhsmKmK JXfb7Jd9uIZkQ9JQBmEUI4klBiih8+u8VVl6yylmwwcRkRPP14LEs7HO0ziVPTGVQd3z sYVA== X-Gm-Message-State: AKGB3mK/mwvwoxJXOyVGWoMoI5NCRa1FEHXoSMvamv0CRKDGPzZTqJbP 7E8FLvZffC8bcoBI/57VWk56IJ2E X-Received: by 10.101.64.130 with SMTP id t2mr3531206pgp.299.1513125317220; Tue, 12 Dec 2017 16:35:17 -0800 (PST) Received: from localhost.localdomain (c-69-181-54-242.hsd1.ca.comcast.net. [69.181.54.242]) by smtp.gmail.com with ESMTPSA id b25sm394282pfd.182.2017.12.12.16.35.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Dec 2017 16:35:16 -0800 (PST) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Dec 2017 16:35:07 -0800 Message-Id: <20171213003511.25342-2-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.14.3 (Apple Git-98) In-Reply-To: <20171213003511.25342-1-ffmpeg@tmm1.net> References: <20171213003511.25342-1-ffmpeg@tmm1.net> Subject: [FFmpeg-devel] [PATCH v2 1/5] avformat/http: ff_http_do_new_request() returns EINVAL if re-used with different hostname 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: nfxjfg@googlemail.com, Aman Gupta , barsnick@gmx.net, kjeyapal@akamai.com MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Gupta This will prevent improper use of ff_http_do_new_request() if the user tries to send a request for a different host to a previously connected persistent http/1.1 connection. --- libavformat/http.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libavformat/http.c b/libavformat/http.c index cf86adc617..a3c36423fc 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -306,6 +306,22 @@ int ff_http_do_new_request(URLContext *h, const char *uri) HTTPContext *s = h->priv_data; AVDictionary *options = NULL; int ret; + char hostname1[1024], hostname2[1024], proto1[10], proto2[10]; + int port1, port2; + + av_url_split(proto1, sizeof(proto1), NULL, 0, + hostname1, sizeof(hostname1), &port1, + NULL, 0, s->location); + av_url_split(proto2, sizeof(proto2), NULL, 0, + hostname2, sizeof(hostname2), &port2, + NULL, 0, uri); + if (port1 != port2 || strncmp(hostname1, hostname2, sizeof(hostname2)) != 0) { + av_log(h, AV_LOG_ERROR, "Cannot reuse HTTP connection for different host: %s:%d != %s:%d\n", + hostname1, port1, + hostname2, port2 + ); + return AVERROR(EINVAL); + } ret = http_shutdown(h, h->flags); if (ret < 0)