Skip to content

Commit

Permalink
Fix UB introduced by copying detail::FormatListN objects. (#59)
Browse files Browse the repository at this point in the history
When copying a detail::FormatListN object, the m_formatterStore must also be copied, otherwise the pointer in the parent FormatList class are possibly invalid.

This addresses the segfault explained in #58. The issue arises when makeFormatList returns an object which holds a pointer to memory created for the temporary object on the stack.
  • Loading branch information
dakep authored and c42f committed Nov 8, 2019
1 parent 4d03ee3 commit 705e3f4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tinyformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,10 @@ class FormatListN : public FormatList
TINYFORMAT_FOREACH_ARGNUM(TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR)
# undef TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR
#endif
FormatListN(const FormatListN& other)
: FormatList(&m_formatterStore[0], N)
{ std::copy(&other.m_formatterStore[0], &other.m_formatterStore[N],
&m_formatterStore[0]); }

private:
FormatArg m_formatterStore[N];
Expand Down

0 comments on commit 705e3f4

Please sign in to comment.