xC: fix relay handling of missing log files

Intermediate error messages would trash the prepared static buffer.
This commit is contained in:
Přemysl Eric Janouch 2023-07-28 04:22:59 +02:00
parent f60ca43156
commit b9cdabca5d
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 9 additions and 12 deletions

21
xC.c
View File

@ -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);
}