Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ Rev 2.3.6: 07.03.2026
Fixes:
* Fix for #167 (https://github.com/beltoforion/muparser/pull/167):
Added additional range checks for accessing internal value stack.
* Fix for #168 (https://github.com/beltoforion/muparser/pull/169):
ClearConst() now also clears m_vStringVarBuf to keep it in sync
with m_StrVarDef. Previously, repeated calls to ClearConst()
followed by DefineStrConst() caused stale entries to accumulate
in the string value buffer.


Rev 2.3.5: 13.12.2024
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Change Notes for Revision 2.3.6 (2026-04-10)
Security Fixes:
-----------
- Issue https://github.com/beltoforion/muparser/issues/167: Add additional checks to eliminate possibility of access violations due to malformed expressions. I dont have test cases and do not know whether this issue was exploitable at all but fixing them made sense.
- Issue https://github.com/beltoforion/muparser/issues/168: ClearConst() now also clears the internal string variable buffer (m_vStringVarBuf) to keep it in sync with the name-to-index map (m_StrVarDef). Previously stale entries accumulated across repeated ClearConst() calls.

Fixed Compiler Warnings and Errors:
-----------
Expand Down
3 changes: 2 additions & 1 deletion include/muParserTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ namespace mu
int TestOptimizer();
int TestLocalization();
int TestIssue165();

int TestIssue168();

void Abort() const;

public:
Expand Down
1 change: 1 addition & 0 deletions src/muParserBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,7 @@ namespace mu
{
m_ConstDef.clear();
m_StrVarDef.clear();
m_vStringVarBuf.clear();
ReInit();
}

Expand Down
56 changes: 56 additions & 0 deletions src/muParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace mu
AddTest(&ParserTester::TestOptimizer);
AddTest(&ParserTester::TestLocalization);
AddTest(&ParserTester::TestIssue165);
AddTest(&ParserTester::TestIssue168);

ParserTester::c_iCount = 0;
}
Expand Down Expand Up @@ -1751,6 +1752,61 @@ namespace mu
return iRet;
}

//---------------------------------------------------------------------------
// Regression test: ClearConst() must also clear m_vStringVarBuf.
//
// Currently ClearConst() clears m_StrVarDef but not m_vStringVarBuf, so
// the value buffer silently accumulates stale entries across calls. After
// one round of DefineStrConst + ClearConst + DefineStrConst the buffer
// should have 2 entries (not 4). This test will FAIL until the bug is fixed.
int ParserTester::TestIssue168()
{
ParserTester::c_iCount++;
int iRet(0);

mu::console() << _T("testing github issue 168...");

try
{
Parser p;
p.DefineFun(_T("strlen"), StrLen);

p.DefineStrConst(_T("s1"), _T("hello"));
p.DefineStrConst(_T("s2"), _T("world"));
p.SetExpr(_T("strlen(s1)+strlen(s2)"));
p.Eval();

p.ClearConst();

p.DefineStrConst(_T("s1"), _T("hi"));
p.DefineStrConst(_T("s2"), _T("!"));
p.SetExpr(_T("strlen(s1)+strlen(s2)"));
p.Eval();

// After ClearConst + re-registration the buffer should hold exactly
// 2 entries. If ClearConst does not clear it, the buffer has 4.
std::size_t sz = p.m_vStringVarBuf.size();
if (sz != 2)
{
mu::console() << _T("\n fail: m_vStringVarBuf.size() == ") << sz
<< _T(" (expected 2 — ClearConst does not clear the buffer)");
iRet++;
}

if (iRet == 0)
mu::console() << _T("passed") << endl;
else
mu::console() << _T("\n failed with ") << iRet << _T(" errors") << endl;
}
catch (...)
{
mu::console() << _T("\n fail: unexpected exception");
return 1;
}

return iRet;
}

//---------------------------------------------------------------------------
int ParserTester::EqnTestInt(const string_type& a_str, double a_fRes, bool a_fPass)
{
Expand Down
Loading