From b958a2d30c69434e1a2b8be927100e16c6eb4554 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 19 May 2014 16:13:42 +0000 Subject: [PATCH] Redis schema updates and fix for GitHub issue #72 --- netconf-service/redis-schema.md | 2 ++ node/SoftwareUpdater.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/netconf-service/redis-schema.md b/netconf-service/redis-schema.md index 9dc4dc5b7..48c530f42 100644 --- a/netconf-service/redis-schema.md +++ b/netconf-service/redis-schema.md @@ -38,6 +38,7 @@ Note: users are referred to elsewhere in the database by their compound key \:member:\:~ diff --git a/node/SoftwareUpdater.cpp b/node/SoftwareUpdater.cpp index 7cb0d4792..02da55db2 100644 --- a/node/SoftwareUpdater.cpp +++ b/node/SoftwareUpdater.cpp @@ -201,7 +201,17 @@ void SoftwareUpdater::_cbHandleGetLatestVersionBinary(void *arg,int code,const s return; } std::string updatesDir(_r->homePath + ZT_PATH_SEPARATOR_S + "updates.d"); - std::string updatePath(updatesDir + ZT_PATH_SEPARATOR_S + url.substr(lastSlash + 1)); + std::string updateFilename(url.substr(lastSlash + 1)); + for(std::string::iterator c(updateFilename.begin());c!=updateFilename.end();++c) { + // Only allow a list of whitelisted characters to make up the filename to prevent any + // path shenanigans, esp on Windows where / is not the path separator. + if (!strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.0123456789",*c)) { + LOG("software update failed: invalid URL: filename contains invalid characters"); + upd->_status = UPDATE_STATUS_IDLE; + return; + } + } + std::string updatePath(updatesDir + ZT_PATH_SEPARATOR_S + updateFilename); #ifdef __WINDOWS__ CreateDirectoryA(updatesDir.c_str(),NULL); #else