auth-filter: do not write more than we've read

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Šī revīzija ir iekļauta:
Jason A. Donenfeld 2018-07-14 05:09:27 +02:00
vecāks c3b5b5f648
revīzija 93a2c33051

4
cgit.c
Parādīt failu

@ -659,13 +659,13 @@ static inline void open_auth_filter(const char *function)
static inline void authenticate_post(void) static inline void authenticate_post(void)
{ {
char buffer[MAX_AUTHENTICATION_POST_BYTES]; char buffer[MAX_AUTHENTICATION_POST_BYTES];
unsigned int len; ssize_t len;
open_auth_filter("authenticate-post"); open_auth_filter("authenticate-post");
len = ctx.env.content_length; len = ctx.env.content_length;
if (len > MAX_AUTHENTICATION_POST_BYTES) if (len > MAX_AUTHENTICATION_POST_BYTES)
len = MAX_AUTHENTICATION_POST_BYTES; len = MAX_AUTHENTICATION_POST_BYTES;
if (read(STDIN_FILENO, buffer, len) < 0) if ((len = read(STDIN_FILENO, buffer, len)) < 0)
die_errno("Could not read POST from stdin"); die_errno("Could not read POST from stdin");
if (write(STDOUT_FILENO, buffer, len) < 0) if (write(STDOUT_FILENO, buffer, len) < 0)
die_errno("Could not write POST to stdout"); die_errno("Could not write POST to stdout");