From 5234cc1b579814ea0d13a33e888b798e9a4bb015 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 22 May 2021 01:24:09 +0300
Subject: [PATCH 60/60] rssanity: Break out from obsoleted_by loop

Server was left in an infinite loop when it detected
an obsoleted_by loop.

See osdn #42301

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 server/rssanity.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/server/rssanity.c b/server/rssanity.c
index 608591061a..a345d620c2 100644
--- a/server/rssanity.c
+++ b/server/rssanity.c
@@ -706,6 +706,7 @@ bool sanity_check_ruleset_data(bool ignore_retired)
                    * immediately so all errors get printed, not just first
                    * one. */
   bool default_gov_failed = FALSE;
+  bool obsoleted_by_loop = FALSE;
 
   if (!sanity_check_metadata()) {
     ok = FALSE;
@@ -872,7 +873,7 @@ bool sanity_check_ruleset_data(bool ignore_retired)
     int chain_length = 0;
     const struct unit_type *upgraded = putype;
 
-    while (upgraded != NULL) {
+    while (upgraded != NULL && !obsoleted_by_loop) {
       upgraded = upgraded->obsoleted_by;
       chain_length++;
       if (chain_length > num_utypes) {
@@ -880,6 +881,7 @@ bool sanity_check_ruleset_data(bool ignore_retired)
                       "There seems to be obsoleted_by loop in update "
                       "chain that starts from %s", utype_rule_name(putype));
         ok = FALSE;
+        obsoleted_by_loop = TRUE;
       }
     }
   } unit_type_iterate_end;
-- 
2.30.2