[FFmpeg-devel,2/3] avutil/avstring: Fix av_match_name() with seperators in the name itself

Submitted by Michael Niedermayer on June 1, 2017, 11:44 a.m.

Details

Message ID 20170601114446.11358-2-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer June 1, 2017, 11:44 a.m.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavutil/avstring.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

wm4 June 1, 2017, 12:56 p.m.
On Thu,  1 Jun 2017 13:44:45 +0200
Michael Niedermayer <michael@niedermayer.cc> wrote:

> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavutil/avstring.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/libavutil/avstring.c b/libavutil/avstring.c
> index f03dd25141..c1348b3a13 100644
> --- a/libavutil/avstring.c
> +++ b/libavutil/avstring.c
> @@ -342,22 +342,28 @@ int av_escape(char **dst, const char *src, const char *special_chars,
>  
>  int av_match_name(const char *name, const char *names)
>  {
> -    const char *p;
> -    int len, namelen;
> +    const char *p, *namep;
> +    int len;
>  
>      if (!name || !names)
>          return 0;
>  
> -    namelen = strlen(name);
>      while (*names) {
>          int negate = '-' == *names;
>          p = strchr(names, ',');
>          if (!p)
>              p = names + strlen(names);
>          names += negate;
> -        len = FFMAX(p - names, namelen);
> -        if (!av_strncasecmp(name, names, len) || !strncmp("ALL", names, FFMAX(3, p - names)))
> -            return !negate;
> +        for (namep = name; namep && *namep; ) {
> +            const char *next_namep = strchr(namep, ',');
> +            int namelen = next_namep ? next_namep - namep : strlen(namep);
> +
> +            len = FFMAX(p - names, namelen);
> +            if (!av_strncasecmp(namep, names, len) || !strncmp("ALL", names, FFMAX(3, p - names)))
> +                return !negate;
> +            namep = next_namep;
> +            namep += !!namep;
> +        }
>          names = p + (*p == ',');
>      }
>      return 0;

The doxygen doesn't specify that name can be comma separated. Thus it's
an API break, as callers might pass names with commas in it, and expect
it not to be matched.

Patch hide | download patch | download mbox

diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index f03dd25141..c1348b3a13 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -342,22 +342,28 @@  int av_escape(char **dst, const char *src, const char *special_chars,
 
 int av_match_name(const char *name, const char *names)
 {
-    const char *p;
-    int len, namelen;
+    const char *p, *namep;
+    int len;
 
     if (!name || !names)
         return 0;
 
-    namelen = strlen(name);
     while (*names) {
         int negate = '-' == *names;
         p = strchr(names, ',');
         if (!p)
             p = names + strlen(names);
         names += negate;
-        len = FFMAX(p - names, namelen);
-        if (!av_strncasecmp(name, names, len) || !strncmp("ALL", names, FFMAX(3, p - names)))
-            return !negate;
+        for (namep = name; namep && *namep; ) {
+            const char *next_namep = strchr(namep, ',');
+            int namelen = next_namep ? next_namep - namep : strlen(namep);
+
+            len = FFMAX(p - names, namelen);
+            if (!av_strncasecmp(namep, names, len) || !strncmp("ALL", names, FFMAX(3, p - names)))
+                return !negate;
+            namep = next_namep;
+            namep += !!namep;
+        }
         names = p + (*p == ',');
     }
     return 0;