Show HN: Demo of Wiki and Forum coded in C under 80k
home.ronsor.gq
home.ronsor.gq
Also, in my opinon, adding "Demo" means that it shows how to do it, but that's not clearly not how to do it properly.
Nowadays it's not possible to write applications without knowledge of XSS, XSRF, SQLi, redirects etc.etc. The security amount you have to understand is just getting ridiculous.
And let's not even mention DOS. No-one is securing against that and most servers can be made inaccessible by a simple script that just opens connections.
Considering that there's some low-hanging fruit still to be plucked, it's better for someone to point them out, and demonstrate the necessity to close these easily-leveraged gaps quickly, rather than to leave them open for someone much less scrupulous to misuse.
Edit: Its also running on my 4mb flash openwrt router, and has NO dependencies
C is definitely not known for easy and safe string processing, so I'm quite curious to see how it accomplishes that.
Also not terribly hard to write a small arbitrary length string library as part of the project.
a = "foo" + "bar"; is very useful so is b = a.split( "," ); or a = b.trim(); etc. C strings are rarely so convenient.
its more obvious with the more high level things you want. to do something like b = a.split( "," ); on a string that is not know until runtime you need dynamic allocations and you could use strtok to fill that memory with the results, but its an error-prone ballache by comparison.
Some don't nul terminate the string if it's longer than the destination buffer.
Also the return value can be -1 (correct behavior on failure, but it's often left unchecked) or more than destination buffer size! Fun times if you accumulate total written without range checking snprintf return value...
_snprintf, _snprintf_l, _snwprintf, _snwprintf_l -> https://msdn.microsoft.com/en-us/library/2ts7cx93.aspx
"If len > count, count characters are stored in buffer, no null-terminator is appended, and a negative value is returned."
Uh, what?I guess that's why it is _snprintf and not snprintf, huh?
They do provide secure [1] versions too, but you need to be careful which one you pick. Those secure versions terminate execution in some cases if buffer length is exceeded.
[1]: https://msdn.microsoft.com/en-us/library/f30dzcf6.aspx - better remember that _TRUNCATE flag.
i did it myself a lot a long time ago by teaching myself, but you are right that using some full featured server and some high level language targetting web development has much more convenience, especially if you care about rich features and security.
the C standard library and the usual set of headers and os functions that you get in most C environments is not what people tend to mean by dependencies....
Its quite possible to have a C-based sockets-/signals- handler in a single source file, say .. 48k lines of code or so. I've seen many robust system daemons with just such an implementation.
3rd party dependencies are definitely an issue that very few languages have managed to promote, since languages either want to promote (or demote) such circumstances as mass-package (i.e. mass usage of the language) in a broad commercial/industrial/social context.
But its not naive to write such things as a Wiki and a Blog in C. Just .. dangerous. I imagine there are, however, some good 3rd-party C libraries available to do less-dangerous implementations, however...
it is interesting stuff.
I've followed Steve off and on over the years. He seems to prefer C++ as a web-app language so much so that he blogs about it and other things. I like his stuff. I discovered Steve through Joel On Software some years ago. If memory serves me, I think at one time he was publishing a Web CMS type engine written in C++ but I could have him confused with someone else (been awhile)
Here is his site: http://stevehanov.ca/blog/index.php?id=95
not even sockets? because /that/ would be impressive.
Unix processes creation is lightweight and fast, unlike Windows.
I mean, what even is the point of sending me a file with a txt extension if you're not sending text headers?
I also recently found out about http://eigenstate.org/myrddin which seems more mature with very similar goals/aesthetics. I've been digging into it a fair bit.
Finally, on the extreme other end of the spectrum, there's Rust.
seems that cgi-bin is also writable, can't make the file executable though
/cgi-bin/wiki?../../../srv/www/cgi-bin/wiki\0txt.e
<script type="text/javascript">alert('you guys better watch out for dat XSS and XSRF bidness');</script>
Oh god, this shit is sooooo not secure.Not a lot you can do with just the latin alphabet, numerals and a space.
Be respectful. Anyone sharing work is making a contribution, however modest.
Instead of "you're doing it wrong", suggest alternatives. When someone is learning, help them learn more.
Would you consider rewriting something like this in rust or go, and doing a comparison? I think you would have found things to combat XSS in either of those languages (safe templating), would be interested to see the differences... And if any of those languages deliver on their promise to be safer than C
http://stackoverflow.com/questions/29008127/why-are-rust-exe...