~grimler/Heimdall

14f3521a6b8e3d1936615610bc2db923e469b3b0 — Henrik Grimler 1 year, 10 months ago 0cf817a
FlashAction: fix FileOpen check

Check needs to be right after it is opened, before we try to seek in
it.  Before this fix, heimdall segfaults if file does not exist.

Fixes commit 60ab9bbaffe3 ("FlashAction: Make sure file fit partition
before flashing")
1 files changed, 4 insertions(+), 4 deletions(-)

M heimdall/source/FlashAction.cpp
M heimdall/source/FlashAction.cpp => heimdall/source/FlashAction.cpp +4 -4
@@ 116,16 116,16 @@ static bool openFiles(Arguments& arguments, vector<PartitionFile>& partitionFile
		{
			const StringArgument *stringArgument = static_cast<const StringArgument *>(*it);
			FILE *file = FileOpen(stringArgument->GetValue().c_str(), "rb");
			FileSeek(file, 0, SEEK_END);
			unsigned long fileSize = (unsigned long)FileTell(file);
			FileRewind(file);

			if (!file)
			{
				Interface::PrintError("Failed to open file \"%s\"\n", stringArgument->GetValue().c_str());
				return (false);
			}

			FileSeek(file, 0, SEEK_END);
			unsigned long fileSize = (unsigned long)FileTell(file);
			FileRewind(file);

			partitionFiles.push_back(PartitionFile(argumentName.c_str(), file, fileSize));
		}
	}