On Fri, Jan 26, 2024 at 09:23:47AM +0100, Peter Krempa wrote:
> On Thu, Jan 25, 2024 at 08:33:42 -0800, Andrea Bolognani wrote:
> > On Tue, Jan 16, 2024 at 05:12:35PM +0100, Peter Krempa wrote:
> > > +        /* YAJL formats empty objects and arrays in a weird way:
> > > +         *
> > > +         * {
> > > +         *   "emptyarray": [
> > > +         *
> > > +         *   ],
> > > +         *   "emptyobject": {
> > > +         *
> > > +         *   }
> > > +         * }
> > > +         *
> > > +         * We want to use empty lines to separate commands and replies as
> > > +         * well as be compatible with python's 'json.dump' method, thus 
> > > we drop
> > > +         * any whitespace between array/object braces.
> > > +         */
> > > +        if ((p[0] == '{' || p[0] == '[') && p[1] == '\n') {
> >
> > I think you can lose the check on p[1]: whenever there's an opening
> > token, we can just skip all whitespace, including the initial
> > newline.
>
> JSON allows un-escaped '{' '[' inside a string:
>
> $ jq <<< '{"blah":"[{"}'
> {
>   "blah": "[{"
> }
>
> And even if it were escaped it's escaped with the traditional backslash
> sequence e.g. '\"', thus the very easy state machine above would still
> consider it.
>
> TBH I didn't check if it's present in our data though.

I hadn't considered that scenario. Better to be safe and keep the
additional check then.

-- 
Andrea Bolognani / Red Hat / Virtualization
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-le...@lists.libvirt.org

Reply via email to