Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by boramalper on Sunday September 21, 2025 @04:09PM
(#45326200)
Untrusted doesn’t always mean adversarial IMO, even a bitrot can invalidate your entire input and possibly also trigger undefined behaviour if you aren’t prepared to handle that.
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by cwmoore on Sunday September 21, 2025 @04:19PM
(#45326290)
UB = "undefined behavior", thanks
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by leptons on Sunday September 21, 2025 @05:15PM
(#45326715)
I was using a checksum to protect against "bitrot" since this was over a very noisy serial transmission line (over a slip ring). So, no, there was no "undefined behavior" and it's quite easy to avoid.
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by interstice on Sunday September 21, 2025 @04:09PM
(#45326207)
Massively agree. Remember this thinking being everywhere with databases back in the day, not every text field is hooked up to a Wordpress comment section.
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by userbinator on Sunday September 21, 2025 @04:09PM
(#45326199)
You probably didn't control the other end, as otherwise you would've used something more sane than JSON?
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by leptons on Sunday September 21, 2025 @05:18PM
(#45326742)
I controlled both ends. There is nothing "insane" about JSON. It's used far and wide for many purposes. The system sending the JSON was based on Nodejs, so it was pretty natural to use JSON. And I did it with JSON just because I wanted to. I'd have had to invent some other protocol to do it anyway, and I didn't feel like reinventing the wheel when it was quite simple to write a basic JSON parser in assembly language, which is what I am comfortable with on the embedded system (been coding assembly for 40 years).
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by userbinator on Sunday September 21, 2025 @06:10PM
(#45327137)
For something that simple I'd choose a custom binary protocol or something like ASN.1 instead of JSON. It's easier to generate from a HLL and parse in a LLL (I've also been writing Asm for a few decades...)
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by leptons on Monday September 22, 2025 @01:06AM
(#45329265)
I've done plenty of custom binary protocols before. I can't say they were any better or easier to deal with. I also can't say that the "parser" for a binary format was any easier than a simple, limited JSON parser.
For this specific project I chose JSON and it worked perfectly. Sending JSON from the embedded CPU was also really simple. Yes, there was a little overhead on a slow connection, but I wasn't getting anywhere near saturation. I think it was 9600 bps max on a noisy connection with checksums. If even 10% of the JSON "packets" got through it was still plenty for the system to run.
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by johnisgood on Monday September 22, 2025 @04:40AM
(#45330643)
I would love to use ASN.1 if other programming languages would match up to Erlang's ASN.1. :(
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by Yeask on Monday September 22, 2025 @11:25AM
(#45334757)
Even if is not popular here .NET does support ASN.1, not sure if at the same level as Erlang.
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by cozzyd on Monday September 22, 2025 @11:54AM
(#45335227)
It depends on the use case. JSON has a lot of tooling making it convenient in a lot of cases
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by ghurtado on Sunday September 21, 2025 @05:27PM
(#45326816)
> Not everything needs to be absolutely 100% secure so long as you control the system.
Isn't that a bit like saying "you don't have to worry about home security as long as you are the only person who has the ability to enter your house"?
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by Yeask on Sunday September 21, 2025 @09:47PM
(#45328339)
Not at all.
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by Mogzol on Sunday September 21, 2025 @11:13PM
(#45328757)
I mean yeah if you're truly the only person that has the ability to enter your house then why should you worry about home security? Nobody else has the ability to get in.
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by ncruces on Monday September 22, 2025 @02:43AM
(#45329846)
Sure. I don't password protect my (Android) TV like I password protect my (Android) phone, despite both of them allowing authorized access to the same Google accounts, because if someone entered my house I have bigger things to worry than them using my TV.
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by johnisgood on Monday September 22, 2025 @04:38AM
(#45330629)
I agree. I knew that the JSON is not going to change, so I wrote a 10 lines long parser for it. It is not a JSON parser by any means, but it parses properly what I need it to.
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by cozzyd on Monday September 22, 2025 @10:08AM
(#45333699)
sscanf as a parser definitely has its uses
Re:Sj.h: A tiny little JSON parsing library in ~150 lines of...
by johnisgood on Monday September 22, 2025 @10:15AM
(#45333774)
I used strchr() in a function I named get_pair(). So, all in all, I used strchr() and strcmp() only!
Here's an example - I once coded a limited JSON parser in assembly language. I did not attempt to make it secure in any way. The purpose was to parse control messages sent over a serial port connection to an embedded CPU that controlled a small motor to rotate a camera and snap a photo. There was simply no way for any "untrusted" JSON to enter the system. It worked perfectly and nothing could ever be compromised by having a very simple JSON parser in the embedded device controlling the motor.