From 585a4c61703ce3dfaa0319f9f7aceff7b2becc54 Mon Sep 17 00:00:00 2001 From: James Crook Date: Sun, 4 Mar 2018 18:40:21 +0000 Subject: [PATCH] Prevent excessive macro reentry. User could have made a macro call itself. Or could have an 'exploding' macro chain with 'too much' in it. So limit it to a macro can call a macro, but not deeper. --- src/BatchCommands.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/BatchCommands.cpp b/src/BatchCommands.cpp index 487eccb35..a9b5ae004 100644 --- a/src/BatchCommands.cpp +++ b/src/BatchCommands.cpp @@ -751,16 +751,27 @@ bool MacroCommands::ApplyCommandInBatchMode(const wxString & command, const wxSt return ApplyCommand( command, params ); } +static int MacroReentryCount = 0; // ApplyMacro returns true on success, false otherwise. // Any error reporting to the user in setting up the chain // has already been done. bool MacroCommands::ApplyMacro(const wxString & filename) { + // Check for reentrant ApplyMacro commands. + // We'll allow 1 level of reentry, but not more. + // And we treat ignoring deeper levels as a success. + if( MacroReentryCount > 1 ) + return true; + + // Restore the reentry counter (to zero) when we exit. + auto cleanup1 = valueRestorer( MacroReentryCount); + MacroReentryCount++; + mFileName = filename; AudacityProject *proj = GetActiveProject(); bool res = false; - auto cleanup = finally( [&] { + auto cleanup2 = finally( [&] { if (!res) { if(proj) { // Macro failed or was cancelled; revert to the previous state @@ -801,7 +812,8 @@ bool MacroCommands::ApplyMacro(const wxString & filename) if (!proj) return false; - proj->PushState(longDesc, shortDesc); + if( MacroReentryCount <= 1 ) + proj->PushState(longDesc, shortDesc); return true; }