From 74c514a5b50a19197a64a86095bc0429188adcbe Mon Sep 17 00:00:00 2001 From: Mikael Olsson Date: Mon, 7 Aug 2023 17:42:18 +0200 Subject: Fix parser not always null-terminating model desc The inference parser copies the description from the model using strncpy, which will only add a null-terminator if the source string is shorter than the destination. Otherwise, if the bytes copied are not null-terminated, the destination is left without one. To ensure that the description is always null-terminated, the last byte of the description is now always overwritten with one. Change-Id: I49c23acd12d661e1f5c37088dba2e37935f25fa5 Signed-off-by: Mikael Olsson --- applications/inference_process/include/inference_parser.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/applications/inference_process/include/inference_parser.hpp b/applications/inference_process/include/inference_parser.hpp index 1ba8abf..1251648 100644 --- a/applications/inference_process/include/inference_parser.hpp +++ b/applications/inference_process/include/inference_parser.hpp @@ -80,7 +80,11 @@ public: if (model == nullptr) { return true; } - strncpy(description, model->description()->c_str(), sizeof(description)); + + // Depending on the src string, strncpy may not add a null-terminator + // so one is manually added at the end. + strncpy(description, model->description()->c_str(), S - 1); + description[S - 1] = '\0'; // Get input dimensions for first subgraph auto *subgraph = *model->subgraphs()->begin(); -- cgit v1.2.1