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 60ab9bbaff ("FlashAction: Make sure file fit partition
before flashing")
This commit is contained in:
Henrik Grimler 2022-07-12 17:15:39 +02:00
parent 0cf817a591
commit 14f3521a6b
No known key found for this signature in database
GPG Key ID: B0076E490B71616B
1 changed files with 4 additions and 4 deletions

View File

@ -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));
}
}