From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id AN1VBMD8kGK6FwEAbAwnHQ (envelope-from ) for ; Fri, 27 May 2022 18:30:56 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 0K9PA8D8kGIJnQAAG6o9tA (envelope-from ) for ; Fri, 27 May 2022 18:30:56 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 84D8BA46B for ; Fri, 27 May 2022 18:30:55 +0200 (CEST) Received: from localhost ([::1]:36322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nucrV-0004i5-2s for larch@yhetil.org; Fri, 27 May 2022 12:30:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nucC2-0002es-9H for guix-patches@gnu.org; Fri, 27 May 2022 11:48:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:41747) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nucC1-0004dx-WB for guix-patches@gnu.org; Fri, 27 May 2022 11:48:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nucC1-0006kJ-Q8 for guix-patches@gnu.org; Fri, 27 May 2022 11:48:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55673] [PATCH v2] cache: Catch valid integer for 'last-expiry-cleanup'. References: <20220527082519.501697-1-zimon.toutoune@gmail.com> In-Reply-To: <20220527082519.501697-1-zimon.toutoune@gmail.com> Resent-From: zimoun Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 27 May 2022 15:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55673 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55673@debbugs.gnu.org Cc: zimoun Received: via spool by 55673-submit@debbugs.gnu.org id=B55673.165366643425730 (code B ref 55673); Fri, 27 May 2022 15:48:01 +0000 Received: (at 55673) by debbugs.gnu.org; 27 May 2022 15:47:14 +0000 Received: from localhost ([127.0.0.1]:35644 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nucBF-0006gv-KW for submit@debbugs.gnu.org; Fri, 27 May 2022 11:47:13 -0400 Received: from mail-wr1-f41.google.com ([209.85.221.41]:36800) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nucBC-0006gh-OG for 55673@debbugs.gnu.org; Fri, 27 May 2022 11:47:12 -0400 Received: by mail-wr1-f41.google.com with SMTP id u3so6381914wrg.3 for <55673@debbugs.gnu.org>; Fri, 27 May 2022 08:47:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/9MTsnm05Ku6jeO1qnRc6AdRgafy7KjBcCVWHGD8mS8=; b=S6Pgm/yRA500QS4V0mjL/ZTUkIwxZJKi22mFJDSTKxhWM4xMDB5Wsk0ufN8G9QtQFS CoFz0fISG7dJr8ENWtE9XTd6srGAEL4/cf/lEtQJ++o3xHmOZbQGVEFCgEBfCqvKNpul yCNs25HopMhZoOxSJxH2948AoZVP6Kps+JtPKyWXqzWO/0K8gQJBjbyHFGzCzy5B9dyS TK78to62UHUq3RDsV2aiDawIapmnqkHt/k0HxQimnIN9s/DF0e6nUWEKuzYZTrIxS/Kn zZR8OtJoWf+mxxUUpVKtOKJtbjjRZM8O0aX3v3B2ZYDrdfFSoeYXsVfLgZaznbhnAV6S BfDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/9MTsnm05Ku6jeO1qnRc6AdRgafy7KjBcCVWHGD8mS8=; b=WNwKFlEFB1iQHckdtEgqAOCy1sJCn5WoWrB9rmjGPIooOA+cRat64IDWqpDWHI+tY8 W2K8rc1yho23N2w4Wiyi4clOFzkG3nTK4aTmxJcfKiKv/W3efobWJu2Ssq+Tlo9M1jB/ s5AKJj4wJCf6Dk3SRSNd4s9msVxlZTnD8sYmrUZtuP1jsusqij1ASFdVjG9NrybYmNpY Y3xitQPYo2VMnecUqufQUN4uiIsS9R2VTyEY+VKKQe7/8nL3Jj/W5+wnAd7kFnCcGCIx nLfrE7jEIfL+Nqtwewms2Y8iiNbkDVHmaTJ8xu0YiEXrkGVH/xIAf9XZbDgHqBBoacbK /pzQ== X-Gm-Message-State: AOAM533AyghmwRMsWOV2A3utdu6JM0v9PIdFE1tRrZvNQDsO/QI18zbf FGWLOp2Tgju0bdGP1yU8LsThdb6fIYg= X-Google-Smtp-Source: ABdhPJwI4fZflGnsTR+3rTM7oJQsyulxXWsDu/mf1k50/ZaTmseG/zf/VNiLcAP3NC79ULXC5a7NaA== X-Received: by 2002:a5d:588d:0:b0:20f:f290:ed83 with SMTP id n13-20020a5d588d000000b0020ff290ed83mr14866356wrf.588.1653666424488; Fri, 27 May 2022 08:47:04 -0700 (PDT) Received: from localhost.localdomain ([193.48.40.241]) by smtp.gmail.com with ESMTPSA id y4-20020a056000168400b0020fd392df33sm2069044wrd.29.2022.05.27.08.47.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 May 2022 08:47:04 -0700 (PDT) From: zimoun Date: Fri, 27 May 2022 17:46:52 +0200 Message-Id: <20220527154652.700549-1-zimon.toutoune@gmail.com> X-Mailer: git-send-email 2.36.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1653669055; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=/9MTsnm05Ku6jeO1qnRc6AdRgafy7KjBcCVWHGD8mS8=; b=lQgBda7oIAOuycW4CdaPtMEY6xiwbKF4/9iaKdAKVlDOTvXDBYJDcJL2z91hwQyT6Y7D5Y DjUn6TK4zglqYPhSvKFJCxk5OtuXfarPZzF3jZ8LqCb1ogPe9S9GdaxOnMbqSYLKDOjv0A nDMWpXCyRr6wRy3bz9x9Nh4ctBM5uibvfgf9CDtnrjOMBJO7221FlNQjnE6eIGLaomSbJG smEoZaG5DRaSD6Opvw1ay36wbsoMb0DGw92Hb2vuI1DfZjBpVugBAedPrnk8J1hG6GsDL7 VH1UcaFAdhNjO70Z9lcpjteWxwRsNYmh0c3iD9NlNuY/8uTlcZfTWtzXuWzxSA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1653669055; a=rsa-sha256; cv=none; b=QvvWWvbvsn0eZxIx8ck/Ok9U6hxT1hcHVocYNnneI6RzLd4ZQDbCTsbv2pwZotaY7kZqyj v6rNLBrdCqEAN/8KtSvau3vMDzRsfHceJMy1ZrYmc5fTq8l0nBE4z9ejUJ27EReb8Ka1WL bLSycEco+kF8czjvBFLy+uFoRIk59pMryTLF+78GQPnVURrzjS5db6DHsnmHy2C+H+DnGs WVaQaLfice8fDxAfHWFBcWphpM9c93l9JN+RhTxTWPxs7Wn9pqE4V1p1eSSBTX6+VRwS8d UkmeEswXiSMNZH4Evk3zyxym2GXBfs1HkfFihw+HRwRVfyC+8I6Sr0UWVvxDqg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="S6Pgm/yR"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 4.66 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="S6Pgm/yR"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 84D8BA46B X-Spam-Score: 4.66 X-Migadu-Scanner: scn0.migadu.com X-TUID: LOSzwBrzP7rd Fixes . * guix/cache.scm (maybe-remove-expired-cache-entries)[last-expiry-date]: Check if the date is a valid integer. * tests/cache.scm: Test it. --- guix/cache.scm | 16 ++++++++++++---- tests/cache.scm | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/guix/cache.scm b/guix/cache.scm index 51009809bd..13f9e4a439 100644 --- a/guix/cache.scm +++ b/guix/cache.scm @@ -20,6 +20,7 @@ (define-module (guix cache) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) #:use-module (ice-9 match) + #:use-module ((ice-9 textual-ports) #:select (get-string-all)) #:export (obsolete? delete-file* file-expiration-time @@ -91,10 +92,17 @@ (define expiry-file (string-append cache "/last-expiry-cleanup")) (define last-expiry-date - (catch 'system-error - (lambda () - (call-with-input-file expiry-file read)) - (const 0))) + (let ((value (catch 'system-error + (lambda () + (call-with-input-file expiry-file get-string-all)) + (const "0")))) + (catch #t ; Handle value out of range (e.g., 1234567890 -> 12E4567890) + (lambda () + ;; Handle empty or corrupted 'expiry-file' when 'write' below is + ;; interrupted before being complete (e.g., SIGINT with C-c) or when + ;; the filesystem crashes. + (or (string->number value) 0)) + (const 0)))) (when (obsolete? last-expiry-date now cleanup-period) (remove-expired-cache-entries (cache-entries cache) diff --git a/tests/cache.scm b/tests/cache.scm index 80b44d69aa..bd6fd64a22 100644 --- a/tests/cache.scm +++ b/tests/cache.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017, 2020 Ludovic Courtès +;;; Copyright © 2022 Simon Tournier ;;; ;;; This file is part of GNU Guix. ;;; @@ -74,6 +75,27 @@ (define-syntax-rule (test-cache-cleanup cache exp ...) (lambda (port) (display 0 port))))) +(test-equal "maybe-remove-expired-cache-entries, empty cache" + '("a" "b" "c") + (test-cache-cleanup cache + (call-with-output-file (string-append cache "/last-expiry-cleanup") + (lambda (port) + (display "" port))))) + +(test-equal "maybe-remove-expired-cache-entries, corrupted cache" + '("a" "b" "c") + (test-cache-cleanup cache + (call-with-output-file (string-append cache "/last-expiry-cleanup") + (lambda (port) + (display "1\"34657890" port))))) + +(test-equal "maybe-remove-expired-cache-entries, corrupted cache of out range" + '("a" "b" "c") + (test-cache-cleanup cache + (call-with-output-file (string-append cache "/last-expiry-cleanup") + (lambda (port) + (display "12E4567890" port))))) + (test-end "cache") ;;; Local Variables: base-commit: 38bf6c7d0cb588e8d4546db7d2e0bae2ec25183d -- 2.36.0