Skip to content

Commit 82c3ebe

Browse files
committed
Address a couple of coverity issues
Signed-off-by: Tom Flynn <tom.flynn@gmail.com> Change-Id: Iafc0ebfaaad2fd67e041c7e431f3e7ab1fd76879
1 parent 06d7233 commit 82c3ebe

File tree

6 files changed

+95
-69
lines changed

6 files changed

+95
-69
lines changed

agent-ovs/cmd/opflex_agent.cpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,25 @@ int main(int argc, char** argv) {
223223

224224
// Parse command line options
225225
po::options_description desc("Allowed options");
226-
desc.add_options()
227-
("help,h", "Print this help message")
228-
("version,v", "print version information and git hash")
229-
("config,c",
230-
po::value<std::vector<string> >(),
231-
"Read configuration from the specified files or directories")
232-
("watch,w", "Watch configuration directories for changes")
233-
("log", po::value<string>()->default_value(""),
234-
"Log to the specified file (default standard out)")
235-
("level", po::value<string>()->default_value("info"),
236-
"Use the specified log level (default info). "
237-
"Overridden by log level in configuration file")
238-
("syslog", "Log to syslog instead of file or standard out")
239-
("daemon", "Run the agent as a daemon")
240-
;
226+
try {
227+
desc.add_options()
228+
("help,h", "Print this help message")
229+
("version,v", "print version information and git hash")
230+
("config,c",
231+
po::value<std::vector<string> >(),
232+
"Read configuration from the specified files or directories")
233+
("watch,w", "Watch configuration directories for changes")
234+
("log", po::value<string>()->default_value(""),
235+
"Log to the specified file (default standard out)")
236+
("level", po::value<string>()->default_value("info"),
237+
"Use the specified log level (default info). "
238+
"Overridden by log level in configuration file")
239+
("syslog", "Log to syslog instead of file or standard out")
240+
("daemon", "Run the agent as a daemon");
241+
} catch (const boost::bad_lexical_cast& e) {
242+
std::cerr << e.what() << std::endl;
243+
return 1;
244+
}
241245

242246
bool daemon = false;
243247
bool watch = false;
@@ -274,10 +278,10 @@ int main(int argc, char** argv) {
274278
}
275279
} catch (const po::unknown_option& e) {
276280
std::cerr << e.what() << std::endl;
277-
return 1;
281+
return 2;
278282
} catch (const std::bad_cast& e) {
279283
std::cerr << e.what() << std::endl;
280-
return 2;
284+
return 3;
281285
}
282286

