diff mbox series

[FFmpeg-devel] libavformat/ffmetadecc.c: Fix Use-of-uninitialized-value

Message ID 20200820191452.471886-1-tfoucu@gmail.com
State Accepted
Commit 5cf439e72ec3432fc52f73badfd0b5ec90162ffa
Headers show
Series [FFmpeg-devel] libavformat/ffmetadecc.c: Fix Use-of-uninitialized-value
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Thierry Foucu Aug. 20, 2020, 7:14 p.m. UTC
Check the return value of sscanf as it can return -1(EOF), for example
when the first char in the line is 0x00
---
 libavformat/ffmetadec.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer Aug. 21, 2020, 9:12 p.m. UTC | #1
On Thu, Aug 20, 2020 at 12:14:52PM -0700, Thierry Foucu wrote:
> Check the return value of sscanf as it can return -1(EOF), for example
> when the first char in the line is 0x00
> ---
>  libavformat/ffmetadec.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/ffmetadec.c b/libavformat/ffmetadec.c
index 45c92f1ff6..0ea89fe3f3 100644
--- a/libavformat/ffmetadec.c
+++ b/libavformat/ffmetadec.c
@@ -101,19 +101,22 @@  static AVChapter *read_chapter(AVFormatContext *s)
     uint8_t line[256];
     int64_t start, end;
     AVRational tb = {1, 1e9};
+    int ret;
 
     get_line(s->pb, line, sizeof(line));
 
     if (sscanf(line, "TIMEBASE=%d/%d", &tb.num, &tb.den))
         get_line(s->pb, line, sizeof(line));
-    if (!sscanf(line, "START=%"SCNd64, &start)) {
+    ret = sscanf(line, "START=%"SCNd64, &start);
+    if (ret <= 0) {
         av_log(s, AV_LOG_ERROR, "Expected chapter start timestamp, found %s.\n", line);
         start = (s->nb_chapters && s->chapters[s->nb_chapters - 1]->end != AV_NOPTS_VALUE) ?
                  s->chapters[s->nb_chapters - 1]->end : 0;
     } else
         get_line(s->pb, line, sizeof(line));
 
-    if (!sscanf(line, "END=%"SCNd64, &end)) {
+    ret = sscanf(line, "END=%"SCNd64, &end);
+    if (ret <= 0) {
         av_log(s, AV_LOG_ERROR, "Expected chapter end timestamp, found %s.\n", line);
         end = AV_NOPTS_VALUE;
     }