[PATCH 07/10] debuginfod: Handle not being able to fopen interval_path.

Mark Wielaard mark@klomp.org
Tue Jun 16 22:25:36 GMT 2020


Although we check for and/or create the interval_path right before,
there is still a possibility that the fopen call fails. Handle that
as if the file is unreadable.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 debuginfod/ChangeLog           | 5 +++++
 debuginfod/debuginfod-client.c | 9 +++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index bc3bce32..66511a3f 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,8 @@
+2020-06-16  Mark Wielaard  <mark@klomp.org>
+
+	* debuginfod-client.c (debuginfod_clean_cache): Handle failing
+	fopen (interval_path).
+
 2020-03-29  Mark Wielaard  <mark@klomp.org>
 
 	* debuginfod-client.c (debuginfod_add_http_header): Check header
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index a7dfbfb1..0cfc6dfc 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -244,9 +244,14 @@ debuginfod_clean_cache(debuginfod_client *c,
   /* Check timestamp of interval file to see whether cleaning is necessary.  */
   time_t clean_interval;
   interval_file = fopen(interval_path, "r");
-  if (fscanf(interval_file, "%ld", &clean_interval) != 1)
+  if (interval_file)
+    {
+      if (fscanf(interval_file, "%ld", &clean_interval) != 1)
+        clean_interval = cache_clean_default_interval_s;
+      fclose(interval_file);
+    }
+  else
     clean_interval = cache_clean_default_interval_s;
-  fclose(interval_file);
 
   if (time(NULL) - st.st_mtime < clean_interval)
     /* Interval has not passed, skip cleaning.  */
-- 
2.18.4



More information about the Elfutils-devel mailing list