283287
if (daemon)
@@ -288,7 +292,12 @@ int main(int argc, char** argv) {
288292
// Initialize agent and configuration
289293
std::vector<string> configFiles;
290294
if (vm.count("config"))
291-
configFiles = vm["config"].as<std::vector<string> >();
295+
try {
296+
configFiles = vm["config"].as<std::vector<string> >();
297+
} catch (const boost::bad_any_cast& e) {
298+
std::cerr << e.what() << std::endl;
299+
return 4;
300+
}
292301
else
293302
configFiles.push_back(DEFAULT_CONF);
294303

agent-ovs/cmd/test/framework_stress.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,19 @@ int main(int argc, char** argv) {
6767
signal(SIGPIPE, SIG_IGN);
6868
// Parse command line options
6969
po::options_description desc("Allowed options");
70-
desc.add_options()
71-
("help,h", "Print this help message")
72-
("log", po::value<string>()->default_value(""),
73-
"Log to the specified file (default standard out)")
74-
("level", po::value<string>()->default_value("info"),
75-
"Use the specified log level (default info)")
76-
("policy,p", po::value<string>()->default_value(""),
77-
"Read the specified policy file to seed the MODB")
78-
;
79-
70+
try {
71+
desc.add_options()
72+
("help,h", "Print this help message")
73+
("log", po::value<string>()->default_value(""),
74+
"Log to the specified file (default standard out)")
75+
("level", po::value<string>()->default_value("info"),
76+
"Use the specified log level (default info)")
77+
("policy,p", po::value<string>()->default_value(""),
78+
"Read the specified policy file to seed the MODB");
79+
} catch (const boost::bad_lexical_cast& e) {
80+
std::cerr << e.what() << std::endl;
81+
return 1;
82+
}
8083
std::string log_file;
8184
std::string level_str;
8285
std::string policy_file;
@@ -98,10 +101,10 @@ int main(int argc, char** argv) {
98101

99102
} catch (const po::unknown_option& e) {
100103
std::cerr << e.what() << std::endl;
101-
return 1;
104+
return 2;
102105
} catch (const std::bad_cast& e) {
103106
std::cerr << e.what() << std::endl;
104-
return 2;
107+
return 3;
105108
}
106109

107110
initLogging(level_str, false /*syslog*/, log_file, "framework-stress");
@@ -202,9 +205,9 @@ int main(int argc, char** argv) {
202205
server.stop();
203206
} catch (const std::exception& e) {
204207
LOG(ERROR) << "Fatal error: " << e.what();
205-
return 2;
208+
return 4;
206209
} catch (...) {
207210
LOG(ERROR) << "Unknown fatal error";
208-
return 3;
211+
return 5;
209212
}
210213
}

agent-ovs/cmd/test/opflex_server.cpp

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,35 +60,39 @@ int main(int argc, char** argv) {
6060
signal(SIGPIPE, SIG_IGN);
6161
// Parse command line options
6262
po::options_description desc("Allowed options");
63-
desc.add_options()
64-
("help,h", "Print this help message")
65-
("log", po::value<string>()->default_value(""),
66-
"Log to the specified file (default standard out)")
67-
("level", po::value<string>()->default_value("info"),
68-
"Use the specified log level (default info)")
69-
("sample", po::value<string>()->default_value(""),
70-
"Output a sample policy to the given file then exit")
71-
("daemon", "Run the opflex server as a daemon")
72-
("policy,p", po::value<string>()->default_value(""),
73-
"Read the specified policy file to seed the MODB")
74-
("ssl_castore", po::value<string>()->default_value("/etc/ssl/certs/"),
75-
"Use the specified path or certificate file as the SSL CA store")
76-
("ssl_key", po::value<string>()->default_value(""),
77-
"Enable SSL and use the private key specified")
78-
("ssl_pass", po::value<string>()->default_value(""),
79-
"Use the specified password for the private key")
80-
("peer", po::value<std::vector<string> >(),
81-
"A peer specified as hostname:port to return in identity response")
82-
("transport_mode_proxies", po::value<std::vector<string> >(),
83-
"3 transport_mode_proxy IPv4 addresses specified to return "
84-
"in identity response")
85-
("grpc_address", po::value<string>()->default_value("localhost:19999"),
86-
"GRPC server address for policy updates")
87-
("grpc_conf", po::value<string>()->default_value(""),
88-
"GRPC config file, should be in same directory as policy file")
89-
("prr_interval_secs", po::value<int>()->default_value(60),
90-
"How often to wakeup prr thread to check for prr timeouts")
91-
;
63+
try {
64+
desc.add_options()
65+
("help,h", "Print this help message")
66+
("log", po::value<string>()->default_value(""),
67+
"Log to the specified file (default standard out)")
68+
("level", po::value<string>()->default_value("info"),
69+
"Use the specified log level (default info)")
70+
("sample", po::value<string>()->default_value(""),
71+
"Output a sample policy to the given file then exit")
72+
("daemon", "Run the opflex server as a daemon")
73+
("policy,p", po::value<string>()->default_value(""),
74+
"Read the specified policy file to seed the MODB")
75+
("ssl_castore", po::value<string>()->default_value("/etc/ssl/certs/"),
76+
"Use the specified path or certificate file as the SSL CA store")
77+
("ssl_key", po::value<string>()->default_value(""),
78+
"Enable SSL and use the private key specified")
79+
("ssl_pass", po::value<string>()->default_value(""),
80+
"Use the specified password for the private key")
81+
("peer", po::value<std::vector<string> >(),
82+
"A peer specified as hostname:port to return in identity response")
83+
("transport_mode_proxies", po::value<std::vector<string> >(),
84+
"3 transport_mode_proxy IPv4 addresses specified to return "
85+
"in identity response")
86+
("grpc_address", po::value<string>()->default_value("localhost:19999"),
87+
"GRPC server address for policy updates")
88+
("grpc_conf", po::value<string>()->default_value(""),
89+
"GRPC config file, should be in same directory as policy file")
90+
("prr_interval_secs", po::value<int>()->default_value(60),
91+
"How often to wakeup prr thread to check for prr timeouts");
92+
} catch (const boost::bad_lexical_cast& e) {
93+
std::cerr << e.what() << std::endl;
94+
return 1;
95+
}
9296

9397
bool daemon = false;
9498
std::string log_file;
@@ -166,10 +170,10 @@ int main(int argc, char** argv) {
166170
prr_interval_secs = vm["prr_interval_secs"].as<int>();
167171
} catch (const po::unknown_option& e) {
168172
std::cerr << e.what() << std::endl;
169-
return 1;
173+
return 2;
170174
} catch (const std::bad_cast& e) {
171175
std::cerr << e.what() << std::endl;
172-
return 2;
176+
return 3;
173177
}
174178

175179
if (daemon)
@@ -271,9 +275,9 @@ int main(int argc, char** argv) {
271275
server.stop();
272276
} catch (const std::exception& e) {
273277
LOG(ERROR) << "Fatal error: " << e.what();
274-
return 2;
278+
return 4;
275279
} catch (...) {
276280
LOG(ERROR) << "Unknown fatal error";
277-
return 3;
281+
return 5;
278282
}
279283
}

agent-ovs/cmd/test/policy_repo_stress.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ int main(int argc, char** argv) {
347347

348348
if (agents.size() == 0) {
349349
LOG(opflexagent::ERROR) << "No agents created";
350-
return 2;
350+
return 3;
351351
}
352352

353353
opflexagent::initLogging(level_str, false, "");
@@ -403,7 +403,12 @@ int main(int argc, char** argv) {
403403

404404
stats.stop();
405405
for (TestAgent& a : agents) {
406-
a.agent->stop();
406+
try {
407+
a.agent->stop();
408+
} catch (const std::runtime_error& e) {
409+
std::cerr << e.what() << std::endl;
410+
return 4;
411+
}
407412
}
408413

409414
return 0;

agent-ovs/lib/Agent.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Agent::Agent(OFFramework& framework_, const LogParams& _logParams)
6666
extraConfigManager(framework),
6767
notifServer(agent_io),rendererFwdMode(opflex_elem_t::INVALID_MODE),
6868
started(false), presetFwdMode(opflex_elem_t::INVALID_MODE),
69+
contractInterval(0), securityGroupInterval(0), interfaceInterval(0),
6970
spanManager(framework, agent_io),
7071
netflowManager(framework,agent_io),
7172
prometheusEnabled(true),
@@ -732,7 +733,7 @@ void Agent::stop() {
732733
if (io_service_thread) {
733734
io_service_thread->join();
734735
io_service_thread.reset();
735-
LOG(DEBUG) << "IO service thread stopped";
736+
LOG(DEBUG) << "IO service thread stopped";
736737
}
737738

738739
framework.stop();

agent-ovs/lib/include/opflexagent/Endpoint.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ class Endpoint {
3939
*/
4040
Endpoint() : promiscuousMode(false), discoveryProxyMode(false), natMode(false),
4141
external(false), aapModeAA(false), disableAdv(false),
42-
accessAllowUntagged(false), extEncap(0) {}
42+
accessAllowUntagged(false), extEncap(0) {
43+
#ifdef HAVE_PROMETHEUS_SUPPORT
44+
attr_hash = 0;
45+
#endif
46+
}
4347

4448
/**
4549
* Construct a new Endpoint with the given uuid. Note that

0 commit comments

Comments
 (0)