From patchwork Tue Aug 25 14:09:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21920 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 8EFCB44B5EC for ; Tue, 25 Aug 2020 17:17:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6A86868AB18; Tue, 25 Aug 2020 17:17:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C02C468803F for ; Tue, 25 Aug 2020 17:17:09 +0300 (EEST) Received: by mail-ed1-f65.google.com with SMTP id k25so11352063edj.13 for ; Tue, 25 Aug 2020 07:17:09 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=9GD11jE0+W4fPkRry+b0jVPTU/yfxP5uv7LdLM50Bx8=; b=BVoho6i2nwnKNGTd9vtTXAOmqqNo8Geu0AjM4i3MFny9MeJCibqy1UyEkPsnTDbumM u93kkBCQsn3HkyH8n7EbtKQdP8dZMCC9g//JLvXrPFf8VXx/KZullbLDknZmvsTjI0m7 GQTTiI/ljMNP1KEHq4GXgatYuqVaTFxY/VlK2KeaK4DCavo+QgXU6Gf+E9FY0wrMbxaE P1n4yYVlwt8wclg6iodGlLCb8tsG0zJQnYn7ZSV15elrptw8fbvYmUOPgCwBJ4++QERu NlF6Uu+VN8baqavoK6OQc6Z6ICqRt4TCAVqoUr3OrIsPaeoomqP0q/vH0qJHK/UOPmgg RS2g== 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:mime-version:content-transfer-encoding; bh=9GD11jE0+W4fPkRry+b0jVPTU/yfxP5uv7LdLM50Bx8=; b=X6DJcmlM2/Qu1sLZ5E8jtaIHwWpCDzwFS3JP0Aj2paDAcNQjF8TNqEkEhaV+UT8T8h Zemuheens64N+/sylETbIW2PeVQnkhi3XGhi9mdu7gjGlDAZ1D3d479mpqrqJQ3M5mH/ 6s9+TyBKUpn2pETIeu/jUW6defz5wejlXxRM9+b+HvOKKxlnyL/mhNtv7YbbRtOYdQY0 e7bkbkZU14MNPOjaNeJcHrqM8ozOHYY+ZnXjeN4ytpuFfvARG1OscMOetIGp2QW3J6ur 0b1+tzivEHyVGIHP6T1CO3cFTjQ6EpVjIBH5U3zqX1L6WW3bnrYSbTM64Gy+AWiu8PQG KbQA== X-Gm-Message-State: AOAM5315AXQM6CMhM5/ivz247OfjQ/DQThgi73tsMmxTS4DSJbiXJhge sD4cRhy5eaQFOHblWI6ohvwsE02b2OQ= X-Google-Smtp-Source: ABdhPJw2Oap/zQyujDhHr4Lg4AQLSDySszCE6O3PoKfLuCqsIYCoqubWgJoDDpyKOEIiT8Hkw/AEBA== X-Received: by 2002:a05:6402:17a2:: with SMTP id j2mr10295427edy.79.1598364619964; Tue, 25 Aug 2020 07:10:19 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id k25sm10169806edx.96.2020.08.25.07.10.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2020 07:10:19 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 25 Aug 2020 16:09:22 +0200 Message-Id: <20200825140927.16433-14-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200825140927.16433-1-andreas.rheinhardt@gmail.com> References: <20200825140927.16433-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/19] avfilter/af_amerge: Fix segfault upon allocation failure 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The amerge filter uses a variable number of inpads and allocates them in its init function; if all goes well, the number of inpads coincides with a number stored in the filter's private context. Yet if allocating a subsequent inpad fails, the uninit function nevertheless uses the number stored in the private context to determine the number of inpads to free and not the AVFilterContext's nb_inputs. This will lead to an access beyond the end of the allocated AVFilterContext.input_pads array and an invalid free. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_amerge.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libavfilter/af_amerge.c b/libavfilter/af_amerge.c index ca94a224af..93f6f17d22 100644 --- a/libavfilter/af_amerge.c +++ b/libavfilter/af_amerge.c @@ -58,13 +58,10 @@ AVFILTER_DEFINE_CLASS(amerge); static av_cold void uninit(AVFilterContext *ctx) { AMergeContext *s = ctx->priv; - int i; - for (i = 0; i < s->nb_inputs; i++) { - if (ctx->input_pads) - av_freep(&ctx->input_pads[i].name); - } av_freep(&s->in); + for (unsigned i = 0; i < ctx->nb_inputs; i++) + av_freep(&ctx->input_pads[i].name); } static int query_formats(AVFilterContext *ctx)