#include "cgic.h" /* Change this to point to a reasonable location on your system */ #define COMMENT_FILE "/CHANGE/THIS/PATH/comments.txt" int cgiMain() { /* Large enough buffers for any reasonable real name and email address. */ char name[256]; char email[256]; /* The comments themselves may be quite large, so we'll allocate space once we know how large they are. */ char *comments; /* Space needed for the comments string. */ int needed; /* Keep the results so we can complain if fields are missing. */ int rName, rEmail, rComments; FILE *out; /* Output the usual MIME header. */ cgiHeaderContentType("text/html"); /* Start the HTML document. */ fprintf(cgiOut, "\n
\n"); /* cgiFormStringNoNewlines() will never overflow buffers or write a non-terminated string. Also, even if the user's browser is defective, it will not return any carriage returns or line feeds. */ rName = cgiFormStringNoNewlines("name", name, sizeof(name)); rEmail = cgiFormStringNoNewlines("email", email, sizeof(email)); /* cgiFormStringSpaceNeeded the number of bytes of space guaranteed to be adequate for the string in question, including the terminating null. */ rComments = cgiFormStringSpaceNeeded("comments", &needed); /* Now check for missing fields. */ if ((rName == cgiFormNotFound) || (rEmail == cgiFormNotFound) || (rComments == cgiFormNotFound)) { /* If any field is missing, complain! */ fprintf(cgiOut, "