From patchwork Fri Feb 23 20:30:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 60938 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 20ED427BBEA; Fri, 23 Feb 2024 21:58:34 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 395A927BBE2 for ; Fri, 23 Feb 2024 21:58:28 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rddYH-0006Zu-4x; Fri, 23 Feb 2024 16:57:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rdctQ-00059H-T1 for guix-patches@gnu.org; Fri, 23 Feb 2024 16:15:41 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdctP-0003Py-K4 for guix-patches@gnu.org; Fri, 23 Feb 2024 16:15:39 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rdctm-00012w-IP for guix-patches@gnu.org; Fri, 23 Feb 2024 16:16:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#69340] [PATCH] system, home: Validate =?utf-8?b?4oCYc2Vydmlj?= =?utf-8?b?ZXPigJk=?= field value. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: , guix-patches@gnu.org Resent-Date: Fri, 23 Feb 2024 21:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 69340 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 69340@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , ( , Andrew Tropin , Ludovic =?utf-8?q?Court=C3=A8s?= X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: ( , Andrew Tropin , Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by submit@debbugs.gnu.org id=B.17087229273919 (code B ref -1); Fri, 23 Feb 2024 21:16:02 +0000 Received: (at submit) by debbugs.gnu.org; 23 Feb 2024 21:15:27 +0000 Received: from localhost ([127.0.0.1]:43860 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdct8-00010q-As for submit@debbugs.gnu.org; Fri, 23 Feb 2024 16:15:27 -0500 Received: from lists.gnu.org ([209.51.188.17]:44718) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdct3-00010M-1j for submit@debbugs.gnu.org; Fri, 23 Feb 2024 16:15:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rdcC0-000757-DI for guix-patches@gnu.org; Fri, 23 Feb 2024 15:30:48 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rdcBz-0002ns-BH; Fri, 23 Feb 2024 15:30:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=UO+REeyKvVv8buh5KPDFicZzbpQxs8iFjbfpHcLQ8Us=; b=Jml4xFrWy+r7dw bYaVshGDZMz1+wo2TlJ0ugWupHNf3pzxirov26TMhDwVUu0R/6CMNgwP/YKT7pua97TeoDaQP4eL3 7FOyk1fftfyXJ/uwA33FhD5NaeS4m4504K356NbpPeyJOT87tdWTotqBSYVFxZ2yRCeZADTdICwfk UCDWOgE44CYMYB4ILOx8CRCH62Z2ByxQtKdGRnmGcZxQcJt2Jcn0+BkXkVYpUvuBCCXuMVfTXAloE 3PL1abn88lCruFYA2R8QOW1H3A97wrJSM3zS0fTqUXjqAhvwgVYhzs/fHRL3cD5VMGt2PrylL5DtK VEuXIMgOxGejGF6eX3sw==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Fri, 23 Feb 2024 21:30:34 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches This guides newcomers who might stick a single (service …) form in this field. * gnu/services.scm (validate-service-list): New macro. (%validate-service-list): New procedure. * gnu/system.scm ()[services]: Add ‘sanitize’. * gnu/home.scm ()[services]: Add ‘sanitize’. Change-Id: I9e29bd9a078e87b627ab766fd669ba9de79f8473 --- gnu/home.scm | 5 +++-- gnu/services.scm | 19 ++++++++++++++++++- gnu/system.scm | 5 +++-- 3 files changed, 24 insertions(+), 5 deletions(-) Hi! The goal here is to recognize this likely pitfall for newcomers and to guide them. Thoughts? Ludo'. base-commit: b386c11e7804e0b577411d930b60f1e0a4a0382c diff --git a/gnu/home.scm b/gnu/home.scm index 2fefe7ba53..b390c8d534 100644 --- a/gnu/home.scm +++ b/gnu/home.scm @@ -1,6 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021 Andrew Tropin -;;; Copyright © 2022 Ludovic Courtès +;;; Copyright © 2022, 2024 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -67,7 +67,8 @@ (define-record-type* home-environment this-home-environment))) (services home-environment-user-services - (default '())) + (default '()) + (sanitize validate-service-list)) (location home-environment-location ; (default (and=> (current-source-location) diff --git a/gnu/services.scm b/gnu/services.scm index 59481af10f..88593e8091 100644 --- a/gnu/services.scm +++ b/gnu/services.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2015-2023 Ludovic Courtès +;;; Copyright © 2015-2024 Ludovic Courtès ;;; Copyright © 2016 Chris Marusich ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen ;;; Copyright © 2020, 2021 Ricardo Wurmus @@ -91,6 +91,8 @@ (define-module (gnu services) for-home for-home? + validate-service-list + service-error? missing-value-service-error? missing-value-service-error-type @@ -1271,4 +1273,19 @@ (define-syntax-rule (for-home exp ...) (syntax-parameterize ((for-home? (identifier-syntax #t))) exp ...)) +(define-with-syntax-properties (validate-service-list (value properties)) + (%validate-service-list value properties)) + +(define (%validate-service-list value properties) + (match value + (((? service?) ...) value) + (_ + (raise + (make-compound-condition + (condition + (&error-location + (location (source-properties->location properties)))) + (formatted-message + (G_ "'services' field must contain a list of services"))))))) + ;;; services.scm ends here. diff --git a/gnu/system.scm b/gnu/system.scm index aede35775e..aef81d8ccf 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013-2022 Ludovic Courtès +;;; Copyright © 2013-2022, 2024 Ludovic Courtès ;;; Copyright © 2015 Mark H Weaver ;;; Copyright © 2015, 2016 Alex Kost ;;; Copyright © 2016 Chris Marusich @@ -294,7 +294,8 @@ (define-record-type* operating-system this-operating-system))) (services operating-system-user-services ; list of services (thunked) ;allow for system-dependent services - (default %base-services)) + (default %base-services) + (sanitize validate-service-list)) (pam-services operating-system-pam-services ; list of PAM services (default (base-pam-services)))