From 09c802cfcb40a2c1415ca5707c80b4be62380c99 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 13 Nov 2025 15:03:32 -0600 Subject: 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 --- org-drill.el | 17 ++++++++++++----- 1 file 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 -- cgit v1.2.3