Skip to content

Commit

Permalink
FileParser: Fixed infinite INCLUDE recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
dorkster committed Jan 30, 2024
1 parent 3cc70cc commit 251389d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Engine fixes:
* Fix power.target_neighbor not using the starting_pos as the origin point.
* Fixed crash in Power tooltips when base_damage was not defined.
* Fix incorrect power level being shown in the action bar tooltips for upgraded powers.
* Fixed infinite INCLUDE recursion in FileParser.
* Android: Fix 'Flare' directory not being automatically created.
* Android: Added a dialog to direct the player to the wiki page for installing if no game data is found.

Expand Down
23 changes: 15 additions & 8 deletions src/FileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ FileParser::FileParser()
: current_index(0)
, is_mod_file(false)
, error_mode(ERROR_NORMAL)
, requested_filename("")
, line("")
, line_number(0)
, include_fp(NULL)
Expand All @@ -40,6 +41,7 @@ FileParser::FileParser()
bool FileParser::open(const std::string& _filename, bool _is_mod_file, int _error_mode) {
is_mod_file = _is_mod_file;
error_mode = _error_mode;
requested_filename = _filename;

filenames.clear();
if (is_mod_file) {
Expand Down Expand Up @@ -172,15 +174,20 @@ bool FileParser::next() {
if (directive == "INCLUDE") {
std::string tmp = line.substr(first_space+1);

include_fp = new FileParser();
if (!include_fp || !include_fp->open(tmp, is_mod_file, error_mode)) {
delete include_fp;
include_fp = NULL;
if (requested_filename != tmp) {
include_fp = new FileParser();
if (!include_fp || !include_fp->open(tmp, is_mod_file, error_mode)) {
delete include_fp;
include_fp = NULL;
}

if (include_fp) {
// INCLUDE file will inherit the current section
include_fp->section = section;
}
}

if (include_fp) {
// INCLUDE file will inherit the current section
include_fp->section = section;
else {
error("FileParser: Recursive INCLUDE detected. Did you mean to use APPEND?");
}

continue;
Expand Down
1 change: 1 addition & 0 deletions src/FileParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class FileParser {
unsigned current_index;
bool is_mod_file;
int error_mode;
std::string requested_filename;

std::ifstream infile;
std::string line;
Expand Down
2 changes: 1 addition & 1 deletion src/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ FLARE. If not, see http://www.gnu.org/licenses/

#include <SDL.h>

Version VersionInfo::ENGINE(1, 14, 33);
Version VersionInfo::ENGINE(1, 14, 34);
Version VersionInfo::MIN(0, 0, 0);
Version VersionInfo::MAX(USHRT_MAX, USHRT_MAX, USHRT_MAX);

Expand Down

0 comments on commit 251389d

Please sign in to comment.