Skip to content

Commit

Permalink
Fix buffer overflow error when bc has 12 characters
Browse files Browse the repository at this point in the history
- mcx_config.bc has type char[12], with no null terminator required
- resolves #191
  • Loading branch information
lkeegan committed Oct 2, 2023
1 parent 7e75498 commit 3c77170
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/pmcx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down

0 comments on commit 3c77170

Please sign in to comment.