From patchwork Wed Jan 8 13:42:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1219678 X-Patchwork-Delegate: wd@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="BOW0Rd5b"; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47t9S01bdwz9sP6 for ; Thu, 9 Jan 2020 00:43:12 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 580E5817D0; Wed, 8 Jan 2020 14:43:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="BOW0Rd5b"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 95E15817D3; Wed, 8 Jan 2020 14:43:06 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FORGED_SPF_HELO, SPF_HELO_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on20720.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1a::720]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 558E881757 for ; Wed, 8 Jan 2020 14:43:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JP5vJGnI+4agHg1aoMpxvzEWMxAlb87vD0o01XZapN/DvaPyDpcfBR5JSNXCSg9LrEeQLhBIIqiw3/8RkHPgI2p02jdZ+Y8j54U1eWRnoWa0buPzktP/KFMraJQTAWbKVwzUhyNGFMRlU0oKhpCdcxhSJglOcGxgupEmh8N+PpZr+xgVTcBkNRcgJoH0tyPfQobjn7TRO0n75YkoQHLrniHKpVYeukisgLjDT2XGac8xeD42MeTU/67cIJK8KOXGeHeHX+wB9XJQztZTMXGnXLl5DC4gSOdzvb9onSIdqdy9wwLaminzqdME/F2jmslFiZlFUwMdeuv2J6awwC6bCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YHOlu53pPlpAZvjrwcT9UwlnDo6J0DYcdHzE2pW9g1A=; b=NbJ0VytWah9/g5Q+GeslgoBsaZnjlRQUjVvacvPtJ/jQc7bP8lO0l/JkoOhcJSpRl3WyHOAowC48LwBUb+pFEh+E2w6QXY4186XnF5RLHFkwtfbGGGrSaoAaVpfRace65TgXl8QTqAd9cDK2N//0+/okHnuznSkgnti3pPfBNOZl8rtj7uRTJAs8xJB/wYxH3cZS/PGTN2jn700TBl4FWuZ0sdtMhsjyxqGDexcuLGOD6ssEYPqhpl4wiDlVKImiY3iqfzpCdQcHdru99UlYEIypPm+lZkpyC3A0QtWgfM0gbVP6wBPxcKM1RNYIYcgSuo3CpEXKq0jq5gG6aojPpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YHOlu53pPlpAZvjrwcT9UwlnDo6J0DYcdHzE2pW9g1A=; b=BOW0Rd5bGurxrPDBxPSQBvUEVLEaPzu+hyAodfbfQ2qHWfRYrEf+ix7n2uEA82UJ9ViYN0AovHSJLZELqVOYxoDlRBOeh7YLI/nGfHy5KBXmeXYNpbpwTclYezMCl4a2oMeAHJbUh92zL2c6MI3+9soVQwcY7zEq+f8pSN9SUPY= Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (20.178.126.85) by VI1PR10MB1712.EURPRD10.PROD.OUTLOOK.COM (10.165.198.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.12; Wed, 8 Jan 2020 13:42:57 +0000 Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::8175:5aa2:2870:766d]) by VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::8175:5aa2:2870:766d%6]) with mapi id 15.20.2602.017; Wed, 8 Jan 2020 13:42:57 +0000 Received: from prevas-ravi.prevas.se (81.216.59.226) by HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2623.9 via Frontend Transport; Wed, 8 Jan 2020 13:42:56 +0000 From: Rasmus Villemoes To: "u-boot@lists.denx.de" Subject: [PATCH] env: introduce CONFIG_ENV_DOTVARS_TEMPORARY Thread-Topic: [PATCH] env: introduce CONFIG_ENV_DOTVARS_TEMPORARY Thread-Index: AQHVximJzpmQm6OOzkq7P/CBo4kSCA== Date: Wed, 8 Jan 2020 13:42:57 +0000 Message-ID: <20200108134247.31443-1-rasmus.villemoes@prevas.dk> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HE1PR0101CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::23) To VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:e1::21) x-mailer: git-send-email 2.23.0 authentication-results: spf=none (sender IP is ) smtp.mailfrom=rasmus.villemoes@prevas.dk; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [81.216.59.226] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ef014955-ffd6-48d2-ee3f-08d79440ab74 x-ms-traffictypediagnostic: VI1PR10MB1712: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 02760F0D1C x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39850400004)(396003)(376002)(366004)(346002)(136003)(189003)(199004)(66446008)(64756008)(66556008)(66476007)(478600001)(1076003)(86362001)(36756003)(66946007)(107886003)(2906002)(6486002)(4326008)(186003)(16526019)(8676002)(81156014)(54906003)(5660300002)(81166006)(2616005)(956004)(26005)(44832011)(6916009)(8936002)(71200400001)(6512007)(316002)(8976002)(52116002)(6506007); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR10MB1712; H:VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: prevas.dk does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: aS1Z9rl8IzuV3VpNuGrNYRYzPR789d6QgPbgpUQkJ6b7hUM2eGiNPKYRL5+kFQGTVrEM7fZiDiKYrgirqPrsFnuQMXMmQVXLqes5K+IPOOCxmw+8jQ5y28wLL6qlG0fEg1v9siTj81Yr9MhNuWu/Hhn+gELvzbxGuUW7vH5vuPRvlVOtFlkY7DYdjKeT98GWLHVLCuTef4BS4ws8Kt1Z0N/tt0gt458bzmO1d5pTuxLd4UyB/ZKEfNz/ghnZcbhvZMko+TsbzbzLCE/VUkvln4ASHaxZ+CfD9Xz8FSLE8r1Uxo5qKanKrgYYBeM2Rdgr0F8q31+/1yukNHHDnz/djGthh2lHvQNoeeRez94nYUm4SvZPsG7gHzl/dbEJbUYmNnrStxjxdh36x4K/uFjnTqLHYjWvKpi+SHRC7r65PJh7Dl4cn9qcgduB6LTG4uCW MIME-Version: 1.0 X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: ef014955-ffd6-48d2-ee3f-08d79440ab74 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Jan 2020 13:42:57.3668 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: +wyCIKN1wj9sd1LjmNoIqwRXx6f6z2ILXo6EvlP4jGACdHQIImtPk5MnWrjPuE7zCKbYKBcN/25zDgxEbPujGoP1UVbvDiGq3NEHCfFNklA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR10MB1712 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joe Hershberger Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean The printenv command already by default hides variables beginning with a dot. It can be useful to take that convention even further, and prevent such variables from ever being stored persistently (and ignored if they happen to exist in stable storage). This way, one can freely use such variable names in script logic, without worrying about random temporary variables leaking to persistent storage and/or to/from another U-boot "session". Shell variables can be used somewhat similarly, but they are not as flexible, since many helper commands (e.g. setexpr, fdt) offer to store their output in an environment variable, not a shell variable. Signed-off-by: Rasmus Villemoes --- env/Kconfig | 10 ++++++++++ env/common.c | 6 ++++-- lib/hashtable.c | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/env/Kconfig b/env/Kconfig index 4661082f0e..69fd2cae03 100644 --- a/env/Kconfig +++ b/env/Kconfig @@ -559,6 +559,16 @@ config SYS_RELOC_GD_ENV_ADDR Relocate the early env_addr pointer so we know it is not inside the binary. Some systems need this and for the rest, it doesn't hurt. +config ENV_DOTVARS_TEMPORARY + bool "Ignore variables beginning with . when saving/loading the environment" + help + If you select this option, environment variable names + beginning with a dot (.) are skipped when writing the + environment to persistent storage. Similarly, should the + persistent storage somehow contain such a variable, it is + ignored (i.e. not added to the runtime environment) when + loading. + config USE_DEFAULT_ENV_FILE bool "Create default environment from file" help diff --git a/env/common.c b/env/common.c index 0da21ee081..c23b490364 100644 --- a/env/common.c +++ b/env/common.c @@ -116,6 +116,7 @@ int env_set_default_vars(int nvars, char * const vars[], int flags) int env_import(const char *buf, int check) { env_t *ep = (env_t *)buf; + int flag = IS_ENABLED(CONFIG_ENV_DOTVARS_TEMPORARY) ? H_HIDE_DOT : 0; if (check) { uint32_t crc; @@ -128,7 +129,7 @@ int env_import(const char *buf, int check) } } - if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0, 0, + if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', flag, 0, 0, NULL)) { gd->flags |= GD_FLG_ENV_READY; return 0; @@ -212,9 +213,10 @@ int env_export(env_t *env_out) { char *res; ssize_t len; + int flag = IS_ENABLED(CONFIG_ENV_DOTVARS_TEMPORARY) ? H_HIDE_DOT : 0; res = (char *)env_out->data; - len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); + len = hexport_r(&env_htab, '\0', flag, &res, ENV_SIZE, 0, NULL); if (len < 0) { pr_err("Cannot export environment: errno = %d\n", errno); return 1; diff --git a/lib/hashtable.c b/lib/hashtable.c index 907e8a642f..e05a097c75 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -928,6 +928,9 @@ int himport_r(struct hsearch_data *htab, if (!drop_var_from_set(name, nvars, localvars)) continue; + if ((flag & H_HIDE_DOT) && *name == '.') + continue; + /* enter into hash table */ e.key = name; e.data = value;