You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ya...@apache.org on 2017/01/18 01:47:06 UTC

[3/4] mesos git commit: Added sanity checks on IDs and roles before creating directories.

Added sanity checks on IDs and roles before creating directories.

Review: https://reviews.apache.org/r/55447


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/458fa754
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/458fa754
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/458fa754

Branch: refs/heads/master
Commit: 458fa754e7b83feb19dd2426953b828793b4a175
Parents: 2d21d96
Author: Jiang Yan Xu <xu...@apple.com>
Authored: Mon Jan 9 13:54:51 2017 -0800
Committer: Jiang Yan Xu <xu...@apple.com>
Committed: Tue Jan 17 17:38:38 2017 -0800

----------------------------------------------------------------------
 src/slave/paths.cpp | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/458fa754/src/slave/paths.cpp
----------------------------------------------------------------------
diff --git a/src/slave/paths.cpp b/src/slave/paths.cpp
index 8792cee..38ad199 100644
--- a/src/slave/paths.cpp
+++ b/src/slave/paths.cpp
@@ -19,6 +19,7 @@
 #include <vector>
 
 #include <mesos/mesos.hpp>
+#include <mesos/roles.hpp>
 #include <mesos/type_utils.hpp>
 
 #include <stout/check.hpp>
@@ -30,9 +31,12 @@
 #include <stout/try.hpp>
 #include <stout/unreachable.hpp>
 
+#include "common/validation.hpp"
+
 #include "messages/messages.hpp"
 
 #include "slave/paths.hpp"
+#include "slave/validation.hpp"
 
 using std::list;
 using std::string;
@@ -456,6 +460,11 @@ string getPersistentVolumePath(
   CHECK(volume.has_disk());
   CHECK(volume.disk().has_persistence());
 
+  // Additionally check that the role and the persistent ID are valid
+  // before using them to construct a directory path.
+  CHECK_NONE(roles::validate(volume.role()));
+  CHECK_NONE(common::validation::validateID(volume.disk().persistence().id()));
+
   // If no `source` is provided in `DiskInfo` volumes are mapped into
   // the `rootDir`.
   if (!volume.disk().has_source()) {
@@ -494,6 +503,14 @@ string createExecutorDirectory(
     const ContainerID& containerId,
     const Option<string>& user)
 {
+  // These IDs should be valid as they are either assigned by the
+  // master/agent or validated by the master but we do a sanity check
+  // here before using them to create a directory.
+  CHECK_NONE(common::validation::validateSlaveID(slaveId));
+  CHECK_NONE(common::validation::validateFrameworkID(frameworkId));
+  CHECK_NONE(common::validation::validateExecutorID(executorId));
+  CHECK_NONE(slave::validation::container::validateContainerId(containerId));
+
   const string directory =
     getExecutorRunPath(rootDir, slaveId, frameworkId, executorId, containerId);
 
@@ -552,6 +569,10 @@ string createSlaveDirectory(
     const string& rootDir,
     const SlaveID& slaveId)
 {
+  // `slaveId` should be valid because it's assigned by the master but
+  // we do a sanity check here before using it to create a directory.
+  CHECK_NONE(common::validation::validateSlaveID(slaveId));
+
   const string directory = getSlavePath(rootDir, slaveId);
 
   Try<Nothing> mkdir = os::mkdir(directory);