You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
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. Reviewed-by: softworkz . <softworkz-at-hotmail.com@ffmpeg.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@ -874,8 +874,6 @@ static int init_graphprint(GraphPrintContext **pgpc, AVBPrint *target_buf)
|
|||||||
AVTextFormatContext *tfc = NULL;
|
AVTextFormatContext *tfc = NULL;
|
||||||
AVTextWriterContext *wctx = NULL;
|
AVTextWriterContext *wctx = NULL;
|
||||||
GraphPrintContext *gpc = NULL;
|
GraphPrintContext *gpc = NULL;
|
||||||
char *w_args = NULL;
|
|
||||||
char *w_name;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
init_sections();
|
init_sections();
|
||||||
@ -883,19 +881,7 @@ static int init_graphprint(GraphPrintContext **pgpc, AVBPrint *target_buf)
|
|||||||
|
|
||||||
av_bprint_init(target_buf, 0, AV_BPRINT_SIZE_UNLIMITED);
|
av_bprint_init(target_buf, 0, AV_BPRINT_SIZE_UNLIMITED);
|
||||||
|
|
||||||
if (!print_graphs_format)
|
const char *w_name = print_graphs_format ? print_graphs_format : "json";
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
text_formatter = avtext_get_formatter_by_name(w_name);
|
text_formatter = avtext_get_formatter_by_name(w_name);
|
||||||
if (!text_formatter) {
|
if (!text_formatter) {
|
||||||
@ -912,6 +898,9 @@ static int init_graphprint(GraphPrintContext **pgpc, AVBPrint *target_buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AVTextFormatOptions tf_options = { .show_optional_fields = -1 };
|
AVTextFormatOptions tf_options = { .show_optional_fields = -1 };
|
||||||
|
const char *w_args = print_graphs_format ? strchr(print_graphs_format, '=') : NULL;
|
||||||
|
if (w_args)
|
||||||
|
++w_args; // consume '='
|
||||||
ret = avtext_context_open(&tfc, text_formatter, wctx, w_args, sections, FF_ARRAY_ELEMS(sections), tf_options, NULL);
|
ret = avtext_context_open(&tfc, text_formatter, wctx, w_args, sections, FF_ARRAY_ELEMS(sections), tf_options, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -706,9 +706,12 @@ const AVTextFormatter *avtext_get_formatter_by_name(const char *name)
|
|||||||
{
|
{
|
||||||
formatters_register_all();
|
formatters_register_all();
|
||||||
|
|
||||||
for (int i = 0; registered_formatters[i]; i++)
|
for (int i = 0; registered_formatters[i]; i++) {
|
||||||
if (!strcmp(registered_formatters[i]->name, name))
|
const char *end;
|
||||||
|
if (av_strstart(name, registered_formatters[i]->name, &end) &&
|
||||||
|
(*end == '\0' || *end == '='))
|
||||||
return registered_formatters[i];
|
return registered_formatters[i];
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user