[FFmpeg-cvslog] lavf: Check the return value of strftime

Martin Storsjö git at videolan.org
Sun Oct 26 02:25:24 CET 2014


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Fri Oct 24 10:43:20 2014 +0300| [9dcf2397219ca796f0fafce2a703770d6fd09920] | committer: Martin Storsjö

lavf: Check the return value of strftime

If the buffer provided to strftime is too small, the buffer contents
are indeterminate - it does not guarantee actually null terminating
the buffer.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9dcf2397219ca796f0fafce2a703770d6fd09920
---

 libavformat/mov.c    |    4 ++--
 libavformat/mxfdec.c |    3 ++-
 libavformat/wtv.c    |   21 ++++++++++++---------
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index efc9314..a5b39f2 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -743,8 +743,8 @@ static void mov_metadata_creation_time(AVDictionary **metadata, time_t time)
         time -= 2082844800;  /* seconds between 1904-01-01 and Epoch */
         ptm = gmtime(&time);
         if (!ptm) return;
-        strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", ptm);
-        av_dict_set(metadata, "creation_time", buffer, 0);
+        if (strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", ptm))
+            av_dict_set(metadata, "creation_time", buffer, 0);
     }
 }
 
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 9aedd47..ff88f91 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -1735,7 +1735,8 @@ static int mxf_timestamp_to_str(uint64_t timestamp, char **str)
     *str = av_mallocz(32);
     if (!*str)
         return AVERROR(ENOMEM);
-    strftime(*str, 32, "%Y-%m-%d %H:%M:%S", &time);
+    if (!strftime(*str, 32, "%Y-%m-%d %H:%M:%S", &time))
+        str[0] = '\0';
 
     return 0;
 }
diff --git a/libavformat/wtv.c b/libavformat/wtv.c
index fa864e8..90984cf 100644
--- a/libavformat/wtv.c
+++ b/libavformat/wtv.c
@@ -429,9 +429,10 @@ static void filetime_to_iso8601(char *buf, int buf_size, int64_t value)
 {
     time_t t = (value / 10000000LL) - 11644473600LL;
     struct tm *tm = gmtime(&t);
-    if (tm)
-        strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", tm);
-    else
+    if (tm) {
+        if (!strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", tm))
+            buf[0] = '\0';
+    } else
         buf[0] = '\0';
 }
 
@@ -442,9 +443,10 @@ static void crazytime_to_iso8601(char *buf, int buf_size, int64_t value)
 {
     time_t t = (value / 10000000LL) - 719162LL*86400LL;
     struct tm *tm = gmtime(&t);
-    if (tm)
-        strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", tm);
-    else
+    if (tm) {
+        if (!strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", tm))
+            buf[0] = '\0';
+    } else
         buf[0] = '\0';
 }
 
@@ -455,9 +457,10 @@ static void oledate_to_iso8601(char *buf, int buf_size, int64_t value)
 {
     time_t t = 631112400LL + 86400*av_int2double(value);
     struct tm *tm = gmtime(&t);
-    if (tm)
-        strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", tm);
-    else
+    if (tm) {
+        if (!strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", tm))
+            buf[0] = '\0';
+    } else
         buf[0] = '\0';
 }
 



More information about the ffmpeg-cvslog mailing list