Skip to content

Commit

Permalink
fix use-after-free with regex_match()
Browse files Browse the repository at this point in the history
The smatch does not copy the input, it points to the original. So if the
string is on the stack and goes out of scope because it's only used as a
parameter, it will just be junk. Make a copy of it at a higher scope.
  • Loading branch information
taviso authored and jwiegley committed Aug 8, 2024
1 parent 7718901 commit efd55c7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/draft.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ void draft_t::parse_args(const value_t& args)
value_t::sequence_t::const_iterator end = args.end();

for (; begin != end; begin++) {
string arg = (*begin).to_string();

if (check_for_date &&
regex_match((*begin).to_string(), what, date_mask)) {
regex_match(arg, what, date_mask)) {
tmpl->date = parse_date(what[0]);
check_for_date = false;
}
else if (check_for_date &&
bool(weekday = string_to_day_of_week((*begin).to_string()))) {
bool(weekday = string_to_day_of_week(arg))) {
#if defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 7
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
Expand All @@ -124,8 +126,6 @@ void draft_t::parse_args(const value_t& args)
check_for_date = false;
}
else {
string arg = (*begin).to_string();

if (arg == "at") {
if (++begin == end)
throw std::runtime_error(_("Invalid xact command arguments"));
Expand Down

0 comments on commit efd55c7

Please sign in to comment.