diff options
| author | Ed Tanous <ed.tanous@intel.com> | 2018-11-14 14:07:48 -0800 |
|---|---|---|
| committer | Ed Tanous <ed.tanous@intel.com> | 2019-01-04 06:25:55 +0000 |
| commit | ad18f070ef8738edd858272fbd71d83ac996333c (patch) | |
| tree | 09f0a26422036890cf0c21d8f8a3703f6b16bb70 /include | |
| parent | 93ef580215ec3cd60e8c505a415d25d3555f554f (diff) | |
| download | bmcweb-ad18f070ef8738edd858272fbd71d83ac996333c.tar.gz bmcweb-ad18f070ef8738edd858272fbd71d83ac996333c.zip | |
bmcweb: Fix issues with /dump endpoint
Technically, if multiple dump files existed, we could get a double end()
called loading each file. Avoid that by returning.
Tested By:
Downloading a file from dump, using the /dump url. File downloads
correctly.
Change-Id: Icd71a2fbbe365557daa1a7e24c5563f3749a748d
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
Diffstat (limited to 'include')
| -rw-r--r-- | include/openbmc_dbus_rest.hpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp index fe85d65..4c68fac 100644 --- a/include/openbmc_dbus_rest.hpp +++ b/include/openbmc_dbus_rest.hpp @@ -1509,30 +1509,32 @@ template <typename... Middlewares> void requestRoutes(Crow<Middlewares...> &app) BMCWEB_ROUTE(app, "/download/dump/<str>/") .methods("GET"_method)([](const crow::Request &req, crow::Response &res, const std::string &dumpId) { - std::regex validFilename("^[\\w\\- ]+(\\.?[\\w\\- ]+)$"); + std::regex validFilename("^[\\w\\- ]+(\\.?[\\w\\- ]*)$"); if (!std::regex_match(dumpId, validFilename)) { - res.result(boost::beast::http::status::not_found); + res.result(boost::beast::http::status::bad_request); res.end(); return; } std::experimental::filesystem::path loc( "/var/lib/phosphor-debug-collector/dumps"); - loc += dumpId; + loc /= dumpId; if (!std::experimental::filesystem::exists(loc) || !std::experimental::filesystem::is_directory(loc)) { + BMCWEB_LOG_ERROR << loc << "Not found"; res.result(boost::beast::http::status::not_found); res.end(); return; } std::experimental::filesystem::directory_iterator files(loc); + for (auto &file : files) { std::ifstream readFile(file.path()); - if (readFile.good()) + if (!readFile.good()) { continue; } @@ -1540,6 +1542,7 @@ template <typename... Middlewares> void requestRoutes(Crow<Middlewares...> &app) res.body() = {std::istreambuf_iterator<char>(readFile), std::istreambuf_iterator<char>()}; res.end(); + return; } res.result(boost::beast::http::status::not_found); res.end(); |

