From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oRNbs-0004ZO-Ho for mharc-grub-devel@gnu.org; Thu, 25 Aug 2022 20:54:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRNbr-0004ZC-3c for grub-devel@gnu.org; Thu, 25 Aug 2022 20:54:07 -0400 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]:42925) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oRNbp-0001Lh-0o for grub-devel@gnu.org; Thu, 25 Aug 2022 20:54:06 -0400 Received: by mail-qt1-x831.google.com with SMTP id x5so229646qtv.9 for ; Thu, 25 Aug 2022 17:54:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=Ixv9Bvmk6q/bOxwo9rSiQ0z7JmdOabSIfMD/qsIoN0s=; b=SwCzaQ6rU5BSWquBHeYCNSlu+zzf9xChCkQTvW+0vrLVgZ+rMR861tG7MsgM/DtVj3 gosb39kfOdSpu3QbIFWePyr6mSrESiddugz4+I84zKRHIAPjwOU6aXtNJFegu/0j1zfF W+slSyljLY26vRG4HukmQxTL+DVHN2Wa/Db+j1ILoCVXC0xzUgORimsTwbxej1qJt2N1 JTR2NF+CqqU91mwzQNtvePQxDco5v76zSKYxykniF6+OpjNKt3Je7qe7eGgqSEpqLTsA sATTIIMIhV3cb3AlUCfQ7EKtWbN2iMSH/u0Bplfj9Tc8VsMmDM6aYvZBVTlrmZuRnK1Y dCbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=Ixv9Bvmk6q/bOxwo9rSiQ0z7JmdOabSIfMD/qsIoN0s=; b=JFQKZYbhjgqGWLbqXHzGMKKzzf0eWHM/bC+FY4MbgqOgSmfykFUS1cHXUbnS/DFkH/ 12gL0niPdlhOW4oIh9ivDzEnTpPNMyBxEadnApNPmjJkMLFeqQ+BsYW9gkufbaar4DCc 2Z49OoS+QBDyFyJX89u8DVUCYbiIG0fwZ+nMBo19E2Zm/SHarlk4bmh+0pgW8mA9oMUP IYz5w8MOP6MQPXrvpOeHLZKhrU1kj5IHaVgE2eUONizeByI1fK56Ip4tFl92Evehiu/K 57gn/GbCcaA5t1VesjUSZIFqWXMfcK91w/ARBrdnIYK35N6+SV6qsjwxkDLuQ0CfxK/5 ziUw== X-Gm-Message-State: ACgBeo1ID/lzhBwqxoecraBmjCQl7fYRWAdiJVjOWbyemviDR/xOvVcq XpEgMYKzP69ulg983AbgG4IFp8jofAl8cA== X-Google-Smtp-Source: AA6agR69SASb3VhqUDl6/4aio4mHUKQ3hU67/G1teV2OMNquOJKIhG1Zkrko1GkKbJU09QmcifPc+A== X-Received: by 2002:a05:622a:c7:b0:343:2e72:8416 with SMTP id p7-20020a05622a00c700b003432e728416mr6063906qtw.92.1661475243558; Thu, 25 Aug 2022 17:54:03 -0700 (PDT) Received: from localhost.localdomain ([37.218.244.249]) by smtp.gmail.com with ESMTPSA id x8-20020a05620a258800b006bbc09af9f5sm710773qko.101.2022.08.25.17.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 17:54:03 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Glenn Washburn Subject: [PATCH v3] grub-core/kern/corecmd: Quote variable values when displayed by the set command Date: Thu, 25 Aug 2022 19:53:51 -0500 Message-Id: <20220826005351.360284-1-development@efficientek.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::831; envelope-from=development@efficientek.com; helo=mail-qt1-x831.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Aug 2022 00:54:07 -0000 Variable values may contain spaces at the end or newlines. However, when displayed without quotes this is not obvious and can lead to confusion as to the actual contents of variables. Also for some variables grub_env_get() returns a NULL pointer instead of a pointer to an empty string and previously would be printed as "var=(null)". Now such variables will be displayed as "var=''". Signed-off-by: Glenn Washburn --- v2->v3: cast away constness when assigning var to fix compiler error --- grub-core/kern/corecmd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/grub-core/kern/corecmd.c b/grub-core/kern/corecmd.c index fc54f43f2b..62d434ba9a 100644 --- a/grub-core/kern/corecmd.c +++ b/grub-core/kern/corecmd.c @@ -40,7 +40,10 @@ grub_core_cmd_set (struct grub_command *cmd __attribute__ ((unused)), { struct grub_env_var *env; FOR_SORTED_ENV (env) - grub_printf ("%s=%s\n", env->name, grub_env_get (env->name)); + { + val = (char *) grub_env_get (env->name); + grub_printf ("%s='%s'\n", env->name, val == NULL ? "" : val); + } return 0; } -- 2.34.1