From e6049c620690c04076cbf323475e94689a84d872 Mon Sep 17 00:00:00 2001 From: Eric Richter Date: Tue, 23 Jul 2024 10:55:26 -0500 Subject: [PATCH] guest/read: don't attempt to print an ESL from a zero-sized buffer Currently, print_esl_buffer() passes along the input buffer and size to next_esl_from_buffer(), which will immediately error since a buffer size of zero obviously cannot contain an ESL. This can sometimes happen when printing a variable that contains a timestamp but no data -- the most obvious example being a variable that was cleared. Therefore, a message should be printed to indicate there is no data, rather than an error message that should be reserved for when the data is actually malformed. Signed-off-by: Eric Richter --- backends/guest/common/read.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backends/guest/common/read.c b/backends/guest/common/read.c index 5271c66a..09f697e9 100644 --- a/backends/guest/common/read.c +++ b/backends/guest/common/read.c @@ -197,6 +197,12 @@ int print_esl_buffer(const uint8_t *buffer, size_t buffer_size, const char *var_ } curr_esl; curr_esl.raw = NULL; + // Do not bother reading from zero-size buffers + if (buffer_size == 0) { + printf("(empty)\n"); + return SUCCESS; + } + rc = next_esl_from_buffer(buffer, buffer_size, &curr_esl.raw, &esl_data_size); if (rc) { prlog(PR_ERR, "Error reading from esl buffer: %d\n", rc);