From: Danny Al-Gaaf Date: Thu, 11 Jun 2015 18:01:26 +0000 (+0200) Subject: mon/MonMap.h: fix potential segfault, add assert() X-Git-Tag: v9.1.0~446^2~28 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a0dc63d795dcb94a46eb08c24fcd34716614fefc;p=ceph.git mon/MonMap.h: fix potential segfault, add assert() Fix for: CID 1297860 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS) 1. Condition this->mon_addr.count(n), taking true branch 2. negative_return_fn: Function this->get_rank(n) returns a negative number. [show details] 3. var_assign: Assigning: signed variable m = get_rank. 4. negative_returns: m is passed to a parameter that cannot be negative. Signed-off-by: Danny Al-Gaaf --- diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index ae81b073ca4..390d88a7ca2 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -159,6 +159,7 @@ class MonMap { entity_inst_t get_inst(const string& n) { assert(mon_addr.count(n)); int m = get_rank(n); + assert(m >= 0); // vector can't take negative indicies entity_inst_t i; i.addr = rank_addr[m]; i.name = entity_name_t::MON(m);