From 0ff19f071f44a0474b9f5dd60d9106488a3046aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= Date: Mon, 13 May 2019 21:34:58 +0200 Subject: [PATCH] Fix #9240: crash when passing directory instead of save file --- distribution/changelog.txt | 1 + src/openrct2/core/FileStream.hpp | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 69033cec49..151425bcb3 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -38,6 +38,7 @@ - Fix: [#9000] Show correct error message if not enough money available. - Fix: [#9152] Spectators can modify ride colours. - Fix: [#9202] Artefacts show when changing ride type as client or using in-game console. +- Fix: [#9240] Crash when passing directory instead of save file. - Fix: Guests eating popcorn are drawn as if they're eating pizza. - Fix: The arbitrary ride type and vehicle dropdown lists are ordered case-sensitively. - Improved: [#6116] Expose colour scheme for track elements in the tile inspector. diff --git a/src/openrct2/core/FileStream.hpp b/src/openrct2/core/FileStream.hpp index ae33e05d7c..c2bc81c918 100644 --- a/src/openrct2/core/FileStream.hpp +++ b/src/openrct2/core/FileStream.hpp @@ -15,6 +15,9 @@ #include "String.hpp" #include +#ifndef _WIN32 +# include +#endif enum { @@ -73,7 +76,12 @@ public: free(pathW); free(modeW); #else - _file = fopen(path, mode); + struct stat fileStat; + // Only allow regular files to be opened as its possible to open directories. + if (stat(path, &fileStat) == 0 && S_ISREG(fileStat.st_mode)) + { + _file = fopen(path, mode); + } #endif if (_file == nullptr) {