From b9cdabca5d0b7ea3b5b88b57502196e9f45c02e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Fri, 28 Jul 2023 04:22:59 +0200 Subject: xC: fix relay handling of missing log files Intermediate error messages would trash the prepared static buffer. --- xC.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/xC.c b/xC.c index a589836..5a59a8f 100644 --- a/xC.c +++ b/xC.c @@ -15543,14 +15543,13 @@ static void client_process_buffer_log (struct client *c, uint32_t seq, struct buffer *buffer) { - struct relay_event_data_response *e = relay_prepare_response (c->ctx, seq); - e->data.command = RELAY_COMMAND_BUFFER_LOG; - + // XXX: We log failures to the global buffer, + // so the client just receives nothing if there is no log file. + struct str log = str_make (); char *path = buffer_get_log_path (buffer); FILE *fp = open_log_path (c->ctx, buffer, path); if (fp) { - struct str log = str_make (); char buf[BUFSIZ]; size_t len; while ((len = fread (buf, 1, sizeof buf, fp))) @@ -15558,17 +15557,15 @@ client_process_buffer_log if (ferror (fp)) log_global_error (c->ctx, "Failed to read `#l': #l", path, strerror (errno)); - - // On overflow, it will later fail serialization. - e->data.buffer_log.log_len = MIN (UINT32_MAX, log.len); - e->data.buffer_log.log = (uint8_t *) str_steal (&log); fclose (fp); } - - // XXX: We log failures to the global buffer, - // so the client just receives nothing if there is no log file. - free (path); + + struct relay_event_data_response *e = relay_prepare_response (c->ctx, seq); + e->data.command = RELAY_COMMAND_BUFFER_LOG; + // On overflow, it will later fail serialization (frame will be too long). + e->data.buffer_log.log_len = MIN (UINT32_MAX, log.len); + e->data.buffer_log.log = (uint8_t *) str_steal (&log); relay_send (c); } -- cgit v1.2.3