[FFmpeg-devel] [PATCH v2 32/33] avdevice/dshow: prevent NULL access

Diederick Niehorster dcnieho at gmail.com
Fri Jun 11 23:31:03 EEST 2021


list_options true would crash when both a video and an audio device were
specified as input. Crash would occur on line 1618 (in this new rev)
because ctx->device_unique_name[otherDevType] would be NULL

Signed-off-by: Diederick Niehorster <dcnieho at gmail.com>
---
 libavdevice/dshow.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 92cfaa062d..d3937df41a 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -1516,9 +1516,9 @@ dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum,
     if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_unique_name, NULL)) < 0)
         return r;
     ctx->device_filter[devtype] = device_filter;
+    ctx->device_unique_name[devtype] = device_unique_name;
     if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, ranges ? &device_pin : NULL, ranges, query_type)) < 0)
         return r;
-    av_freep(&device_unique_name);
     return 0;
 }
 
@@ -1578,7 +1578,8 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum,
             goto error;
         }
     }
-        if (ctx->device_filter[otherDevType]) {
+    
+    if (ctx->device_filter[otherDevType]) {
         // avoid adding add two instances of the same device to the graph, one for video, one for audio
         // a few devices don't support this (could also do this check earlier to avoid double crossbars, etc. but they seem OK)
         if (strcmp(device_filter_unique_name, ctx->device_unique_name[otherDevType]) == 0) {
@@ -2040,6 +2041,7 @@ static int dshow_read_header(AVFormatContext *avctx)
                 }
             }
         }
+        // don't exit yet, allow it to list crossbar options in dshow_open_device
     }
     ctx->is_running = 0;
     if (ctx->device_name[VideoDevice]) {
-- 
2.28.0.windows.1



More information about the ffmpeg-devel mailing list