From patchwork Thu Sep 12 16:23:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Liddicott X-Patchwork-Id: 49023 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 03487EED61E for ; Thu, 12 Sep 2024 16:24:44 +0000 (UTC) Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) by mx.groups.io with SMTP id smtpd.web11.52289.1726158276489963716 for ; Thu, 12 Sep 2024 09:24:37 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@liddicott-com.20230601.gappssmtp.com header.s=20230601 header.b=XAPXnCij; spf=none, err=SPF record not found (domain: liddicott.com, ip: 209.85.208.181, mailfrom: sam@liddicott.com) Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2f75c205e4aso14476951fa.0 for ; Thu, 12 Sep 2024 09:24:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=liddicott-com.20230601.gappssmtp.com; s=20230601; t=1726158273; x=1726763073; darn=lists.openembedded.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=fN0hGl4NWW2Q2pMnWJsul8OWjBM46WYszEVin2mUyyc=; b=XAPXnCijl6HqF7H66ZUeQCw3nSGh+A35uZ6h7MiVkFtHUJmD312H5w15vuIjeHIjwf sI2M5qpz0jeMgAFJbLV3yDxooDuUCmwHqr5IUXl+yujIG1vGsjR9bvocol95cAV+JA/x CDprTA+i6p3fh97F72p/nBIRI3npSicb5euBtQ8vQCUnZVTYBLvObxIEgyYcKiNXgxTO WPR6KwboHBLYjmpnYs17eOMSavlYCuflULtw3c0B51hIb8/QP24xE/npzmRqs+E9tscz ROghPiWukFBm2K95BpewQa8ubpxewCpQb+xuZobaolkJDe8ONfqGfBJM3o/SPlXPYzYt yevg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726158273; x=1726763073; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=fN0hGl4NWW2Q2pMnWJsul8OWjBM46WYszEVin2mUyyc=; b=pgLCElGjwvarczpAA/CRISYQTg/vzh5ffTHkMmEz+o6YhG3EEXNAI7olhMDOdDIOPM QlX0CHtdM/V4SzNxkODaOeZQETA6IAAJuTdWK68BG25eMHEP7+4UaBCI5nq/URDQFXF7 eKlrcsBk6L7u6bIBzmPJl7J2ZT/lyu1as3Q72X6tDlAhB5mA8vjp7ThLp61X9OW+4JbY +Zo0//PsviQqALt0bEj8JlVWFpsaDMw28aWDLyAEjFXc5XeTj9HngYdULg+2gnSXZemb cUh6I58Z8GkaXw6TlIbafje+jHUo7O/BWo14E02zwAAlaAH7MjGylpnzGGEWzH9FQvOQ XCiA== X-Gm-Message-State: AOJu0YzZZbF33eb1WbUfkPsCDVdE+v9Yn5OZlDqqYSSC6JQibVRFU8s2 LuuoyO2FD6fvvdSeIVueV8iaWUmNKffGYrR3QV93gPTrHQrMtbQjm91hi8MIW8qCV5eFdJbwL+s q7kEBfE4NMuZgdeWHoVioj069D0A1jZ352Uv2p5+CQwESEhtfaQ== X-Google-Smtp-Source: AGHT+IG9UyemFkYqDRdoO1gNcBE0XpoBzyLH5IghwwmeNSLt9VvYpfomAPPG+0gYBsCDBxiBSthkcyDPwqrf6qFNJ4Y= X-Received: by 2002:a2e:be83:0:b0:2f7:503e:ed43 with SMTP id 38308e7fff4ca-2f787edf4a8mr22030471fa.26.1726158272885; Thu, 12 Sep 2024 09:24:32 -0700 (PDT) MIME-Version: 1.0 From: Sam Liddicott Date: Thu, 12 Sep 2024 17:23:56 +0100 Message-ID: Subject: [OE-core][PATCH] fully fix kernel menuconfig shell composition fault in cml1.bbclass To: openembedded-core@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 16:24:44 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/204448 I mistakenly posted bad patches to bitbake-devel earlier today. These are 2 alternative patches (pick only one). They apply on master branch but should backport easily. I tested them and generated them on kirkstone (and then updated the path and checked application on master). This is a full fix for a problem partially addressed by Jaeyoon Jung ( jaeyoon.jung@lge.com Thu Sep 21 17:27:10 2023 +0200 https://lists.openembedded.org/g/openembedded-core/message/186885) That fix swapped " for ' which instead causes the failure to occur when KCONFIG_CONFIG_COMMAND contained ' (single quotes) whereas before it occurred when KCONFIG_CONFIG_COMMAND contained " (double quotes). The problem only arises because of the extra "sh -c" needed in cml1.bbclass to execute multiple shell statements, and because of the existence of a prepended "exec" by terminal.bbclass function emit_terminal_func. This means that the implicitly shell-ready KCONFIG_CONFIG_COMMAND needs escaping for insertion into the extra "sh -c". Although cml1.bbclass escaped the shell code in the source, the KCONFIG_CONFIG_COMMAND was not escaped, and so either " or ' was going to fall victim at some point. These two alternative patches directly address the need to escape KCONFIG_CONFIG_COMMAND. The first patch is the simplest, and causes KCONFIG_CONFIG_COMMAND to be passed as additional arguments to the inner "sh -c", entirely avoiding the need to shell escape, on this principle: -"sh -c 'make %s ...'" % ${KCONFIG_CONFIG_COMMAND}" +"sh -c 'make \"$@\" ...' dummy-arg0 %s" % ${KCONFIG_CONFIG_COMMAND} The second fix uses shlex.quote (suitable for python 3.3 or above) to quote the entire argument to "sh -c" including KCONFIG_CONFIG_COMMAND, avoiding also the need to manually escape any of the nested shell. I think that the first fix is more portable, but they both require scrutiny to ensure fixing the problem properly is worth the trouble. For application in kirkstone and some others, meta/classes-recipe/cml1.bbclass needs changing to meta/classes/cml1.bbclass I know that we have a good-enough-for-now fix from Jaeyoon Jung, so this isn't urgent, and maybe not even important. Sam From a96f41f6d6f0d8308d74a74d736d5a35dc54f0fa Mon Sep 17 00:00:00 2001 From: Sam Liddicott Date: Thu, 12 Sep 2024 17:18:37 +0100 Subject: use shlex.quote on KCONFIG_CONFIG_COMMAND for do_menuconfig Although KCONFIG_CONFIG_COMMAND is shell-ready, it needs escaping when composed as part of some shell which is then embedded into an outer "sh -c" in cml1.bbclass This patch uses shlex.quote to escape the entire shell fragment when it is composed in the inner "sh -c" Signed-off-by: Sam Liddicott --- meta/classes-recipe/cml1.bbclass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta/classes-recipe/cml1.bbclass b/meta/classes-recipe/cml1.bbclass index d319d66ab2..f6727c5c33 100644 --- a/meta/classes-recipe/cml1.bbclass +++ b/meta/classes-recipe/cml1.bbclass @@ -36,4 +36,5 @@ KCONFIG_CONFIG_ENABLE_MENUCONFIG ??= "true" KCONFIG_CONFIG_ROOTDIR ??= "${B}" python do_menuconfig() { import shutil + import shlex @@ -48,5 +49,5 @@ 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 %s' % shlex.quote("make %s; if [ $? -ne 0 ]; then echo 'Command failed.'; printf 'Press any key to continue... '; read r; fi" % d.getVar('KCONFIG_CONFIG_COMMAND')), d.getVar('PN') + ' Configuration', d) -- 2.43.0