+
+ /* Naughty NULL bytes inside the request? */
+ c_len = strlen(buf);
+ if (c_len < len)
+ {
+ /*
+ * Yes. Log the request, return an
+ * error response and hang up.
+ */
+ size_t tmp_len = c_len;
+
+ do
+ {
+ /*
+ * Replace NULL byte(s) with line break(s)
+ * so the request can be logged as string.
+ */
+ buf[tmp_len]='\n';
+ tmp_len += strlen(buf+tmp_len);
+ } while (tmp_len < len);
+
+ log_error(LOG_LEVEL_ERROR, "%s\'s request contains NULL byte(s) "
+ "(length=%d, strlen=%d).", csp->ip_addr_str, len, c_len);
+ log_error(LOG_LEVEL_HEADER,
+ "Denied request with NULL byte(s) turned into line break(s):\n%s", buf);
+
+ strcpy(buf, NULL_BYTE_RESPONSE);
+ write_socket(csp->cfd, buf, strlen(buf));
+
+ /* XXX: Log correct size */
+ log_error(LOG_LEVEL_CLF, "%s - - [%T] \"Invalid request\" 400 0", csp->ip_addr_str);
+
+ return;
+ }
+