From: Sage Weil Date: Mon, 15 Jul 2013 23:12:23 +0000 (-0700) Subject: crush: return EINVAL on invalid name from {insert,update,create_or_move}_item, set_it... X-Git-Tag: v0.67-rc1~59^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=466d0f5fc8ceaa3f0625397aee28c7a7b3b03122;p=ceph.git crush: return EINVAL on invalid name from {insert,update,create_or_move}_item, set_item_name Signed-off-by: Sage Weil Reviewed-by: Dan Mick --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 1a4097c08b96..e96e6123aaba 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -333,6 +333,9 @@ int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string n ldout(cct, 5) << "insert_item item " << item << " weight " << weight << " name " << name << " loc " << loc << dendl; + if (!is_valid_crush_name(name)) + return -EINVAL; + if (name_exists(name)) { if (get_item_id(name) != item) { ldout(cct, 10) << "device name '" << name << "' already exists as id " @@ -473,6 +476,10 @@ int CrushWrapper::create_or_move_item(CephContext *cct, int item, float weight, { int ret = 0; int old_iweight; + + if (!is_valid_crush_name(name)) + return -EINVAL; + if (check_item_loc(cct, item, loc, &old_iweight)) { ldout(cct, 5) << "create_or_move_item " << item << " already at " << loc << dendl; } else { @@ -497,6 +504,9 @@ int CrushWrapper::update_item(CephContext *cct, int item, float weight, string n << " name " << name << " loc " << loc << dendl; int ret = 0; + if (!is_valid_crush_name(name)) + return -EINVAL; + // compare quantized (fixed-point integer) weights! int iweight = (int)(weight * (float)0x10000); int old_iweight; diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index f399e342110d..3d07a281956e 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -200,10 +200,13 @@ public: return p->second.c_str(); return 0; } - void set_item_name(int i, const string& name) { + int set_item_name(int i, const string& name) { + if (!is_valid_crush_name(name)) + return -EINVAL; name_map[i] = name; if (have_rmaps) name_rmap[name] = i; + return 0; } // rule names