From patchwork Thu Sep 12 10:41:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Liddicott X-Patchwork-Id: 49013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 271DBEEB58A for ; Thu, 12 Sep 2024 10:41:52 +0000 (UTC) Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) by mx.groups.io with SMTP id smtpd.web11.45127.1726137702748321222 for ; Thu, 12 Sep 2024 03:41:43 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@liddicott-com.20230601.gappssmtp.com header.s=20230601 header.b=itU10g+h; spf=none, err=SPF record not found (domain: liddicott.com, ip: 209.85.208.50, mailfrom: sam@liddicott.com) Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5c4146c7d5dso847908a12.3 for ; Thu, 12 Sep 2024 03:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=liddicott-com.20230601.gappssmtp.com; s=20230601; t=1726137700; x=1726742500; darn=lists.openembedded.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=nbU+dnHXSuguPbijYZSxie+4U3i5coE72akHkAlncZM=; b=itU10g+hnCDpmRqBPflEr19agdjw7jjv0Vg9BUfmxvqRMRjGsuG1Y4fJQycGAn54m0 pM6g2TxpaPNKIiFlxzskcZaj96/W9j3jxddygK2Cve9mhDyIQ5fPCMHOnTmvIR8crkac LqVVpnqz2f6QVYFJ4Cqrgjq7uNQf3dJjHs9twTb97zcbkLn3+J0sFsD1uKFJRVddu7Lh V56CRjUCWK29osjvl1hCeCec4dJRDwIZVEsLRdkxxyEIRDhxRZgrT/KPTJfjOSGKiM0d kosblRVjrP5ez0ZHE88x7gBhPIEfRXkRxEUiU1uY18fXQ5fQewqLA1AlfxVi+JYHn6J/ r0yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726137700; x=1726742500; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=nbU+dnHXSuguPbijYZSxie+4U3i5coE72akHkAlncZM=; b=bXy+wDRZEoEkEVFCzD/lQ6rogJzJUm1dMSdfqMtF98zloBCcJL8IEpBIvc737E6T5x MHaFSM27zkZuaQk9yzMt8p1Mgk2Ph8r07Z4Y8Wo5PaaBUlo0Wb3Ie3mLeyVynfK/fMej kWZZCsaSLNqBBt3iai+Fw2B2AcNe+f4qZ1d6M/kYn2p6hbK+AsFTA11b5789hrjoYyoX YoGWSzRcVwFclkVZo34OW0puWa4o9RCcy+ROaERFV3s2vQl260RbJFytoQkXQiYfew1H s0LFrUoWEFXW/G34o+iF5aBqXIYtjPH3ULmFHNbcBFqdTxo0ni+9Vc5eOn6Z3lmHGDzD BX5g== X-Gm-Message-State: AOJu0Yzpp1h6MC/oUKSzV0GaBkzuFK3y6WQ5nd5Zgx9zdSIbv3CsKgCn JLVyzbSZd5n9HBKcacK2x70Kvo+cCBeXV9nI1lV5k47+xMqQ4HDZWPNzzMArdrgVZWI/t8Iogb+ kgiLEDWQcHPAqCSSWaulxfZnycQ6fpZyTMPSnXx5Xz9HpOhhe1A== X-Google-Smtp-Source: AGHT+IHe4ZjSpU/Yxv3LE/+zljsqNz0jTaKc3yx+g2OuRkRC0yuvd4eLyi5KQwuy+TEEOcsh34B0gfUX5zNEHUXj1OQ= X-Received: by 2002:a05:6402:240a:b0:5c2:5cf1:70e2 with SMTP id 4fb4d7f45d1cf-5c413e27c63mr1927285a12.20.1726137699798; Thu, 12 Sep 2024 03:41:39 -0700 (PDT) MIME-Version: 1.0 From: Sam Liddicott Date: Thu, 12 Sep 2024 11:41:03 +0100 Message-ID: Subject: fix kernel menuconfig failure due to shell composition fault in cml1.bbclass To: bitbake-devel@lists.openembedded.org List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 12 Sep 2024 10:41:52 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/bitbake-devel/message/16555 Function do_menuconfig in cml1.bbclass has a problem with the composition of the shell command, manifest when KCONFIG_CONFIG_COMMAND contains " which it often may, e.g. KCONFIG_CONFIG_COMMAND="menuconfig CC=\"ccache x86_64-sublime-linux-gcc -fuse-ld=bfd\" ..." Without the fix, this command fails for me on kirkstone: bitbake linux-intel -c menuconfig which generates a hidden error that requires a degree in archeology to unearth: 0: linux-intel-5.15.94+... do_menuconfig - 0s (pid 3056478) Trying to run: screen -r devshell_3056478 GEN Makefile ccache: unknown compiler scripts/Kconfig.include:44: Sorry, this compiler is not supported. make[1]: *** [.../kernel-source/scripts/kconfig/Makefile:48: menuconfig] Error 1 make: *** [.../kernel-source/Makefile:620: menuconfig] Error 2 screen is terminating] which is because the invoked command was effectively: make menuconfig "CC=ccache" x86_64-sublime-linux-gcc ... and as extra args are ignored, it is the same as: make menuconfig "CC=ccache" kernel menuconfig can succeed in some manner for other kernels and architectures and open embedded releases, although it is still subject to ignoring most of KCONFIG_CONFIG_COMMAND, perhaps depending whether or not a kernel has previously been build (avoiding the need to invoke a broken compiler for menuconfig) As mentioned, the problem is that a " can terminate the value of the -c argument in this line: oe_terminal("sh -c \"make %s; .... causing the rest of KCONFIG_CONFIG_COMMAND to become additional (and ignored) numeric arguments from $0 onwards. This also means that the error handler "Command failed.' and 'Press any key to continue..." doesn't work. I attach three alternative patches, depending which approach the maintainers want to take. Patch 1 uses the shell to dynamically compose the shell command by means of "$@" which is a great trick I've used for years when the arguments already exist as a shell-safe list. This means that there is no need to escape the make arguments. Patch 2 uses shlex.quote which of course requires python >= 3.3 so one of the other patches may be needed for some of older open embedded releases Patch 3 uses .replace() and is likely inadequate but could be a preferred starting point for maintainers if they don't like patch 1 and want to avoid shlex in patch 2, but would rather roll their own. From 6fea0b20d62b7ccd844754aebef76bd675d72165 Mon Sep 17 00:00:00 2001 From: Sam Liddicott Date: Thu, 12 Sep 2024 10:09:37 +0100 Subject: escape " in KCONFIG_CONFIG_COMMAND for do_menuconfig The problem with composing shell frgaments in python like this: oe_terminal("sh -c \"make %s ..." % args ... is that if args contains " this can terminate the command that is passed to sh -c, and the remainder of args will become additional arguments to the shell command, available as $0 onwards. That also has the effect of breaking the "Command failed" and the "Press any key to continue..." messages. This patch escapes all " and \ in args with a backslash, suitable for composing with python. oe_terminal("sh -c \"make %s ..." % args.replace("\"", "\\\"") ... all instances of " become \" in the command invocation. However those escapes may be buggy, and I'm not confident that they are sufficient. --- meta/classes/cml1.bbclass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta/classes/cml1.bbclass b/meta/classes/cml1.bbclass index d319d66ab2..f6727c5c33 100644 --- a/meta/classes/cml1.bbclass +++ b/meta/classes/cml1.bbclass @@ -48,7 +48,7 @@ python do_menuconfig() { # ensure that environment variables are overwritten with this tasks 'd' values d.appendVar("OE_TERMINAL_EXPORTS", " PKG_CONFIG_DIR PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR") - oe_terminal("sh -c \"make %s; if [ \\$? -ne 0 ]; then echo 'Command failed.'; printf 'Press any key to continue... '; read r; fi\"" % d.getVar('KCONFIG_CONFIG_COMMAND'), + oe_terminal("sh -c \"make %s; if [ \\$? -ne 0 ]; then echo 'Command failed.'; printf 'Press any key to continue... '; read r; fi\"" % d.getVar('KCONFIG_CONFIG_COMMAND').replace("\\", "\\\\").replace("\"", "\\\""), d.getVar('PN') + ' Configuration', d) # FIXME this check can be removed when the minimum bitbake version has been bumped -- 2.43.0