From: Marcin Siodelski Date: Fri, 10 Jun 2016 14:22:56 +0000 (+0200) Subject: [master] Merge branch 'trac4498' X-Git-Tag: fdxhook_base~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=14716853a92e08c4cc5be75ae85c5e84d6356a1e;p=thirdparty%2Fkea.git [master] Merge branch 'trac4498' --- 14716853a92e08c4cc5be75ae85c5e84d6356a1e diff --cc src/lib/dhcp/libdhcp++.cc index eeebcf5da7,6f4cdc22d8..116c61dc26 --- a/src/lib/dhcp/libdhcp++.cc +++ b/src/lib/dhcp/libdhcp++.cc @@@ -845,37 -853,18 +855,44 @@@ LibDHCP::initVendorOptsIsc6() initOptionSpace(vendor6_defs_[ENTERPRISE_ID_ISC], ISC_V6_DEFS, ISC_V6_DEFS_SIZE); } +uint32_t +LibDHCP::optionSpaceToVendorId(const std::string& option_space) { + // 8 is a minimal length of "vendor-X" format + if ((option_space.size() < 8) || (option_space.substr(0,7) != "vendor-")) { + return (0); + } + + int64_t check; + try { + // text after "vendor-", supposedly numbers only + std::string x = option_space.substr(7); + + check = boost::lexical_cast(x); + + } catch (const boost::bad_lexical_cast &) { + return (0); + } + + if ((check < 0) || (check > std::numeric_limits::max())) { + return (0); + } + + // value is small enough to fit + return (static_cast(check)); +} + - void initOptionSpace(OptionDefContainer& defs, + void initOptionSpace(OptionDefContainerPtr& defs, const OptionDefParams* params, size_t params_size) { - defs.clear(); + // Container holding vendor options is typically not initialized, as it + // is held in map of null pointers. We need to initialize here in this + // case. + if (!defs) { + defs.reset(new OptionDefContainer()); + + } else { + defs->clear(); + } for (size_t i = 0; i < params_size; ++i) { std::string encapsulates(params[i].encapsulates);