Browse Source

avutil/avstring: Fix bug and undefined behavior in av_strncasecmp()

The function in case of n=0 would read more bytes than 0.
The end pointer could be beyond the allocated space, which
is undefined.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 6f0e9a8634)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
tags/n4.0.5
Michael Niedermayer 6 years ago
parent
commit
32c200d49d
1 changed files with 3 additions and 2 deletions
  1. +3
    -2
      libavutil/avstring.c

+ 3
- 2
libavutil/avstring.c View File

@@ -222,12 +222,13 @@ int av_strcasecmp(const char *a, const char *b)

int av_strncasecmp(const char *a, const char *b, size_t n)
{
const char *end = a + n;
uint8_t c1, c2;
if (n <= 0)
return 0;
do {
c1 = av_tolower(*a++);
c2 = av_tolower(*b++);
} while (a < end && c1 && c1 == c2);
} while (--n && c1 && c1 == c2);
return c1 - c2;
}



Loading…
Cancel
Save