From patchwork Sat Aug 11 15:28:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 956564 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41nmLC0ZZhz9s89 for ; Sun, 12 Aug 2018 01:36:19 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B0A94C21DFD; Sat, 11 Aug 2018 15:32:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id C7AD4C21E62; Sat, 11 Aug 2018 15:28:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 70513C21C8B; Sat, 11 Aug 2018 15:28:46 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lists.denx.de (Postfix) with ESMTPS id 16DFFC21BE5 for ; Sat, 11 Aug 2018 15:28:46 +0000 (UTC) Received: from LT02.fritz.box ([88.152.14.153]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LeBPM-1gGDBo1zO0-00puBn; Sat, 11 Aug 2018 17:28:44 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Sat, 11 Aug 2018 17:28:14 +0200 Message-Id: <20180811152820.26817-10-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180811152820.26817-1-xypron.glpk@gmx.de> References: <20180811152820.26817-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K1:2ulQieLI87KlKV6RV6w3Z8d2LoH4rk9XNQzAwV6i6DqTX2L7pTp JYYWlEMkuUHzMu0+G9XjG+MpppomIHW2M5UqKPVDb6id3VB6g/T2rFCSD4IAZTsC6AJxhWf TYRfc34y9wdZ24XolWk5HV5Mt/lCRidOUNL8iV+YMQMFICgx8iJ32pM7uIoQzh9SGxF7lIe UGmO64Pbv412InX2Zo6xg== X-UI-Out-Filterresults: notjunk:1; V01:K0:d0XmBL95rOw=:Hzvp2BapM56s7Y1E2tRC2H IgILwUhqiepHYwbgK202yk9f3XMm3T7RjIYHafQ3QvABpeQswi4eSgp70STBmf4TAlgOuuDly sKeSkTWZgCXMV0XW7rcKz7NkmKSEZejPnI33cyWZRiyBKnh6uMTistMdpLdidRfRnHSJf/ww/ /MrDdnoA+xz/81WUYZUc9Q6TrYXFH/DG6Tanma2sXk0L5Tzlw+f/1cZvmvJCvDdLNfz2uax20 K2SEKzr6uBLfsv7P9XfclgpgsJwf36elFcf1QPd6g+qegMJ/zMd2l4lzMWqSleq++qU9e6iCE Lk8G0BFzXpzZugAJIBXTHv0PYw2Hv1S1dLTxWkqKSXVnmVBAg0eIpAvE38ki8ctsuXOTDMTXH AM3n4yOqxNQCdwyUNNLakufyGK6I/hVGAlq04NKEz67UPHu71I5Qe9giYdfVL9I0BlpT7E7S7 2TKhuE1FJN+pMMySdc/1naPNUVWXzOJZ9s6vyiXSpDWOrifbltkWbX7wDx1YZ2fO7X9E3PsGl 7OTJ1/4pgjC0uxm9Sg6VgBkbGxJOMK8MdeXedT55Fq2n186e4Dbd1ARZqgmYtU8pBWte7O4gd JeZX0xkQAJ9RURw9skaVTIUNP7Ksnk7bRF3fa6Bvi78muvK+U04qdb/nhbSt3iOruUFtsGEyo OLU94qcQB3r+Exmhu/DKrMjvAAuTbSxYNZ7Fi8ENl2sZvO7kZbOmgTlrgq50Ff0sJ55KN+ut/ F4eq+LArmNf1Oz6O1LF0CJ/M6cTxLU1ZZ50mylc4NV2wEHduLsRXG+dXRHU= Cc: Heinrich Schuchardt , u-boot@lists.denx.de Subject: [U-Boot] [PATCH 09/15] efi_loader: buffer size for load options X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The number of bytes in an utf-8 string is an upper limit for the number of words in the equivalent utf-16 string. In so far the inumbant coding works correctly. For non-ASCII characters the utf-16 string is shorter. With the patch only the necessary buffer size is allocated for the load options. Signed-off-by: Heinrich Schuchardt Reviewed-by: Alexander Graf --- cmd/bootefi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index b60c151fb4..708113b16e 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -116,18 +116,20 @@ static void set_load_options(struct efi_loaded_image *loaded_image_info, { size_t size; const char *env = env_get(env_var); + u16 *pos; loaded_image_info->load_options = NULL; loaded_image_info->load_options_size = 0; if (!env) return; - size = strlen(env) + 1; + size = utf8_utf16_strlen(env) + 1; loaded_image_info->load_options = calloc(size, sizeof(u16)); if (!loaded_image_info->load_options) { printf("ERROR: Out of memory\n"); return; } - utf8_to_utf16(loaded_image_info->load_options, (u8 *)env, size); + pos = loaded_image_info->load_options; + utf8_utf16_strcpy(&pos, env); loaded_image_info->load_options_size = size * 2; }