From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1ny57j-0005Rl-KB for mharc-grub-devel@gnu.org; Mon, 06 Jun 2022 01:17:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ny57g-0005Pd-9x for grub-devel@gnu.org; Mon, 06 Jun 2022 01:17:52 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:59525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ny57d-0000hq-Ho for grub-devel@gnu.org; Mon, 06 Jun 2022 01:17:51 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id CA0065C00F5; Mon, 6 Jun 2022 01:17:39 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 06 Jun 2022 01:17:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm2; t=1654492659; x=1654579059; bh=qJvoK5bC9Y CxavShBRynyiuqpeqiSVYcCSNdKJCy79w=; b=xw5haayj7jMWCUlFItuLaKkuz+ zLrCemwNPF2IMSyd89cV6tIVs3bvXeGFppcBWHqoXkHUx5XhPOkVjRCfj2MEpPF8 FHNewv7tRtFg0uT2w7Dpr3AENx4PyNtMBOB0iI0yRTnLAptOYwj/ty6HBuItk0bC 9R0euM15cg+YMDxWeokBLLNb5Jfeid751Ga7r9zw1Q9sUwjR929dnnP3VERdyPzU VbeYQpDXrj5gbm2BfElYb3YK+0IrzrXlTBTlVmGB0carjkAdyx8NGaEBovph7MMq aapJQ7HJAXQdnFP9IBd/bta+XzwKMiumh08qQDanz7OwPTSE4gatew6zzjNA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1654492659; x=1654579059; bh=qJvoK5bC9YCxavShBRynyiuqpeqi SVYcCSNdKJCy79w=; b=NeLKZXdZnXOTwc606XlNA6mE4ocmKVdWyNjBywn/H95Y YEylHOTIO8PKUr6j8RVe5z0ILPDWaR8S8f5eqBLSeDjta4YAvuLLlhmObN/Rd7AR w0h9JKj3bto4ll9bApxQ3upQhdngMWM4gCZ8iuqeDZUUGTnyETKnduFzXF5sy9ZX hkGEFa8yxbA/kYURUXGNqyrq9P04rTKTAVzBqA3BT2mfV2nrwqN+m6FGxk6AbBeQ v9E4Hd7R9js+aDKACo1XwHjiH4k8hpX2dQbckJSCk35u/+PIPwFLsrZGdTtL1pY6 xZc40JBAJXLuFC4H+f8IX205tOhwx9tG1HcuGmCdaQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedruddtuddgleefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 6 Jun 2022 01:17:38 -0400 (EDT) Received: from localhost (tanuki [10.192.0.23]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 3f6cb797 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 6 Jun 2022 05:17:31 +0000 (UTC) Date: Mon, 6 Jun 2022 07:18:28 +0200 From: Patrick Steinhardt To: Glenn Washburn Cc: grub-devel@gnu.org, Daniel Kiper Subject: Re: [PATCH v3 1/2] json: Add function to unescape JSON-encoded strings Message-ID: References: <3055f9f2fb2e2b418c037a4a3c1059b05f8b2701.1653926123.git.ps@pks.im> <20220605140044.5140c94e@crass-HP-ZBook-15-G2> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="+8RvQ1WLZthiQmfB" Content-Disposition: inline In-Reply-To: <20220605140044.5140c94e@crass-HP-ZBook-15-G2> Received-SPF: pass client-ip=66.111.4.25; envelope-from=ps@pks.im; helo=out1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Jun 2022 05:17:52 -0000 --+8RvQ1WLZthiQmfB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Jun 05, 2022 at 02:00:44PM -0500, Glenn Washburn wrote: > On Mon, 30 May 2022 18:01:01 +0200 > Patrick Steinhardt wrote: >=20 > > JSON strings require certain characters to be encoded, either by using a > > single reverse solidus character "\" for a set of popular characters, or > > by using a Unicode representation of "\uXXXXX". The jsmn library doesn't > > handle unescaping for us, so we must implement this functionality for > > ourselves. > >=20 > > Add a new function `grub_json_unescape ()` that takes a potentially > > escaped JSON string as input and returns a new unescaped string. > >=20 > > Signed-off-by: Patrick Steinhardt > > --- > > grub-core/lib/json/json.c | 98 +++++++++++++++++++++++++++++++++++++++ > > grub-core/lib/json/json.h | 12 +++++ > > 2 files changed, 110 insertions(+) > >=20 > > diff --git a/grub-core/lib/json/json.c b/grub-core/lib/json/json.c > > index 1c20c75ea..3e5e25f79 100644 > > --- a/grub-core/lib/json/json.c > > +++ b/grub-core/lib/json/json.c > > @@ -262,3 +262,101 @@ grub_json_getint64 (grub_int64_t *out, const grub= _json_t *parent, const char *ke > > =20 > > return GRUB_ERR_NONE; > > } > > + > > +grub_err_t > > +grub_json_unescape (char **out, size_t *outlen, const char *in, size_t= inlen) >=20 > Why not grub_size_t instead of size_t? >=20 > > +{ > > + grub_err_t ret =3D GRUB_ERR_NONE; > > + size_t inpos, resultpos; >=20 > Same here. >=20 > > + char *result; > > + > > + result =3D grub_calloc (1, inlen + 1); >=20 > Should check for grub_calloc failure. >=20 > I like the idea of being able to do an inplace conversion if in =3D=3D > *out, which would save on memory and be safe as the out string length > should always be less than or equal to the length of the in string. > I'll admit its not really necessary for the current use-case. [snip] Yeah, I thought about this, and in fact my first iteration did exactly that. But it complicates the interface somewhat given that you now have to pass in the caller-allocated size, return the end result's size and also have to somehow handle NUL-terminating the result. So altogether it added complexity and felt a lot more fragile compared to just allocating the result array. Patrick --+8RvQ1WLZthiQmfB Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAmKdjiMACgkQVbJhu7ck PpT0NBAAnPaGdxJr4L1mDM3DJabtx+B6GqDbtPc64E0zPgFVMxut5xfKvU9aT7DC 2suSPtCjb6T4o/k8Jgeuc5TKrsLbQ4+Clf2aDyfGhrSel/vgtDHk+ndkdJ9Tp5x9 A9UQjKk0LOEkttGoV+KNw4e9WgkWvGLbqz21mv84/V9nKFC11zITlutxMK8sMFZu iUkiTPOvPoEQLUumfIPXz7SQezk7io7J4yqKM61HawvhiRXJdoy4GLmNc6BoTJy0 mYAat0dfrKDt6YqIl3yAMzlXXMs6jc28Hk9wDUqMudB6ZWKP334CXVxS7snV1Sl0 TpYAnqxo+6LwJpf9OY8FJ04QLpz+iV53Bc9Bi7glFd/be1Fx5LdaPgv+zZDJ3aFt cKF2OiNqecAaGtVilxgOjwaX6+C8IJ68b++cejvU8NPpoRsxkAVBJWCNEALguOhw 9156yDtxTwcfAD4RZpXSNbHBO8F1qvcxyW0b4UNRXrdpRW7G8NH0SZR7Otfb+0Ow +8W8tyrY9+YrCnb5SEBLhKaDMBUdiR548xzIC9plX3Pnxsad4GHD060H5US/d73t aJV6tPthqv5eNd5kBLVog1MJ87OhfX3joIlScJYGb5Jj3sfnEwRZZqbobxcj6nfG FjU9H635tBWpiTqyp/lu2avrtjoXsbB2I3UgEmKBFZp1UC3fMpg= =UJ2X -----END PGP SIGNATURE----- --+8RvQ1WLZthiQmfB--