From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id 982FD3858D35 for ; Tue, 16 Jun 2020 22:26:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 982FD3858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mark@klomp.org Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 7DE5D317FC14; Wed, 17 Jun 2020 00:25:59 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 28195402412B; Wed, 17 Jun 2020 00:25:58 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH 07/10] debuginfod: Handle not being able to fopen interval_path. Date: Wed, 17 Jun 2020 00:25:36 +0200 Message-Id: <20200616222539.29109-7-mark@klomp.org> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200616222539.29109-1-mark@klomp.org> References: <20200616222539.29109-1-mark@klomp.org> X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Jun 2020 22:26:01 -0000 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 --- 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 + + * debuginfod-client.c (debuginfod_clean_cache): Handle failing + fopen (interval_path). + 2020-03-29 Mark Wielaard * 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