From f33af4ef4913f37458b89f19ec7fb71ae4b39978 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 30 May 2025 16:02:08 +0200 Subject: [PATCH 01/11] fftools/graph/graphprint: Fix races when initializing graphprint Setting print_graphs_format (in case no -print_graphs_format option was specified) is racy, as is using av_strtok() to split it. Both have been removed. Notice that using av_strtok() was destructive: In the absence of races the options would only have been applied for the first initialization. Signed-off-by: Andreas Rheinhardt --- fftools/graph/graphprint.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/fftools/graph/graphprint.c b/fftools/graph/graphprint.c index 852a8f6c0c..b67de3d8c1 100644 --- a/fftools/graph/graphprint.c +++ b/fftools/graph/graphprint.c @@ -875,8 +875,6 @@ static int init_graphprint(GraphPrintContext **pgpc, AVBPrint *target_buf) AVTextFormatContext *tfc = NULL; AVTextWriterContext *wctx = NULL; GraphPrintContext *gpc = NULL; - char *w_args = NULL; - char *w_name; int ret; init_sections(); @@ -884,19 +882,7 @@ static int init_graphprint(GraphPrintContext **pgpc, AVBPrint *target_buf) av_bprint_init(target_buf, 0, AV_BPRINT_SIZE_UNLIMITED); - if (!print_graphs_format) - print_graphs_format = av_strdup("json"); - if (!print_graphs_format) { - ret = AVERROR(ENOMEM); - goto fail; - } - - w_name = av_strtok(print_graphs_format, "=", &w_args); - if (!w_name) { - av_log(NULL, AV_LOG_ERROR, "No name specified for the filter graph output format\n"); - ret = AVERROR(EINVAL); - goto fail; - } + const char *w_name = print_graphs_format ? print_graphs_format : "json"; text_formatter = avtext_get_formatter_by_name(w_name); if (!text_formatter) { @@ -913,6 +899,7 @@ static int init_graphprint(GraphPrintContext **pgpc, AVBPrint *target_buf) } AVTextFormatOptions tf_options = { .show_optional_fields = -1 }; + const char *w_args = print_graphs_format ? strchr(print_graphs_format, '=') : NULL; ret = avtext_context_open(&tfc, text_formatter, wctx, w_args, sections, FF_ARRAY_ELEMS(sections), tf_options, NULL); if (ret < 0) { goto fail; -- 2.45.2