From 07fdd581bbdd550df65acd91e4c2dd6e2f52385e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 9 Jun 2014 02:09:10 +0200 Subject: m + fix echo server crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-echo.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/mds-echo.c b/src/mds-echo.c index c9087c5..f2b1f82 100644 --- a/src/mds-echo.c +++ b/src/mds-echo.c @@ -276,6 +276,7 @@ int echo_message(void) #undef __get_header + if ((recv_client_id == NULL) || (strequals(recv_client_id, "0:0"))) { eprint("received message from anonymous sender, ignoring."); @@ -289,7 +290,7 @@ int echo_message(void) n = 1 + strlen("To: \nIn response to: \nMessage ID: \n\n"); n += strlen(recv_client_id) + strlen(recv_message_id) + 10; - if (recv_length) + if (recv_length != NULL) n += strlen(recv_length) + 1; if ((echo_buffer_size < n) || (echo_buffer_size * 4 > n)) @@ -302,14 +303,12 @@ int echo_message(void) } } - sprintf(echo_buffer, "To: %s\nIn response to:%s\nMessage ID: " PRIi32 "\n%s%s\n", + sprintf(echo_buffer, "To: %s\nIn response to: %s\nMessage ID: %" PRIi32 "\n%s%s\n", recv_client_id, recv_message_id, message_id, recv_length == NULL ? "" : recv_length, recv_length == NULL ? "" : "\n"); - message_id += 1; - if (message_id < 0) - message_id = 0; + message_id = message_id == INT32_MAX ? 0 : (message_id + 1); if (full_send(echo_buffer, n - 1)) return 1; -- cgit v1.2.3-70-g09d2