Add ASSERTs to prevent re-entrancy inside CPWL_EditImpl_Undo.
In CPWL_EditImpl_Undo, |m_bWorking| is suppose to protect Redo() and
Undo() so nothing gets added in the middle of a redo/undo action. This
only works if Redo() and Undo() are not re-entrant. In the case of
re-entrancy, what can happen is:
1. First Undo() call starts, sets |m_bWorking| to true.
2. Second Undo() call starts, sets |m_bWorking| to true again.
3. Second Undo() call finishes, sets |m_bWorking| to false.
4. First Undo() call finishes, sets |m_bWorking| to false again.
Between events 3 and 4, there is a gap where the first Undo() call has
not finished, and |m_bWorking| is suppose to be true, but has already
been set to false.
Change-Id: I402714f480cb061a5fef83b0c81d10e0a31df83f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/57170
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/pwl/cpwl_edit_impl.cpp b/fpdfsdk/pwl/cpwl_edit_impl.cpp
index 0988c1f..494bc1b 100644
--- a/fpdfsdk/pwl/cpwl_edit_impl.cpp
+++ b/fpdfsdk/pwl/cpwl_edit_impl.cpp
@@ -209,6 +209,7 @@
}
void CPWL_EditImpl_Undo::Undo() {
+ ASSERT(!m_bWorking);
m_bWorking = true;
int nUndoRemain = 1;
while (CanUndo() && nUndoRemain > 0) {
@@ -217,6 +218,7 @@
nUndoRemain--;
}
ASSERT(nUndoRemain == 0);
+ ASSERT(m_bWorking);
m_bWorking = false;
}
@@ -225,6 +227,7 @@
}
void CPWL_EditImpl_Undo::Redo() {
+ ASSERT(!m_bWorking);
m_bWorking = true;
int nRedoRemain = 1;
while (CanRedo() && nRedoRemain > 0) {
@@ -233,6 +236,7 @@
nRedoRemain--;
}
ASSERT(nRedoRemain == 0);
+ ASSERT(m_bWorking);
m_bWorking = false;
}