From: Patrick Steinhardt <ps@pks.im>
To: Glenn Washburn <development@efficientek.com>
Cc: grub-devel@gnu.org, Daniel Kiper <dkiper@net-space.pl>
Subject: Re: [PATCH v3 1/2] json: Add function to unescape JSON-encoded strings
Date: Mon, 6 Jun 2022 07:18:28 +0200 [thread overview]
Message-ID: <Yp2OJEo47DwwPVMU@tanuki> (raw)
In-Reply-To: <20220605140044.5140c94e@crass-HP-ZBook-15-G2>
[-- Attachment #1: Type: text/plain, Size: 2261 bytes --]
On Sun, Jun 05, 2022 at 02:00:44PM -0500, Glenn Washburn wrote:
> On Mon, 30 May 2022 18:01:01 +0200
> Patrick Steinhardt <ps@pks.im> wrote:
>
> > 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.
> >
> > Add a new function `grub_json_unescape ()` that takes a potentially
> > escaped JSON string as input and returns a new unescaped string.
> >
> > Signed-off-by: Patrick Steinhardt <ps@pks.im>
> > ---
> > grub-core/lib/json/json.c | 98 +++++++++++++++++++++++++++++++++++++++
> > grub-core/lib/json/json.h | 12 +++++
> > 2 files changed, 110 insertions(+)
> >
> > 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
> >
> > return GRUB_ERR_NONE;
> > }
> > +
> > +grub_err_t
> > +grub_json_unescape (char **out, size_t *outlen, const char *in, size_t inlen)
>
> Why not grub_size_t instead of size_t?
>
> > +{
> > + grub_err_t ret = GRUB_ERR_NONE;
> > + size_t inpos, resultpos;
>
> Same here.
>
> > + char *result;
> > +
> > + result = grub_calloc (1, inlen + 1);
>
> Should check for grub_calloc failure.
>
> I like the idea of being able to do an inplace conversion if in ==
> *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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2022-06-06 5:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-30 16:00 [PATCH v3 0/2] luks2: Fix decoding of digests and salts with escaped chars Patrick Steinhardt
2022-05-30 16:01 ` [PATCH v3 1/2] json: Add function to unescape JSON-encoded strings Patrick Steinhardt
2022-06-05 19:00 ` Glenn Washburn
2022-06-06 5:18 ` Patrick Steinhardt [this message]
2022-06-06 17:10 ` Glenn Washburn
2022-05-30 16:01 ` [PATCH v3 2/2] luks2: Fix decoding of digests and salts with escaped chars Patrick Steinhardt
2022-06-05 19:04 ` Glenn Washburn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yp2OJEo47DwwPVMU@tanuki \
--to=ps@pks.im \
--cc=development@efficientek.com \
--cc=dkiper@net-space.pl \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.