You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by gi...@apache.org on 2018/06/21 20:15:10 UTC
[5/5] mesos git commit: Added a length validation for container IDs.
Added a length validation for container IDs.
Review: https://reviews.apache.org/r/67616/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c545bbfa
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c545bbfa
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c545bbfa
Branch: refs/heads/master
Commit: c545bbfa584d303956f3d8b4075680d3d4c9995e
Parents: 00e5f1b
Author: wei xiao <xw...@outlook.com>
Authored: Thu Jun 21 11:58:14 2018 -0700
Committer: Gilbert Song <so...@gmail.com>
Committed: Thu Jun 21 13:14:49 2018 -0700
----------------------------------------------------------------------
src/slave/constants.hpp | 4 ++++
src/slave/validation.cpp | 7 +++++++
src/tests/slave_validation_tests.cpp | 11 +++++++++++
3 files changed, 22 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/c545bbfa/src/slave/constants.hpp
----------------------------------------------------------------------
diff --git a/src/slave/constants.hpp b/src/slave/constants.hpp
index b97daf3..0bd9f37 100644
--- a/src/slave/constants.hpp
+++ b/src/slave/constants.hpp
@@ -85,6 +85,10 @@ constexpr size_t MAX_COMPLETED_FRAMEWORKS = 50;
// to store in memory.
constexpr size_t DEFAULT_MAX_COMPLETED_EXECUTORS_PER_FRAMEWORK = 150;
+// Maximum number of a container id length, according to the
+// max entry length for directory names on AUFS.
+constexpr size_t MAX_CONTAINER_ID_LENGTH = 242;
+
// Maximum number of completed tasks per executor to store in memory.
//
// NOTE: This should be greater than zero because the agent looks
http://git-wip-us.apache.org/repos/asf/mesos/blob/c545bbfa/src/slave/validation.cpp
----------------------------------------------------------------------
diff --git a/src/slave/validation.cpp b/src/slave/validation.cpp
index 09f1fc7..7b4c15a 100644
--- a/src/slave/validation.cpp
+++ b/src/slave/validation.cpp
@@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include "slave/constants.hpp"
#include "slave/validation.hpp"
#include <string>
@@ -52,6 +53,12 @@ Option<Error> validateContainerId(const ContainerID& containerId)
// Check ContainerID specific rules.
//
+ // Valid the container id length
+ if (id.length() > MAX_CONTAINER_ID_LENGTH) {
+ return Error("'ContainerID.value' '" + id + "' exceeds the maximum"
+ " length (" + stringify(MAX_CONTAINER_ID_LENGTH) + ")");
+ }
+
// Periods are disallowed because our string representation of
// ContainerID uses periods: <uuid>.<child>.<grandchild>.
// For example: <uuid>.redis.backup
http://git-wip-us.apache.org/repos/asf/mesos/blob/c545bbfa/src/tests/slave_validation_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_validation_tests.cpp b/src/tests/slave_validation_tests.cpp
index d8bc142..25019cc 100644
--- a/src/tests/slave_validation_tests.cpp
+++ b/src/tests/slave_validation_tests.cpp
@@ -93,6 +93,17 @@ TEST(AgentValidationTest, ContainerID)
error = validation::container::validateContainerId(containerId);
EXPECT_SOME(error);
+ // Valid with invalid container ID (length more than 242).
+ containerId.set_value(
+ "length243-223456789-323456789-423456789-523456789-623456789-"
+ "723456789-823456789-923456789-023456789-123456789-223456789-"
+ "323456789-423456789-523456789-623456789-723456789-823456789-"
+ "923456789-023456789-123456789-223456789-323456789-423456789-"
+ "123");
+ containerId.mutable_parent()->set_value("redis");
+ error = validation::container::validateContainerId(containerId);
+ EXPECT_SOME(error);
+
// Valid with valid parent.
containerId.set_value("backup");
containerId.mutable_parent()->set_value("redis");