5

I am developing a site for online C coding competition. The coding will be done in an editor that will be embedded in the webpage, and this must also be able to compile the program online. Is there any available compiler that can be embedded in the webpage? The server can be either linux or windows server. If anyone has any idea please share.

Dolphin
  • 333
  • 1
  • 3
  • 9
  • I think, you should send a text to server, start a compiler (e.g gcc) on server (smth like `system()`) and post results (compilererrors and warnings) back to the page. – osgx Aug 04 '11 at 10:05
  • Why don't you use system() to call a traditional compiler? – ckruse Aug 04 '11 at 10:06
  • 1
    Not concrete code but some info of how it has been done: http://codepad.org/about – hakre Aug 04 '11 at 10:08

1 Answers1

6

Well, you can always write a script that invokes an installed compiler through system() commands. Although you want to be very, very careful as this can be very dangerous. For example if you do not sanitize your input, then someone could inject commands which intentionally crash/damage your system.

Waleed Amjad
  • 6,716
  • 4
  • 35
  • 35
  • 1
    +1 Also take a look @ http://stackoverflow.com/questions/3695858/how-do-sites-like-codepad-org-sandbox-your-program for sandboxing info – Alex K. Aug 04 '11 at 10:12
  • 2
    Sanitizing up-front is impossible with every programming language save incredibly simplistic toy languages. Limiting what the program can actually do (blocking most if not all syscalls, sandboxing, timeouts, etc.) should be way more effective. –  Aug 04 '11 at 10:13
  • 2
    You are absolutely right delnan, the OP probably wants to restrict the set of allowable C functions to a subset that is safe to use. Will also need to implement some sort of maximum execution timeout for not only the whole script but also for loops and so on... it's not an easy task. – Waleed Amjad Aug 04 '11 at 10:20