Skip to content

Commit

Permalink
Merge pull request #192 from lkeegan/pmcx_bc_overflow_error
Browse files Browse the repository at this point in the history
Fix buffer overflow error when bc has 12 characters
  • Loading branch information
fangq authored Oct 3, 2023
2 parents 7e75498 + 3c77170 commit 35170f9
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 35170f9

Please sign in to comment.