This is a version of thttpd 2.29 that is being ported to Checked C with the help of 3C. Checked C is an extension of the C programming language that guarantees spatial memory safety (e.g., lack of buffer overflows) under certain assumptions.
For the original thttpd readme, see the README file.
The commits in the Git history of this repository represent steps of an incremental porting process, starting from an import of the original thttpd source code. You can use the usual Git commands to browse the history (git log), check out previous stages of the port (git checkout), etc. At any point, 3C can be run via the convert_all.sh script (details in the next section), and it will write updated versions of the source files to a subdirectory named out.checked. Each commit in the history consists of changes made by 3C (i.e., we ran 3C and then copied some of the code from out.checked back to the original files), manual edits we made to port the code to Checked C, or a combination of both.
This port serves as an example of our recommended Checked C porting process, which has evolved a bit from what is described in the the 3C usage documentation as of this writing (2021-12-08). We plan to make documentation of the new process available soon.
You can build thttpd, try to recreate previous porting steps we took (after checking out a previous commit), or improve the port further. Here's what you'll need to do:
-
Build 3C (including the
clangtarget), but contrary to the normal instructions, use Correct Computation'scheckedcrepository because the port requires changes to the checked system headers that we have not yet had time to upstream. The port has last been tested withcheckedc-clangcommit 79804ee066f04e44583dd6df2dbe883b466aef5d andcheckedccommit 19247d67f8c249eb1105c3ef05b49340e91458e8, so if you have trouble with the latest versions, try those versions. Add thebindirectory of 3C to your$PATH. -
Install Bear.
-
Run the following to build thttpd and generate
compile_commands.jsonfor use by 3C:CC=clang ./configure bear make -kCC=clanguses the Checked Cclangfrom step 1.-ktellsmaketo attempt compilation of all source files even if one of them has an error, which ensures that all source files get added tocompile_commands.json. Do not use a parallel build (-j): the makefiles aren't designed for it, and we've seen an issue where two differentmakeprocesses tried to buildmatch.oat the same time.We've seen a problem where the Checked C compiler sometimes crashes while compiling
libhttpd.c(the behavior is nondeterministic); we haven't yet investigated it. If you run into this, yourcompile_commands.jsonwill still be complete with the record that the compilation was attempted; just re-runmakewithoutbearto retry the compilation. -
To run a 3C pass on the whole project, run
./convert_all.sh. This writes the updated versions of the source files toout.checked. Rundiff -ru . out.checkedto see what 3C changed; you can then copy chunks of code from the new files to the original files as desired. See the 3C usage documentation for more information. -
To perform an incremental build after you change the source files, run the same
makecommand as in step 3, but withoutbear(because the full set of source files and compiler options hasn't changed, and usingbearon an incremental build would overwritecompile_commands.jsonto contain only the subset of files that changed in that build).
For a better experience working on Checked C code, consider using Checked C's clangd.