Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1j9Am4-000124-8M for mharc-grub-devel@gnu.org; Tue, 03 Mar 2020 11:52:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59677) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9Am1-0000z1-M7 for grub-devel@gnu.org; Tue, 03 Mar 2020 11:52:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j9Am0-0001kw-Jb for grub-devel@gnu.org; Tue, 03 Mar 2020 11:52:01 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:34546) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j9Am0-0001kE-Dw for grub-devel@gnu.org; Tue, 03 Mar 2020 11:52:00 -0500 Received: from mail-wr1-f69.google.com ([209.85.221.69]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j9Aly-0004f4-Oj for grub-devel@gnu.org; Tue, 03 Mar 2020 16:51:58 +0000 Received: by mail-wr1-f69.google.com with SMTP id f10so1492208wrv.1 for ; Tue, 03 Mar 2020 08:51:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :accept-language:references:mime-version:content-disposition :in-reply-to; bh=Xk+GLHqF4loZRjrULhfCOh3OdmyR/rhO6saYHh1R/aI=; b=o4j1k9KOZgp74rs9kgJInF5WG8W4WiNpWGQl1wtVLOEvB2SYEEIx6/wxbL8rTqQxKE 2RmsLCTsOjqb59K/d9an1U8zIcESNACMpvTUpUw/Zy4JKYgglpcnv3WNjdWJUvBko6BS PZXIhSHXSiJHe3isyzoFXsn5TzaJA9pvliFCtlGld5sd05gV7P2mj9yZvGTVhoTz2+Ng UGw/nHctLp9k44MqaxdHPPuGIGmW9a6KFHSEBFpwGUGKs7nlcj1ohsB3GnPDjPBiemZy Wyy480L4FHy/3cROMFe+9Ft5sgHpdvaxDrpl4GuzzoXL55WOy+lo0sozvQoxzgpJzuT9 zXCA== X-Gm-Message-State: ANhLgQ3zPE5bCEvAVByBb4UWh8EPrk2UkCsmap+dVUWuTAgIos4YZiIx FXtSEM1GxsosOjyq9owDt65S+altV7b2XqrFxpSzo/VPB1lQD0FDzrc/PSXEUE0WrV0e/4X98RZ +I9qRyJsRwvSxkblRWE5HxU1nMOSJ X-Received: by 2002:a05:600c:230d:: with SMTP id 13mr5059399wmo.11.1583254318396; Tue, 03 Mar 2020 08:51:58 -0800 (PST) X-Google-Smtp-Source: ADFU+vtkQ2T/gYsad8SLdy8K0liiCdGfaK681yeg6ppHq2sIlgUX4Ib8FiV+iz1bUZGIggR8LvPAQg== X-Received: by 2002:a05:600c:230d:: with SMTP id 13mr5059386wmo.11.1583254318136; Tue, 03 Mar 2020 08:51:58 -0800 (PST) Received: from jak-t480s ([217.110.231.98]) by smtp.gmail.com with ESMTPSA id f17sm24201920wrj.28.2020.03.03.08.51.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 08:51:57 -0800 (PST) Date: Tue, 3 Mar 2020 17:51:55 +0100 From: Julian Andres Klode To: Daniel Kiper Cc: grub-devel@gnu.org Subject: Re: [PATCH v2] smbios: Add a --linux argument to apply linux modalias-like filtering Message-ID: <20200303165155.7soxaybubpd2l4d3@jak-t480s> Accept-Language: de-DE, de, en-GB, en-US, en References: <20200303145406.852454-1-julian.klode@canonical.com> <20200303150633.942527-1-julian.klode@canonical.com> <20200303164454.pvbyz5qahdue5qv4@tomti.i.net-space.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200303164454.pvbyz5qahdue5qv4@tomti.i.net-space.pl> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 91.189.89.112 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Mar 2020 16:52:02 -0000 On Tue, Mar 03, 2020 at 05:44:54PM +0100, Daniel Kiper wrote: > On Tue, Mar 03, 2020 at 04:06:34PM +0100, Julian Andres Klode wrote: > > @@ -261,6 +279,7 @@ grub_cmd_smbios (grub_extcmd_context_t ctxt, > > > > const grub_uint8_t *structure; > > const char *value; > > + char *modified_value = NULL; > > grub_int32_t option; > > grub_int8_t field_type = -1; > > grub_uint8_t i; > > @@ -334,12 +353,17 @@ grub_cmd_smbios (grub_extcmd_context_t ctxt, > > return grub_error (GRUB_ERR_IO, > > N_("failed to retrieve the structure field")); > > > > + if (state[LINUX_OPT].set) > > + value = modified_value = linux_string (value); > > + > > /* Store or print the formatted value. */ > > if (state[SETTER_OPT].set) > > grub_env_set (state[SETTER_OPT].arg, value); > > else > > grub_printf ("%s\n", value); > > > > + grub_free(modified_value); > > I am not sure why we need modified_value if you free it immediately here... Because `value` is `const char *` that might point to static buffers or other buffers, so we need to store this dynamically allocated string somewhere else we can free later. I guess we could also store the buffer statically with a size and realloc it if it's too small, thus reusing it and not having to free it, but this approach seemed slightly easier. -- debian developer - deb.li/jak | jak-linux.org - free software dev ubuntu core developer i speak de, en