/*
* uhttpd - Tiny single-threaded httpd - CGI handler
*
- * Copyright (C) 2010 Jo-Philipp Wich <xm@subsignal.org>
+ * Copyright (C) 2010-2011 Jo-Philipp Wich <xm@subsignal.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
bufptr = &buf[0];
- for( pos = 0; pos < len; pos++ )
+ for( pos = 0; pos < *off; pos++ )
{
if( !hdrname && (buf[pos] == ':') )
{
else if( (buf[pos] == '\r') || (buf[pos] == '\n') )
{
- buf[pos++] = 0;
-
if( ! hdrname )
break;
+ buf[pos++] = 0;
+
if( (pos < len) && (buf[pos] == '\n') )
pos++;
fd_set reader;
fd_set writer;
+ sigset_t ss;
+
struct sigaction sa;
struct timeval timeout;
struct http_response *res;
/* exec child */
case 0:
+ /* unblock signals */
+ sigemptyset(&ss);
+ sigprocmask(SIG_SETMASK, &ss, NULL);
+
/* restore SIGTERM */
sa.sa_flags = 0;
sa.sa_handler = SIG_DFL;
dup2(rfd[1], 1);
dup2(wfd[0], 0);
+ /* avoid leaking our pipe into child-child processes */
+ fd_cloexec(rfd[1]);
+ fd_cloexec(wfd[0]);
+
/* check for regular, world-executable file _or_ interpreter */
if( ((pi->stat.st_mode & S_IFREG) &&
(pi->stat.st_mode & S_IXOTH)) || (ip != NULL)