avformat/nistspheredec: check sscanf() success before using the result
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 19 Dec 2013 19:48:51 +0000 (20:48 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 19 Dec 2013 20:46:47 +0000 (21:46 +0100)
Fixes use of uninitialized memory
Fixes: msan_uninit-mem_7f935c3c6c1a_7413_nist_pcms8.nist
Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavformat/nistspheredec.c

index c09df9c..76f65ec 100644 (file)
@@ -108,8 +108,11 @@ static int nist_read_header(AVFormatContext *s)
             sscanf(buffer, "%*s %*s %"SCNd32, &st->codec->bits_per_coded_sample);
         } else {
             char key[32], value[32];
-            sscanf(buffer, "%31s %*s %31s", key, value);
-            av_dict_set(&s->metadata, key, value, AV_DICT_APPEND);
+            if (sscanf(buffer, "%31s %*s %31s", key, value) == 3) {
+                av_dict_set(&s->metadata, key, value, AV_DICT_APPEND);
+            } else {
+                av_log(s, AV_LOG_ERROR, "Failed to parse '%s' as metadata\n", buffer);
+            }
         }
     }