From 51a0e823fbaf3b9163ce72bb9e2b02f5f6583c6c Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Tue, 30 Mar 2021 10:05:43 +1000 Subject: [PATCH] * csocket processing: handle \r\n lines --- src/csocket.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/csocket.c b/src/csocket.c index 6ea50fa..14b7ee7 100644 --- a/src/csocket.c +++ b/src/csocket.c @@ -176,9 +176,14 @@ f2b_conn_process(f2b_conn_t *conn, bool in, void (*cb)(const f2b_cmd_t *cmd, f2b f2b_log_msg(log_debug, "received %zd bytes from socket %d, append %d to buf", read, conn->sock, retval); /* extract message(s) */ while ((line = f2b_buf_extract(&conn->recv, "\n")) != NULL) { - if (strlen(line) == 0) { + size_t len = strlen(line); + if (len <= 0) { free(line); continue; + } /* else: len > 0 */ + if (line[len - 1] == '\r') { + /* strip CR */ + line[len - 1] = '\0'; len--; } f2b_log_msg(log_debug, "extracted line: %s", line); if ((cmd = f2b_cmd_create(line)) != NULL) {