File ffmpeg-6-CVE-2024-35365.patch of Package A_slowroll-ffmpeg-6

58
 
1
From ced5c5fdb8634d39ca9472a2026b2d2fea16c4e5 Mon Sep 17 00:00:00 2001
2
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3
Date: Mon, 25 Mar 2024 16:54:25 +0100
4
Subject: [PATCH] fftools/ffmpeg_mux_init: Fix double-free on error
5
6
MATCH_PER_STREAM_OPT iterates over all options of a given
7
OptionDef and tests whether they apply to the current stream;
8
if so, they are set to ost->apad, otherwise, the code errors
9
out. If no error happens, ost->apad is av_strdup'ed in order
10
to take ownership of this pointer.
11
12
But this means that setting it originally was premature,
13
as it leads to double-frees when an error happens lateron.
14
This can simply be reproduced with
15
ffmpeg -filter_complex anullsrc  -apad bar -apad:n baz -f null -
16
This is a regression since 83ace80bfd80fcdba2c65fa1d554923ea931d5bd.
17
18
Fix this by using a temporary variable instead of directly
19
setting ost->apad. Also only strdup the string if it actually
20
is != NULL.
21
22
Reviewed-by: Marth64 <marth64@proxyid.net>
23
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
24
---
25
 fftools/ffmpeg_mux_init.c | 9 +++++++--
26
 1 file changed, 7 insertions(+), 2 deletions(-)
27
28
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
29
index 818d76acda..d3d7d022ff 100644
30
--- a/fftools/ffmpeg_mux_init.c
31
+++ b/fftools/ffmpeg_mux_init.c
32
@@ -845,6 +845,7 @@
33
         int channels = 0;
34
         char *layout = NULL;
35
         char *sample_fmt = NULL;
36
+        const char *apad = NULL;
37
38
         MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st);
39
         if (channels) {
40
@@ -882,8 +883,12 @@
41
42
         MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
43
44
-        MATCH_PER_STREAM_OPT(apad, str, ost->apad, oc, st);
45
-        ost->apad = av_strdup(ost->apad);
46
+        MATCH_PER_STREAM_OPT(apad, str, apad, oc, st);
47
+        if (apad) {
48
+            ost->apad = av_strdup(apad);
49
+            if (!ost->apad)
50
+                return AVERROR(ENOMEM);
51
+        }
52
53
 #if FFMPEG_OPT_MAP_CHANNEL
54
         /* check for channel mapping for this audio stream */
55
--
56
2.41.0
57
58