You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bb...@apache.org on 2017/12/08 16:02:20 UTC

[2/5] mesos git commit: Fixed 'getResourceProviderId' for operations without resources.

Fixed 'getResourceProviderId' for operations without resources.

The code in 'getResourceProviderId' was written in a way assuming that
any operation containing a list resources always contained at least a
single resource. This is both incorrect since such operations pass
validation, and also neglects to check a crucial precondition since
accessing a non-existent element in this context would lead to a check
failure in protobuf and a subsequent abort.

This code updates 'getResourceProviderId' to check the precondition of
operations holding at least one element.

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


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

Branch: refs/heads/master
Commit: 396b927c19bc61a986c8c0fb4068af159fd1e87e
Parents: f8771c7
Author: Benjamin Bannier <bb...@apache.org>
Authored: Thu Dec 7 17:14:46 2017 +0100
Committer: Benjamin Bannier <bb...@apache.org>
Committed: Fri Dec 8 13:59:40 2017 +0100

----------------------------------------------------------------------
 src/common/resources_utils.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/396b927c/src/common/resources_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources_utils.cpp b/src/common/resources_utils.cpp
index 8e3d304..1676b72 100644
--- a/src/common/resources_utils.cpp
+++ b/src/common/resources_utils.cpp
@@ -234,15 +234,27 @@ Result<ResourceProviderID> getResourceProviderId(
     case Offer::Operation::LAUNCH_GROUP:
       return Error("Unexpected LAUNCH_GROUP operation");
     case Offer::Operation::RESERVE:
+      if (operation.reserve().resources().empty()) {
+        return Error("Operation contains no resources");
+      }
       resource = operation.reserve().resources(0);
       break;
     case Offer::Operation::UNRESERVE:
+      if (operation.unreserve().resources().empty()) {
+        return Error("Operation contains no resources");
+      }
       resource = operation.unreserve().resources(0);
       break;
     case Offer::Operation::CREATE:
+      if (operation.create().volumes().empty()) {
+        return Error("Operation contains no resources");
+      }
       resource = operation.create().volumes(0);
       break;
     case Offer::Operation::DESTROY:
+      if (operation.destroy().volumes().empty()) {
+        return Error("Operation contains no resources");
+      }
       resource = operation.destroy().volumes(0);
       break;
     case Offer::Operation::CREATE_VOLUME: