summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNathan Angelacos <nangel@alpinelinux.org>2008-01-25 22:08:15 +0000
committerNathan Angelacos <nangel@alpinelinux.org>2008-01-25 22:08:15 +0000
commit5e7e0d5adf033df30115eb427a77ac18303599ee (patch)
tree7390adf2bd393facd3786a1946a75dbbe9841e20 /src
parent4c80d5d0a9059b10c46d0c9211bdd58a3eca0c64 (diff)
downloadhaserl-5e7e0d5adf033df30115eb427a77ac18303599ee.tar.bz2
haserl-5e7e0d5adf033df30115eb427a77ac18303599ee.tar.xz
Diego Santa Cruz's fixes
Diffstat (limited to 'src')
-rw-r--r--src/h_bash.c2
-rw-r--r--src/haserl.c4
-rw-r--r--src/rfc2388.c4
-rw-r--r--src/sliding_buffer.c8
-rw-r--r--src/sliding_buffer.h2
5 files changed, 19 insertions, 1 deletions
diff --git a/src/h_bash.c b/src/h_bash.c
index dbbdbc3..063a2c5 100644
--- a/src/h_bash.c
+++ b/src/h_bash.c
@@ -74,6 +74,7 @@ bash_setup (char *shell, list_t * env)
/* I'm the child, connect stdin to the parent */
dup2 (subshell_pipe[PARENT_IN], STDIN_FILENO);
close (subshell_pipe[PARENT_IN]);
+ close (subshell_pipe[PARENT_OUT]);
count = argc_argv (shell, &argv, "");
if (count > 19)
{
@@ -105,6 +106,7 @@ bash_setup (char *shell, list_t * env)
else
{
/* I'm parent, move along please */
+ close (subshell_pipe[PARENT_IN]);
}
}
diff --git a/src/haserl.c b/src/haserl.c
index ee95889..3c342d1 100644
--- a/src/haserl.c
+++ b/src/haserl.c
@@ -432,6 +432,10 @@ ReadCGIPOSTValues (list_t * env)
s_buffer_init (&sbuf, 32768);
sbuf.fh = STDIN;
+ if ( getenv( "CONTENT_LENGTH" ) )
+ {
+ sbuf.maxread = strtoul(getenv("CONTENT_LENGTH"), NULL, 10);
+ }
buffer_init (&token);
diff --git a/src/rfc2388.c b/src/rfc2388.c
index 13b6987..8fd626d 100644
--- a/src/rfc2388.c
+++ b/src/rfc2388.c
@@ -392,6 +392,10 @@ rfc2388_handler (list_t * env)
/* initialize a 128K sliding buffer */
s_buffer_init (&sbuf, 1024 * 128);
sbuf.fh = STDIN;
+ if (getenv("CONTENT_LENGTH"))
+ {
+ sbuf.maxread = strtoul(getenv("CONTENT_LENGTH"), NULL, 10);
+ }
/* initialize the buffer, and make sure it doesn't point to null */
buffer_init (&buf);
diff --git a/src/sliding_buffer.c b/src/sliding_buffer.c
index 9883b78..707de46 100644
--- a/src/sliding_buffer.c
+++ b/src/sliding_buffer.c
@@ -43,6 +43,8 @@ s_buffer_init (sliding_buffer_t * sbuf, int size)
sbuf->len = 0;
sbuf->ptr = sbuf->buf;
sbuf->bufsize = 0;
+ sbuf->maxread = 0;
+ sbuf->nrread = 0;
return (sbuf->buf != NULL); /* return true if the alloc succeeded */
}
@@ -98,7 +100,10 @@ s_buffer_read (sliding_buffer_t * sbuf, char *matchstr)
}
else
{
- r = read (sbuf->fh, sbuf->buf + len, sbuf->maxsize - len);
+ size_t n = sbuf->maxsize - len;
+ if ( sbuf->maxread && sbuf->maxread < sbuf->nrread + n)
+ n = sbuf->maxread - sbuf->nrread;
+ r = read (sbuf->fh, sbuf->buf + len, n);
}
/*
* only report eof when we've done a read of 0.
@@ -110,6 +115,7 @@ s_buffer_read (sliding_buffer_t * sbuf, char *matchstr)
else
{
sbuf->bufsize += (r > 0) ? r : 0;
+ sbuf->nrread += (r > 0) ? r : 0;
}
}
diff --git a/src/sliding_buffer.h b/src/sliding_buffer.h
index 83c7919..167e461 100644
--- a/src/sliding_buffer.h
+++ b/src/sliding_buffer.h
@@ -11,6 +11,8 @@ typedef struct {
size_t len; /* length of this segment */
size_t maxsize; /* max size of buffer */
size_t bufsize; /* current size of buffer */
+ size_t maxread; /* maximum number of bytes to read from fh, ignored if 0 */
+ size_t nrread; /* number of bytes read from fh */
int eof; /* true if there is no more to read */
} sliding_buffer_t;