From patchwork Wed Mar 10 01:05:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26291 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 68905448EE5 for ; Wed, 10 Mar 2021 03:06:43 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4ADDF68A830; Wed, 10 Mar 2021 03:06:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7376068A315 for ; Wed, 10 Mar 2021 03:06:36 +0200 (EET) Received: by mail-ed1-f42.google.com with SMTP id w9so24409543edt.13 for ; Tue, 09 Mar 2021 17:06:36 -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:reply-to :mime-version:content-transfer-encoding; bh=4AwLu1n/V789jvqPfEnpUrPmE032pwnWyS/aNRI5R+A=; b=ranz/xJ3kVnbn0LPOTjj2TY4r3dEhTS20S4yc1rLh+TYt0ncMiITWwN/Pq4lrFLsX2 JY9MkCkrt8KHY9uXGyG5W/kieIRlXzhBlg3XmxFYotcidnGR4ToqcwkK+gwDpsrvGIH7 mL8Q4NtMutYWipNYcg8W2saDrs4gzxQZN6IewUt5+916yPdwBVWviVS84VSzFau9e8Kl lCQuMOewz1Sy/35iaTC6SgcCobGHAIeHv9wLeT1BErMtgME61uskG2gKyFF9E4JQuC1o RWn+nNd+ef8/NaoAKD8K5qxjv5jo5dW0DZQanv1W737qpi3YsIGc+WMULOgwKlIKTzOr 7DmA== 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:reply-to:mime-version:content-transfer-encoding; bh=4AwLu1n/V789jvqPfEnpUrPmE032pwnWyS/aNRI5R+A=; b=g+R0fJssTsCG/8iRrpBNrFo+RzKZMSBkdPksyNL4g9Ae7c1KKeFPeAZGxwWJljIa+a 9ZadlJulAkY+pRrAxj2jXiXmfVE6btxhwBTrUU6Q0sTv3za0ZXtXiAhrw8fMrjJyiAhD v4x3Vj/ioVigbViQhMmd80WypQFelh3l2YqXJDuc2xGnn8JRlTX8QDQlXva0UZGwpXMl 9W2GUZQn4bxTSxzupQIjcoJGhJSm/03oab+UFSj/aNXio2qETBSQ49FxhV2B2+GYSI+f zY2l4bhn19WL391c6auSvGTqgQyGngLvUq/KCZ9MlhOEPzEf93tGV7L/f3XdU77BCwWV ZIyQ== X-Gm-Message-State: AOAM530oq3Ddb3NFez8ZuX36UhRIFFNtdCvoTQqLZCtfU4IiO0YxSSdl ulakpoxxwT/2YDDh4u6nVw79NCp7z9M= X-Google-Smtp-Source: ABdhPJy+v6yG/Xd1nR+SYbcfHS3bE5SWLBBZiD7ROGiqcgrZasfhGLHk8267HYjcazFrm2fSNFGmMg== X-Received: by 2002:a50:ee18:: with SMTP id g24mr389856eds.267.1615338395697; Tue, 09 Mar 2021 17:06:35 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id r13sm9960737edy.3.2021.03.09.17.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 17:06:35 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 02:05:58 +0100 Message-Id: <20210310010601.1142819-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/8] avutil/avstring: Check for memory allocation error in av_escape 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" av_bprint_finalize() can still fail even when it has been checked that the AVBPrint is currently complete: Namely if the string was so short that it fit into the AVBPrint's internal buffer. Signed-off-by: Andreas Rheinhardt --- libavutil/avstring.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavutil/avstring.c b/libavutil/avstring.c index 832bec750f..49e8df55aa 100644 --- a/libavutil/avstring.c +++ b/libavutil/avstring.c @@ -336,6 +336,7 @@ int av_escape(char **dst, const char *src, const char *special_chars, enum AVEscapeMode mode, int flags) { AVBPrint dstbuf; + int ret; av_bprint_init(&dstbuf, 1, INT_MAX); /* (int)dstbuf.len must be >= 0 */ av_bprint_escape(&dstbuf, src, special_chars, mode, flags); @@ -343,10 +344,10 @@ int av_escape(char **dst, const char *src, const char *special_chars, if (!av_bprint_is_complete(&dstbuf)) { av_bprint_finalize(&dstbuf, NULL); return AVERROR(ENOMEM); - } else { - av_bprint_finalize(&dstbuf, dst); - return dstbuf.len; } + if ((ret = av_bprint_finalize(&dstbuf, dst)) < 0) + return ret; + return dstbuf.len; } int av_match_name(const char *name, const char *names)