]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Added code for Role input validation.
authorPritha Srivastava <prsrivas@redhat.com>
Mon, 20 Feb 2017 07:20:34 +0000 (12:50 +0530)
committerPritha Srivastava <prsrivas@redhat.com>
Tue, 7 Mar 2017 04:26:45 +0000 (09:56 +0530)
Signed-off-by: Pritha Srivastava <prsrivas@redhat.com>
src/rgw/rgw_role.cc
src/rgw/rgw_role.h

index ab08c57807d4b685850446988b8a94d6a40cc476..b6cb7e92f9e28199dc3903a5b8768debe4279b73 100644 (file)
@@ -1,5 +1,6 @@
 #include <errno.h>
 #include <ctime>
+#include <regex>
 
 #include "common/errno.h"
 #include "common/Formatter.h"
@@ -58,6 +59,10 @@ int RGWRole::create(bool exclusive)
 {
   int ret;
 
+  if (! validate_input()) {
+    return -EINVAL;
+  }
+
   /* check to see the name is not used */
   ret = read_id(name, tenant, id);
   if (exclusive && ret == 0) {
@@ -350,6 +355,31 @@ int RGWRole::read_name()
   return 0;
 }
 
+bool RGWRole::validate_input()
+{
+  if (name.length() > MAX_ROLE_NAME_LEN) {
+    ldout(cct, 0) << "ERROR: Invalid name length " << dendl;
+    return false;
+  }
+
+  if (path.length() > MAX_PATH_NAME_LEN) {
+    ldout(cct, 0) << "ERROR: Invalid path length " << dendl;
+    return false;
+  }
+
+  std::regex regex_name("[A-Za-z0-9:=,.@-]+");
+  if (! std::regex_match(name, regex_name)) {
+    ldout(cct, 0) << "ERROR: Invalid chars in name " << dendl;
+    return false;
+  }
+
+  std::regex regex_path("(\/[!-~]+\/)|(\/)");
+  if (! std::regex_match(path,regex_path)) {
+    ldout(cct, 0) << "ERROR: Invalid chars in path " << dendl;
+    return false;
+  }
+}
+
 void RGWRole::update_trust_policy(string& trust_policy)
 {
   this->trust_policy = trust_policy;
index 138381e74f04fabe100dadbe8c529e8733d791b9..03cd67c692621983ed5b5d01216f025ab4b1872f 100644 (file)
@@ -7,6 +7,8 @@ class RGWRole
   static const string role_oid_prefix;
   static const string role_path_oid_prefix;
   static const string role_arn_prefix;
+  static constexpr int MAX_ROLE_NAME_LEN = 64;
+  static constexpr int MAX_PATH_NAME_LEN = 512;
 
   CephContext *cct;
   RGWRados *store;
@@ -26,6 +28,7 @@ class RGWRole
   int read_name();
   int read_info();
   void set_id(const string& id) { this->id = id; }
+  bool validate_input();
 
 public:
   RGWRole(CephContext *cct,