diff options
author | June McEnroe <june@causal.agency> | 2020-08-06 13:38:52 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-08-06 13:38:52 -0400 |
commit | 4046ddacddced524615f8314d6389b971843d9b9 (patch) | |
tree | c05334433a888089033d51d31640618f1bfce892 | |
parent | Document concatenating client certificates for auth (diff) | |
download | pounce-4046ddacddced524615f8314d6389b971843d9b9.tar.gz pounce-4046ddacddced524615f8314d6389b971843d9b9.zip |
Handle broken clients sending only \n
Sigh. The robustness principle enables the proliferation of worse quality software.
-rw-r--r-- | client.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/client.c b/client.c index 4f315c8..30174e9 100644 --- a/client.c +++ b/client.c @@ -358,21 +358,22 @@ void clientRecv(struct Client *client) { } client->len += read; - char *crlf; + char *lf; char *line = client->buf; for (;;) { - crlf = memmem(line, &client->buf[client->len] - line, "\r\n", 2); - if (!crlf) break; + lf = memchr(line, '\n', &client->buf[client->len] - line); + if (!lf) break; if (verbose) { - fprintf(stderr, "\x1B[33m%.*s\x1B[m\n", (int)(crlf - line), line); + fprintf(stderr, "\x1B[33m%.*s\x1B[m\n", (int)(lf - line), line); } - if (client->need || intercept(line, crlf - line)) { - crlf[0] = '\0'; + if (client->need || intercept(line, lf - line)) { + lf[0] = '\0'; + if (lf - line && lf[-1] == '\r') lf[-1] = '\0'; clientParse(client, line); } else { - serverSend(line, crlf + 2 - line); + serverSend(line, lf + 1 - line); } - line = crlf + 2; + line = lf + 1; } client->len -= line - client->buf; memmove(client->buf, line, client->len); |