Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by danieltillett on Friday December 04, 2015 @04:10AM
(#10675350)
I really think we should stop being so mean to the submitter. Sure the code might have problems and the whole approach might not be advisable, but I am sure they have learned a lot from doing this. Ronsor congratulations for actually shipping.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by danieltillett on Friday December 04, 2015 @04:34AM
(#10675415)
Yes it should not be getting the attention it is getting right now, but we can approach this in a more generous fashion. Let's help rather than ridicule.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by frgewut on Friday December 04, 2015 @10:20AM
(#10676738)
Well even Google still has tons of bugs (including XSS and XSRF).
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.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by qwontem on Friday December 04, 2015 @04:32AM
(#10675409)
I wouldn't characterize a collegial inspection of key security/durability features a website should employ as mean-spirited.
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.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by sdegutis on Thursday December 03, 2015 @10:49PM
(#10674473)
Excited to see the code. C isn't known for being great for writing high level applications like this, so I'm really curious what the source looks like. Especially since it has no dependencies!
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by jheriko on Thursday December 03, 2015 @11:30PM
(#10674620)
you may be surprised how easy it is to write a http server that replies with html in C... its all just text going over sockets after all.
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.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by emcrazyone on Friday December 04, 2015 @01:21AM
(#10674983)
It is relatively easy. I've done it myself many moons ago.
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)
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by jheriko on Friday December 04, 2015 @12:23AM
(#10674835)
i doubt it tbh, i bet he means no /3rd party/ dependencies other than the ones that came with the development environment.
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....
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by fit2rule on Friday December 04, 2015 @08:45AM
(#10676242)
POSIX?
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...
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by vardump on Friday December 04, 2015 @03:49AM
(#10675293)
Not all implementations of snprintf behave the same way. Many are subtly broken.
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...
"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.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by jheriko on Thursday December 03, 2015 @11:45PM
(#10674680)
its still not as easy as in languages with modern libraries.
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.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by kbenson on Friday December 04, 2015 @01:58AM
(#10675074)
I still maintain that + is a terrible operator for concatenating strings, and results in quite a few types of bugs that are pervasive in many languages (usually from trying to automatically coerce non-matching operands).
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by emcrazyone on Friday December 04, 2015 @01:18AM
(#10674977)
I think what the OP meant was no 3rd party library dependencies such as a CGI library and that he's still dependent on OS system calls such as file I/O and sockets.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by z92 on Friday December 04, 2015 @03:00AM
(#10675197)
You don't need sockets. I used xinetd instead. Got the idea from someone else on the net. Not uncommon. And performance isn't bad either just 10% less than what it could have been, even if every request spawns a process.
Unix processes creation is lightweight and fast, unlike Windows.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by krapp on Friday December 04, 2015 @12:50AM
(#10674902)
It looks interesting. Unfortunately, judging from the comments here, it's also more or less useless. I really look forward to seeing the source code, though, but the hard part is the part that seems not yet done - which is the security.
I mean, what even is the point of sending me a file with a txt extension if you're not sending text headers?
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by dbpokorny on Thursday December 03, 2015 @11:00PM
(#10674523)
What are your thoughts re: adding memory protection to C? (in other words: add a distinction between "pointer bytes" and "raw data bytes" and some rules regarding pointer assignment, arithmetic, and dereferencing that serve to treat the pointer bytes as protected memory of a "3rd space" that sits between kernel space and user space; thereby ensuring that a program can only obtain a pointer to either a stack location (with restrictions) or heap location that points to a byte in an allocated segment of memory?)
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by akkartik on Thursday December 03, 2015 @11:47PM
(#10674694)
I've actually been building a teaching VM with these properties. You can't take the address of arbitrary values (so there's no distinction between lvalues and rvalues), there's no pointer arithmetic (instead you have type-safe primitives for record access and array indexing), all arrays (including strings) know their length and bounds-check accesses, and unions behave more like sum types, always knowing precisely what type they have stored. All these constraints ensure you can never convert a number to an address, or generate an address to an illegal value. More info about the goal and rationale: http://akkartik.name/post/mu;http://github.com/akkartik/mu.
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.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by erikb on Friday December 04, 2015 @04:05AM
(#10675333)
Now that more than enough people complained about security etc. I also want to add that a modern wiki doesn't really work with their own grammar anymore. Consider changing to markdown, restructuredText, MediaWiki, or Atlassian style (last not really suggested but better than nothing).
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by unboxed_type on Friday December 04, 2015 @05:07AM
(#10675504)
It is interesting from performance and low resource consumption point of view. Great work! I wonder if someone would like to do the same in assembly language for even more crazy experiment -)
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by bschiett on Friday December 04, 2015 @06:06AM
(#10675651)
this is still an awesome project, unfortunately there will be lots of python and ruby hipsters here who will dismiss this project... it doesn't matter, since most software you use is built in C or C++, and that won't change anytime soon :-)
Re:Show HN: Demo of Wiki and Forum coded in C under 80k
by hardwaresofton on Friday December 04, 2015 @03:11AM
(#10675214)
Not trying to be snarky, but if the goal was to show why you shouldn't do something like this, you've succeeded.
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
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
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.
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
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.
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.
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
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.
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.
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
http://home.ronsor.gq:12321/cgi-bin/ohshit.txt
/cgi-bin/wiki?../../../srv/www/cgi-bin/wiki\0txt.e
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.
https://news.ycombinator.com/showhn.html
Not a lot you can do with just the latin alphabet, numerals and a space.
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...
https://golang.org/doc/go1.5#compiler