tools: fix segfault when invalid identity given
Giving no or invalid identity to dnc, dsh or dvpn was giving a segfault.
They now print an error message and exit with a non-zero status
correctly. dhtnet-crtmgr was also suffering segfault when no -o option,
even for --help or --version options. This is now fixed.
Change-Id: I7871db9ab73205c9ad024260d7687cc20ae1a983
diff --git a/tools/dsh/main.cpp b/tools/dsh/main.cpp
index 3b2592d..12dae12 100644
--- a/tools/dsh/main.cpp
+++ b/tools/dsh/main.cpp
@@ -219,6 +219,10 @@
fmt::print("dsh 1.0\n");
auto identity = dhtnet::loadIdentity(params.privateKey, params.cert);
+ if (!identity.first || !identity.second) {
+ fmt::print(stderr, "Hint: To generate new identity files, run: dhtnet-crtmgr --interactive\n");
+ return EXIT_FAILURE;
+ }
fmt::print("Loaded identity: {} \n", identity.second->getId());
std::unique_ptr<dhtnet::Dsh> dhtsh;