From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id A0F5547F3B for ; Mon, 5 Feb 2024 02:58:40 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EECD368D163; Mon, 5 Feb 2024 04:58:31 +0200 (EET) Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4462B68CD39 for ; Mon, 5 Feb 2024 04:58:25 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 8D36FFF802 for ; Mon, 5 Feb 2024 02:58:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1707101904; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:in-reply-to:in-reply-to:references:references; bh=OlYhoQbNzap8kkzwAokhmAeckR7/6SRwUNLn/2hmpgY=; b=EPDNCUlK0GvYfXefB9knj5Yv9pa3pYAyaxWovF1rzKOP+wLNUumPdWzSk7uFhu9Qey+BQb +sYgf6eEh4gehQRuI/fCy+AzzFNBG6ZP9eoXK578BA4hT8UFaT+SEIYLy+IkhcDYaQhU3N TyaO9Uj+L3zvwGshB/bosnVQsUlJqEwWZK5WcRoxeAfHOslK3zTqNSF2GcPuo7vdfKw9ih KHNdzso2hnr8cV3ga5NIHxuef9Co1JCJ3MZGOtTOdMKPxO07K78df2CVqNKktnzR5H5Bv0 jaVdMoa2l3Ytb/rXbEKhT/1x7dgjfnK1wBqH/94HThEmhmMFM07uEgKxScSdsQ== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Mon, 5 Feb 2024 03:58:23 +0100 Message-Id: <20240205025823.4259-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240205025823.4259-1-michael@niedermayer.cc> References: <20240205025823.4259-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 2/2] avfilter/signature_lookup: Do not dereference NULL pointers after malloc failure X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Fixes: CID 1403229 Dereference after null check Signed-off-by: Michael Niedermayer --- libavfilter/signature_lookup.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/libavfilter/signature_lookup.c b/libavfilter/signature_lookup.c index 86dd0c66754..6e45fde1b5a 100644 --- a/libavfilter/signature_lookup.c +++ b/libavfilter/signature_lookup.c @@ -37,6 +37,14 @@ #define STATUS_END_REACHED 1 #define STATUS_BEGIN_REACHED 2 +static void sll_free(MatchingInfo **sll) +{ + while (*sll) { + sll = &(*sll)->next; + av_freep(sll); + } +} + static void fill_l1distlut(uint8_t lut[]) { int i, j, tmp_i, tmp_j,count; @@ -290,6 +298,10 @@ static MatchingInfo* get_matching_parameters(AVFilterContext *ctx, SignatureCont av_log(ctx, AV_LOG_FATAL, "Could not allocate memory"); c = c->next; } + if (!c) { + sll_free(&cands); + goto error; + } c->framerateratio = (i+1.0) / 30; c->score = hspace[i][j].score; c->offset = j-90; @@ -305,6 +317,7 @@ static MatchingInfo* get_matching_parameters(AVFilterContext *ctx, SignatureCont } } } + error: for (i = 0; i < MAX_FRAMERATE; i++) { av_freep(&hspace[i]); } @@ -520,16 +533,6 @@ static MatchingInfo evaluate_parameters(AVFilterContext *ctx, SignatureContext * return bestmatch; } -static void sll_free(MatchingInfo *sll) -{ - void *tmp; - while (sll) { - tmp = sll; - sll = sll->next; - av_freep(&tmp); - } -} - static MatchingInfo lookup_signatures(AVFilterContext *ctx, SignatureContext *sc, StreamContext *first, StreamContext *second, int mode) { CoarseSignature *cs, *cs2; @@ -572,7 +575,7 @@ static MatchingInfo lookup_signatures(AVFilterContext *ctx, SignatureContext *sc "ratio %f, offset %d, score %d, %d frames matching\n", bestmatch.first->index, bestmatch.second->index, bestmatch.framerateratio, bestmatch.offset, bestmatch.score, bestmatch.matchframes); - sll_free(infos); + sll_free(&infos); } } while (find_next_coarsecandidate(sc, second->coarsesiglist, &cs, &cs2, 0) && !bestmatch.whole); return bestmatch; -- 2.17.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".