From 954840b7949d3d95903136f16812392da206a14d Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Wed, 21 Oct 2026 19:21:48 +0300
Subject: [PATCH 87/88] Check that savegame to load is a regular file

See RM #2403

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 server/fcdb.c      |  7 ++++++-
 server/stdinhand.c | 11 ++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/server/fcdb.c b/server/fcdb.c
index 64a1822d39..6b5b5373ce 100644
--- a/server/fcdb.c
+++ b/server/fcdb.c
@@ -126,12 +126,17 @@ static bool fcdb_load_config(const char *filename)
 
   fc_assert_ret_val(filename != nullptr, FALSE);
 
-  /* does file exist? */
+  /* Does file exist? */
   if (fc_stat(filename, &buf) != 0) {
     log_error(_("Cannot load fcdb config file '%s':\n%s"), filename,
               fc_strerror(fc_get_errno()));
     return FALSE;
   }
+  if (!S_ISREG(buf.st_mode)) {
+    log_error(_("Cannot load fcdb config file '%s':\n%s"), filename,
+              "not a file");
+    return FALSE;
+  }
 
   if (!(secfile = secfile_load(filename, FALSE))) {
     log_error(_("Cannot load fcdb config file '%s':\n%s"), filename,
diff --git a/server/stdinhand.c b/server/stdinhand.c
index 9979209a39..916a5d82b6 100644
--- a/server/stdinhand.c
+++ b/server/stdinhand.c
@@ -3852,11 +3852,20 @@ bool load_command(struct connection *caller, const char *filename, bool check)
 
   {
     struct stat buf;
+    bool failure = FALSE;
 
-    /* does file exist? */
+    /* Does file exist? */
     if (fc_stat(arg, &buf) != 0) {
       log_error("Error loading savefile '%s': %s", arg,
                 fc_strerror(fc_get_errno()));
+      failure = TRUE;
+    } else if (!S_ISREG(buf.st_mode)) {
+      log_error("Error loading savefile '%s': %s", arg,
+                "not a file");
+      failure = TRUE;
+    }
+
+    if (failure) {
       cmd_reply(CMD_LOAD, caller, C_FAIL, _("Could not load savefile: %s"),
                 arg);
       dlsend_packet_game_load(game.est_connections, FALSE, arg);
-- 
2.53.0

