From 18a2b61b85346f9f45948af7e192863fb046b224 Mon Sep 17 00:00:00 2001 From: Christoph Hohmann Date: Sat, 12 Mar 2016 18:49:59 +0100 Subject: [PATCH] image-source: Fix reloading bug when stat fails (Note: This commit also modified text-freetype2) The implementation of get_modified_timestamp() did not check the return value of stat(), so in case the check fails the values in the stats structure can be any garbage on the stack and the value of stats.st_mtime can change on every call. This can trigger a reload of the image every second, even if the file was not actually modified. Closes jp9000/obs-studio#520 --- plugins/image-source/image-source.c | 3 ++- plugins/text-freetype2/text-functionality.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/image-source/image-source.c b/plugins/image-source/image-source.c index f8729663a..b962fa8a0 100644 --- a/plugins/image-source/image-source.c +++ b/plugins/image-source/image-source.c @@ -30,7 +30,8 @@ struct image_source { static time_t get_modified_timestamp(const char *filename) { struct stat stats; - stat(filename, &stats); + if (stat(filename, &stats) != 0) + return -1; return stats.st_mtime; } diff --git a/plugins/text-freetype2/text-functionality.c b/plugins/text-freetype2/text-functionality.c index 066675b7d..684a2a573 100644 --- a/plugins/text-freetype2/text-functionality.c +++ b/plugins/text-freetype2/text-functionality.c @@ -322,7 +322,8 @@ time_t get_modified_timestamp(char *filename) // stat is apparently terrifying and horrible, but we only call it once // every second at most. - stat(filename, &stats); + if (stat(filename, &stats) != 0) + return -1; return stats.st_mtime; }