[FFmpeg-devel] [PATCH 3/6] Make av_parse_expr() fail if there are trailing chars at the end of the provided expression that have not been parsed.

Stefano Sabatini stefano.sabatini-lala
Sun Jun 13 00:40:50 CEST 2010


On date Sunday 2010-06-13 00:38:43 +0200, Stefano Sabatini encoded:
> ---
>  libavutil/eval.c |    8 +++++++-
>  1 files changed, 7 insertions(+), 1 deletions(-)
> 
> diff --git a/libavutil/eval.c b/libavutil/eval.c
> index 5506822..def3def 100644
> --- a/libavutil/eval.c
> +++ b/libavutil/eval.c
> @@ -451,6 +451,7 @@ int av_parse_expr(AVExpr **expr, const char *s,
>      AVExpr *e = NULL;
>      char *w = av_malloc(strlen(s) + 1);
>      char *wp = w;
> +    const char *s0 = s;
>      int ret = 0;
>  
>      if (!w)
> @@ -470,9 +471,14 @@ int av_parse_expr(AVExpr **expr, const char *s,
>      p.func2_names = func2_names;
>      p.log_offset = log_offset;
>      p.log_ctx    = log_ctx;
> -
>      if ((ret = parse_expr(&e, &p)) < 0)
>          goto end;
> +    if (*p.s) {
> +        av_log(log_ctx, AV_LOG_ERROR+log_offset,
> +               " Invalid chars '%s' at the end of expression '%s'\n", p.s, s0);
> +        ret = AVERROR(EINVAL);
> +        goto end;
> +    }
>      if (!verify_expr(e)) {
>          av_free_expr(e);
>          ret = AVERROR(EINVAL);

Test result after this:

Evaluating ''
[Eval @ 0xbfe6d6e0]Undefined constant or missing '(' in ''
'' -> nan
Evaluating '1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)'
'1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)' -> 12.700000
Evaluating '80G/80Gi1k'
 Invalid chars '1k' at the end of expression '80G/80Gi1k'
'80G/80Gi1k' -> nan
Evaluating '1Gi'
'1Gi' -> 1073741824.000000
Evaluating '1gi'
 Invalid chars 'gi' at the end of expression '1gi'
'1gi' -> nan
Evaluating '1GiFoo'
 Invalid chars 'Foo' at the end of expression '1GiFoo'
'1GiFoo' -> nan
Evaluating '1k+1k'
'1k+1k' -> 2000.000000
Evaluating '1Gi*3foo'
 Invalid chars 'oo' at the end of expression '1Gi*3foo'
'1Gi*3foo' -> nan
Evaluating 'foo'
[Eval @ 0xbfe6d6e0]Undefined constant or missing '(' in 'foo'
'foo' -> nan
Evaluating 'foo('
[Eval @ 0xbfe6d6e0]Undefined constant or missing '(' in ''
'foo(' -> nan
Evaluating 'foo()'
[Eval @ 0xbfe6d6e0]Undefined constant or missing '(' in ')'
'foo()' -> nan
Evaluating 'foo)'
[Eval @ 0xbfe6d6e0]Undefined constant or missing '(' in 'foo)'
'foo)' -> nan
Evaluating 'sin'
[Eval @ 0xbfe6d6e0]Undefined constant or missing '(' in 'sin'
'sin' -> nan
Evaluating 'sin('
[Eval @ 0xbfe6d6e0]Undefined constant or missing '(' in ''
'sin(' -> nan
Evaluating 'sin()'
[Eval @ 0xbfe6d6e0]Undefined constant or missing '(' in ')'
'sin()' -> nan
Evaluating 'sin)'
[Eval @ 0xbfe6d6e0]Undefined constant or missing '(' in 'sin)'
'sin)' -> nan
Evaluating 'sin 10'
[Eval @ 0xbfe6d6e0]Undefined constant or missing '(' in 'sin10'
'sin 10' -> nan
Evaluating 'sin(1,2,3)'
[Eval @ 0xbfe6d6e0]Missing ')' or too many args in 'sin(1,2,3)'
'sin(1,2,3)' -> nan
Evaluating 'sin(1 )'
'sin(1 )' -> 0.841471
Evaluating '1'
'1' -> 1.000000
Evaluating '1foo'
 Invalid chars 'oo' at the end of expression '1foo'
'1foo' -> nan
Evaluating 'bar + PI + E + 100f*2 + foo'
[Eval @ 0xbfe6d6e0]Undefined constant or missing '(' in 'bar+PI+E+100f*2+foo'
'bar + PI + E + 100f*2 + foo' -> nan
Evaluating 'foo(1, 2)'
[Eval @ 0xbfe6d6e0]Unknown function in 'foo(1,2)'
'foo(1, 2)' -> nan
Evaluating '1gi'
 Invalid chars 'gi' at the end of expression '1gi'
'1gi' -> nan
Evaluating '1Gi'
'1Gi' -> 1073741824.000000

Regards.
-- 
FFmpeg = Funny Fast Magic Puristic Evil Guru



More information about the ffmpeg-devel mailing list