From 3c77170c2c0d3156e5c180f7927ecc243da21647 Mon Sep 17 00:00:00 2001 From: Liam Keegan Date: Mon, 2 Oct 2023 17:09:55 +0200 Subject: [PATCH] Fix buffer overflow error when bc has 12 characters - mcx_config.bc has type char[12], with no null terminator required - resolves #191 --- src/pmcx.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pmcx.cpp b/src/pmcx.cpp index 6e17320e..cfc09705 100644 --- a/src/pmcx.cpp +++ b/src/pmcx.cpp @@ -723,11 +723,10 @@ void parse_config(const py::dict& user_cfg, Config& mcx_config) { std::string bc_string = py::str(user_cfg["bc"]); if (bc_string.empty() || bc_string.size() > 12) { - throw py::value_error("the 'bc' field must be a non-empty string / have less than 12 characters."); + throw py::value_error("the 'bc' field must be a non-empty string / have no more than 12 characters."); } - strncpy(mcx_config.bc, bc_string.c_str(), bc_string.size() + 1); - mcx_config.bc[bc_string.size()] = '\0'; + strncpy(mcx_config.bc, bc_string.c_str(), bc_string.size()); } if (user_cfg.contains("detphotons")) {