Skip to content
Snippets Groups Projects
Commit 2da6725e authored by Louis Maillard's avatar Louis Maillard
Browse files

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
parent 6999623d
No related branches found
No related tags found
No related merge requests found
...@@ -86,8 +86,8 @@ parse_args(int argc, char** argv) ...@@ -86,8 +86,8 @@ parse_args(int argc, char** argv)
} }
} }
if (params.id.empty() && !params.pkid) { if (params.id.empty() && !params.pkid && !params.help && !params.version) {
std::cerr << "Error: The path to save the generated certificate is not provided.\n Please specify the path using the -i option.\n"; std::cerr << "Error: The path to save the generated certificate is not provided.\n Please specify the path using the -o option.\n";
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
return params; return params;
......
...@@ -236,6 +236,10 @@ main(int argc, char** argv) ...@@ -236,6 +236,10 @@ main(int argc, char** argv)
} }
auto identity = dhtnet::loadIdentity(params.privateKey, params.cert); 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()); fmt::print("Loaded identity: {}\n", identity.second->getId());
fmt::print("dnc 1.0\n"); fmt::print("dnc 1.0\n");
......
...@@ -219,6 +219,10 @@ main(int argc, char** argv) ...@@ -219,6 +219,10 @@ main(int argc, char** argv)
fmt::print("dsh 1.0\n"); fmt::print("dsh 1.0\n");
auto identity = dhtnet::loadIdentity(params.privateKey, params.cert); 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()); fmt::print("Loaded identity: {} \n", identity.second->getId());
std::unique_ptr<dhtnet::Dsh> dhtsh; std::unique_ptr<dhtnet::Dsh> dhtsh;
......
...@@ -217,6 +217,10 @@ main(int argc, char** argv) ...@@ -217,6 +217,10 @@ main(int argc, char** argv)
fmt::print("dvpn 1.0\n"); fmt::print("dvpn 1.0\n");
auto identity = dhtnet::loadIdentity(params.privateKey, params.cert); 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()); fmt::print("Loaded identity: {}\n", identity.second->getId());
std::unique_ptr<dhtnet::Dvpn> dvpn; std::unique_ptr<dhtnet::Dvpn> dvpn;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment