4 ms·
That looks way oversimplified. I once wrote a minimal HTTP server in Lua for Nmap project and part of the problem was UTF8 security. Consider get_next_char_len
by d33 9y ago
That looks way oversimplified. I once wrote a minimal HTTP server in Lua for Nmap project and part of the problem was UTF8 security. Consider get_next_char_len function here to see some of the edge cases:
https://github.com/nmap/nmap/blob/b7a5a6/ncat/scripts/httpd.lua https://github.com/nmap/nmap/blob/b7a5a6/ncat/scripts/httpd....
- loeg 9y agoThe Lua code is just excessively verbose.
- d33 9y agoWhat do you mean? How else would you implement a check for whether the prefix length is valid?
- loeg 9y agoHere's the code to do it: https://github.com/skeeto/branchless-utf8/blob/master/utf8.h https://github.com/skeeto/branchless-utf8/blob/master/utf8.h It's pretty straightforward. He uses a lookup table for the first byte ("lengths") and then later checks that subsequent bytes have the correct continuation prefix (0xc0 mask / 0x2a value). I think it checks all of the same conditions as your Lua code.
- feelin_googley 9y agoMimimal but useful. I just tried this httpd.lua script with djb's tcpserver and was pleasantly surprised. It is quick and handles large PDFs well enough. I like that there are no third party libraries. If directory listing and output for video could be added I might try using something like this on a local LAN as a replacement for the httpd binary I am using.
- d33 9y agoGlad to hear you like it! What do you mean by output for video? As for video listing, Lua doesn't provide a cross-platform way to do this, but I might have hacks for Unix/Windows that parse the output of dir/ls commands. Interested? Can't promise I find it though.
- feelin_googley 9y agoBriefly tested with a few filetypes and a couple of browsers, including Safari. Problem loading video/mp4, i.e., problem with "HTTP streaming". Maybe need to handle Range: header? Of course, any examples in Lua of different approaches to UNIX directory listing via HTTP are appreciated. Still a Lua noob.