Prevents crash or interruption in text rendering if new option string contains invalid values.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -862,20 +862,49 @@ static int config_input(AVFilterLink *inlink) · 861 unmodified lines | |||
| 862 | 862 | ||
| 863 | static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags) | 863 | static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags) |
| 864 | { | 864 | { |
| 865 | DrawTextContext *s = ctx->priv; | 865 | DrawTextContext *old = ctx->priv; |
| 866 | DrawTextContext *new = NULL; | ||
| 867 | int ret; | ||
| 866 | 868 | ||
| 867 | if (!strcmp(cmd, "reinit")) { | 869 | if (!strcmp(cmd, "reinit")) { |
| 868 | int ret; | 870 | new = av_mallocz(sizeof(DrawTextContext)); |
| 871 | if (!new) | ||
| 872 | return AVERROR(ENOMEM); | ||
| 873 | |||
| 874 | new->class = &drawtext_class; | ||
| 875 | ret = av_opt_copy(new, old); | ||
| 876 | if (ret < 0) | ||
| 877 | goto fail; | ||
| 878 | |||
| 879 | ctx->priv = new; | ||
| 880 | ret = av_set_options_string(ctx, arg, "=", ":"); | ||
| 881 | if (ret < 0) { | ||
| 882 | ctx->priv = old; | ||
| 883 | goto fail; | ||
| 884 | } | ||
| 885 | |||
| 886 | ret = init(ctx); | ||
| 887 | if (ret < 0) { | ||
| 888 | uninit(ctx); | ||
| 889 | ctx->priv = old; | ||
| 890 | goto fail; | ||
| 891 | } | ||
| 892 | |||
| 893 | new->reinit = 1; | ||
| 894 | |||
| 895 | ctx->priv = old; | ||
| 869 | uninit(ctx); | 896 | uninit(ctx); |
| 870 | s->reinit = 1; | 897 | av_freep(old); |
| 871 | if ((ret = av_set_options_string(ctx, arg, "=", ":")) < 0) | 898 | |
| 872 | return ret; | 899 | ctx->priv = new; |
| 873 | if ((ret = init(ctx)) < 0) | ||
| 874 | return ret; | ||
| 875 | return config_input(ctx->inputs[0]); | 900 | return config_input(ctx->inputs[0]); |
| 876 | } | 901 | } else |
| 902 | return AVERROR(ENOSYS); | ||
| 877 | 903 | ||
| 878 | return AVERROR(ENOSYS); | 904 | fail: |
| 905 | av_log(ctx, AV_LOG_ERROR, "Failed to process command. Continuing with existing parameters.\n"); | ||
| 906 | av_freep(new); | ||
| 907 | return ret; | ||
| 879 | } | 908 | } |
| 880 | 909 | ||
| 881 | static int func_pict_type(AVFilterContext *ctx, AVBPrint *bp, | 910 | static int func_pict_type(AVFilterContext *ctx, AVBPrint *bp, |