From 385c6cb09714593be3aa5b5d123e4e42bf4fbb05 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Fri, 3 Nov 2023 11:08:54 +0100 Subject: [PATCH] edid-decode: safely terminate edid vector with 0 We are using string functions for the EDID format parsing that depend on 0-terminated sequences, so to be safe add a '\0' after reading the EDID file. Drop it again when it is processed as a binary file. Signed-off-by: Hans Verkuil --- edid-decode.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/edid-decode.cpp b/edid-decode.cpp index dfeb2b9..515a3b5 100644 --- a/edid-decode.cpp +++ b/edid-decode.cpp @@ -1001,6 +1001,8 @@ static bool extract_edid(int fd, FILE *error) state.edid_size = 0; return false; } + // Ensure it is safely terminated by a 0 char + edid_data.push_back('\0'); const char *data = &edid_data[0]; const char *start; @@ -1045,6 +1047,9 @@ static bool extract_edid(int fd, FILE *error) if (i == 32) return extract_edid_hex(data); + // Drop the extra '\0' byte since we now assume binary data + edid_data.pop_back(); + /* Assume binary */ if (edid_data.size() > sizeof(edid)) { fprintf(error, "Binary EDID length %zu is greater than %zu.\n", -- 2.11.4.GIT