Repository: mesos
Updated Branches:
  refs/heads/master e2f560424 -> bcec2ae36


Added TaskID validation check.

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


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

Branch: refs/heads/master
Commit: bcec2ae36e92e46fc3c295300587c29d2518bbc5
Parents: e2f5604
Author: Dominic Hamon <[email protected]>
Authored: Wed Mar 5 17:12:53 2014 -0800
Committer: Vinod Kone <[email protected]>
Committed: Wed Mar 5 17:13:15 2014 -0800

----------------------------------------------------------------------
 src/master/master.cpp | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/bcec2ae3/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index f7ba9aa..f328bd9 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -1149,6 +1149,34 @@ struct TaskInfoVisitor
   virtual ~TaskInfoVisitor() {}
 };
 
+// Checks that a task id is valid, i.e., contains only valid characters.
+struct TaskIDChecker : TaskInfoVisitor
+{
+  virtual TaskInfoError operator () (
+      const TaskInfo& task,
+      const Resources& resources,
+      const Framework& framework,
+      const Slave& slave)
+  {
+    const std::string& id = task.task_id().value();
+
+    if (id.size() > PATH_MAX) {
+      return "Task ID '" + id + "' is too long";
+    }
+
+    if (std::count_if(id.begin(), id.end(), isInvalid) != 0) {
+      return "Task ID '" + id + "' contains invalid characters.";
+    }
+
+    return None();
+  }
+
+  static bool isInvalid(int c)
+  {
+    return iscntrl(c) || c == '/' || c == '\\';
+  }
+};
+
 
 // Checks that the slave ID used by a task is correct.
 struct SlaveIDChecker : TaskInfoVisitor
@@ -1592,6 +1620,7 @@ void Master::launchTasks(
 
   // Create task visitors.
   list<TaskInfoVisitor*> taskVisitors;
+  taskVisitors.push_back(new TaskIDChecker());
   taskVisitors.push_back(new SlaveIDChecker());
   taskVisitors.push_back(new UniqueTaskIDChecker());
   taskVisitors.push_back(new ResourceUsageChecker());

Reply via email to