From 2f09cf0a2fbfb01347d49658ecb5a27dc8703363 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 23 Feb 2014 17:58:06 +0100 Subject: [PATCH] hdd_menu: improve error resilience in getFmtType() --- src/gui/hdd_menu.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/gui/hdd_menu.cpp b/src/gui/hdd_menu.cpp index d165a5435..ee9320703 100644 --- a/src/gui/hdd_menu.cpp +++ b/src/gui/hdd_menu.cpp @@ -111,14 +111,18 @@ std::string getFmtType(const char* name, int num) FILE* f = my_popen(pid, pcmd.c_str(), "r"); if (f != NULL) { char buff[512]; - fgets(buff, sizeof(buff), f); + if (!fgets(buff, sizeof(buff), f)) + buff[0] = '\0'; fclose(f); ret = buff; std::string search = "TYPE=\""; size_t pos = ret.find(search); + if (pos == std::string::npos) + return ""; ret = ret.substr(pos + search.length()); pos = ret.find("\""); - ret = ret.substr(0, pos); + if (pos != std::string::npos) + ret = ret.substr(0, pos); } return ret; }