diff options
| author | Craig Jennings <c@cjennings.net> | 2025-11-13 15:03:32 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-11-13 15:03:32 -0600 |
| commit | 09c802cfcb40a2c1415ca5707c80b4be62380c99 (patch) | |
| tree | 83a033fa19977a688695a3f65514d4b3d0b0e013 | |
| parent | 8a1de84bd25c0f583c9f10402fd62ae477242808 (diff) | |
| download | org-drill-09c802cfcb40a2c1415ca5707c80b4be62380c99.tar.gz org-drill-09c802cfcb40a2c1415ca5707c80b4be62380c99.zip | |
Fix potential infinite loop in marker selection
Added safety counter to prevent infinite loop when all pending entries
are invalid (deleted or no longer have drill tag).
Changes:
- Added attempts counter with max-attempts limit of 1000
- Loop now exits if max attempts reached
- Returns nil if no valid entry found after exhausting attempts
Impact: Prevents infinite loop if all pending entries become invalid,
which could happen if entries are deleted or tags are removed during
a session.
Fixes severity B bug in todo.org
| -rw-r--r-- | org-drill.el | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/org-drill.el b/org-drill.el index ee335af..80081c9 100644 --- a/org-drill.el +++ b/org-drill.el @@ -2618,9 +2618,12 @@ maximum number of items." (defun org-drill-pop-next-pending-entry (session) (cl-block org-drill-pop-next-pending-entry - (let ((m nil)) - (while (or (null m) - (not (org-drill-entry-p m))) + (let ((m nil) + (attempts 0) + (max-attempts 1000)) ; Safety limit to prevent infinite loop + (while (and (or (null m) + (not (org-drill-entry-p m))) + (< attempts max-attempts)) (setq m (cond @@ -2660,8 +2663,12 @@ maximum number of items." ((oref session again-entries) (pop (oref session again-entries))) (t ; nothing left -- return nil - (cl-return-from org-drill-pop-next-pending-entry nil))))) - m))) + (cl-return-from org-drill-pop-next-pending-entry nil)))) + (cl-incf attempts)) + ;; If we exhausted attempts trying to find a valid entry, return nil + (if (>= attempts max-attempts) + nil + m)))) (defun org-drill-entries (session &optional resuming-p) "Returns nil, t, or a list of markers representing entries that were |
