Live data from Hacker News

Althttpd: Simple webserver in a single C file

sqlite.org

281–290 of 345 posts

Re: Althttpd: Simple webserver in a single C file

#281
post #65

Earlier quoted context omitted.

You mean zero runtime deps because it pulls a lot of stuff when it does get built. Still great but I'd use traefik for more than 10 sites.

Caddy can serve thousands of sites without a sweat. What are your concerns exactly?

The webui based config helps for lots of sites and my clients can do it themselves without bothering me.

Re: Althttpd: Simple webserver in a single C file

#282

Earlier quoted context omitted.

Yeah. The function in question is called in only one place. It would seem you’d need to send the web server more than a size_t of data for this to be an issue.

Yes, absolutely. If the webserver is compiled 32-bit, that is only 4GB of data, which might be feasible? I don't know enough to say. Assuming a hacker kindly won't overflow your buffer is never a good idea. However, the presence of one piece of code that is not integer-overflow safe definitely makes me nervous. This is just the one I found in 5 minutes, what else is in there?

It's not an integer overflow that would be needed but an unsigned overflow. The way I see it, on 32-bits, that means that the size HTTP request would have to be bigger than what's available to both user application and the OS together. In short, one just can't get the input request that big. Of course, if you manage that, you'll disprove this claim.

Re: Althttpd: Simple webserver in a single C file

#283
post #154

Earlier quoted context omitted.

People say this, but then there's ASN.1 which has had critical security bugs in: https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=asn.1 I will agree that exhaustively defining text protocols is extremely hard, starting from character set / encoding and getting worse from there.

I guess if you're going to pick the absolute worst example of a binary protocol.

That is absolutely not fair.

BER-TLV is really nice protocol. I have worked with it for couple of years when I worked on an EMV application. It uses BER-TLV to communicate with the credit card but it is also very convenient format for all sorts of other uses and I would use it wherever I could. Think of it as Json but in binary form. It is not complicated and I would not even bother parsing the messages -- I could interpret hex dumps of them by sight very easily.

Re: Althttpd: Simple webserver in a single C file

#284
post #24

/* ** Test procedure for ParseRfc822Date */ void TestParseRfc822Date(void){ time_t t1, t2; for(t1=0; t1 There's only two billion integers, guess we can test them all. Well, substantially fewer than two billion with that skip. I wonder if that completes in a few seconds.

How would you write a better test? IMO most tests are fundamentally flawed. The way most testing is done it would be easier and better to just write everything twice, have a method to compare results, and hope you got it right at least once.

I do think of tests as a kind of double accounting.

Re: Althttpd: Simple webserver in a single C file

#285

Earlier quoted context omitted.

It's been a few years but my one and only interaction with Zed via an email exchange showed me he was quite unstable and prone to outbursts. Never meet your heroes, they say.

I had exactly one interaction with him, too, whereby he shared with me a very long list of companies that he knew of which were hiring at the time, this would've been around 2012 or so. I got quite a few interviews as a result, and quite a few offers, FWIW, though I ended up taking a job with a company that wasn't on this list. I understand both that he is and why he is such a polarizing figure. Just wanted to put my…

I believe it. Some people exhibit pretty extreme behavior. It sounds like that was extremely nice of him :)

Re: Althttpd: Simple webserver in a single C file

#286
post #276

Earlier quoted context omitted.

You might want to try filed ! This was for serving MPEG4-TS files with, IIRC, H.264 video and MPEG-III audio streams -- nothing fancy -- from a server running a container living on a disk attached via USB/1.1. While USB/1.1 has enough bandwidth to stream the video, the other HTTP servers were too slow with Range requests, because they would do things like wait for logs to complete and open the file to serve (which is…

> a server running a container living on a disk attached via USB/1.1. Ah, ok. That makes sense. USB 1.1 can certainly challenge cache layers and software assumptions. I do wonder how far apache2 might have been pushed, dropping logs and adjusting proxy/cache settings.

I do not know, though I do know that just disabling logging wasn't sufficient.

Re: Althttpd: Simple webserver in a single C file

#287
post #62
post #2

Here is the actual single C-code file: https://sqlite.org/althttpd/file?name=althttpd.c Something I absolutely love about text based protocols such as HTTP/1 is how easy you can implement it in any virtually programming language. Sure, the implementation is not top-of-the-notch, but it just damned works, it is portable, it is understandable by humans. That's something what's got lost with HTTP/2 and HTTP/3, respectiv…

For people who like text-based protocols (and dislike surveillance and web bloat), I suggest taking a look at Gemini, which was designed so you could write a client for it over the weekend. https://gemini.circumlunar.space/

Gemini is quite interesting in that brings nostalgic feeling from when the web was a new thing, but is also modern.

The Lagrange browser seems quite polished.

Re: Althttpd: Simple webserver in a single C file

#288

Earlier quoted context omitted.

Yeah. The function in question is called in only one place. It would seem you’d need to send the web server more than a size_t of data for this to be an issue.

Yes, absolutely. If the webserver is compiled 32-bit, that is only 4GB of data, which might be feasible? I don't know enough to say. Assuming a hacker kindly won't overflow your buffer is never a good idea. However, the presence of one piece of code that is not integer-overflow safe definitely makes me nervous. This is just the one I found in 5 minutes, what else is in there?

MAX_CONTENT_LENGTH is 250MB. You won’t be able to send 4GB of data.

Re: Althttpd: Simple webserver in a single C file

#289

I'd be putting this in 1000 layers of sandboxing since its a C program with network access.

Maybe I'm getting old but these days I'm having a hard time telling if comments like these are serious or sarcastic.

It's both. Of course we have to rely on C now because most stuff is C but this is not an ideal situation and C shouldn't be used for new software.

Re: Althttpd: Simple webserver in a single C file

#290

Earlier quoted context omitted.

HTTP/1 simplicity comes not from text nature, but from it's clear concept and limited functionality. At core, it's just request-reply + key-value metadata. Whenever it's text, or binary, it does not matter much. But writing HTTP/2 frame types in letters would not make them any easier to understand.

There are also keep-alive, caching (a big topic), chunked transfer encoding, header parsing peculiarities, and authentication in HTTP. The combination of these creates some nice opportunities for implementation bugs. Source: have worked on a client-side implementation. Now, HTTP/2 isn't even conceptually simple, I agree about that... it seems ugly.

> implementation bugs. Source: have worked on a client-side implementation

well because the hard part is the client-side. caching is a client-side only thing with http, keep-alive is a thing that a server pushes to a client, the same with chunked transfer, which is not as easy to implement for a client like it was with content length.

basically a server does only need to implement certain headers, but a client needs to know all. also most clients even accept bad servers, like content for head requests, etc.. most stateless protocols put a lot of burden into clients.

h2 on the other hand is stateful and keeps the same hard semantics onto the client side and also makes servers more complex, because it's a state machine.

Post reply on HN