Skip to content

Commit

Permalink
Merge pull request #1969 from Sonicadvance1/fexrootfsfetcher_fix_crash
Browse files Browse the repository at this point in the history
FEXRootFSFetcher: Fix crash if curl fails to download rootfs definition file
  • Loading branch information
Sonicadvance1 authored Sep 2, 2022
2 parents 7f9edbf + 760b9c8 commit 31fefaa
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Source/Tools/FEXRootFSFetcher/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <fstream>
#include <iostream>
#include <unistd.h>
#include <optional>
#include <sstream>
#include <sys/mman.h>
#include <sys/syscall.h>
Expand Down Expand Up @@ -514,10 +515,14 @@ namespace WebFileFetcher {
return &*alloc->json_objects->emplace(alloc->json_objects->end());
}

std::vector<FileTargets> GetRootFSLinks() {
std::optional<std::vector<FileTargets>> GetRootFSLinks() {
// Decode the filetargets
std::string Data = DownloadToString(DownloadURL);

if (Data.empty()) {
return std::nullopt;
}

JsonAllocator Pool {
.PoolObject = {
.init = PoolInit,
Expand Down Expand Up @@ -1121,7 +1126,14 @@ int main(int argc, char **argv, char **const envp) {
}

if (AskForConfirmation(Question)) {
auto Targets = WebFileFetcher::GetRootFSLinks();
auto TargetReturn = WebFileFetcher::GetRootFSLinks();
if (!TargetReturn.has_value()) {
ExecWithInfo("Couldn't download rootfs list from the server. Try again in a minute or report on the fex-emu issue tracker.");
return -1;
}

auto Targets = TargetReturn.value();

if (Targets.empty()) {
ExecWithInfo("Couldn't parse rootfs definition URL.");
return -1;
Expand Down

0 comments on commit 31fefaa

Please sign in to comment.