News for hackers. Stuff that matters.
Re:What developers should know about TCP by kccqzy on Friday May 15, 2020 @07:22PM (#23198678)
Definitely be sure to check the length though. Imagine a mistaken client trying to send HTTP, but of course the first four bytes "HTTP" when interpreted as a 32-bit integer, whichever endian, is an absurdly large buffer.
Re:What developers should know about TCP by nucleardog on Friday May 15, 2020 @07:57PM (#23198963)
I mean, at this point you're effectively defining a new network protocol (or, you will be shortly once you implement ways to work around all the other issues you're going to run into). I'd go all-in from the start and start every packet with a magic string/byte sequence of your own, a length, and probably a version code just to make it extensible.

Or see if there's an existing protocol you can abuse for what you want. If it's transactional, you get a pretty big ecosystem of battle-tested clients/servers/proxies/etc if you use HTTP.

Re:What developers should know about TCP by userbinator on Saturday May 16, 2020 @02:24AM (#23200932)
A 16-bit length (64k max message size) is usually sufficient, or even 24-bit (16M max) if you really feel the need, but 32 bits is far more than should be needed for parsing messages in memory; it would be fine for a streaming application, however (in which case a 64-bit length wouldn't be a bad idea either.)
Re:What developers should know about TCP by kccqzy on Saturday May 16, 2020 @03:48AM (#23201313)
Good advice. I was actually referring to this: https://rachelbythebay.com/w/2016/02/21/malloc/ I read this article a long time ago, and yet I made a similar mistake in my own code.