tools: Fix segmentation fault in ndnsec-sign-req
Change-Id: I586b7b366b8006723f8e892f8a23939653c73ecc
Refs: #2211
diff --git a/tools/ndnsec-sign-req.hpp b/tools/ndnsec-sign-req.hpp
index 1910083..55ad4b1 100644
--- a/tools/ndnsec-sign-req.hpp
+++ b/tools/ndnsec-sign-req.hpp
@@ -80,18 +80,20 @@
KeyChain keyChain;
if (isKeyName)
- {
- selfSignCert = keyChain.selfSign(name);
- }
- else
- {
- Name keyName = keyChain.getDefaultKeyNameForIdentity(name);
- selfSignCert = keyChain.selfSign(keyName);
- }
+ selfSignCert = keyChain.selfSign(name);
+ else {
+ Name keyName = keyChain.getDefaultKeyNameForIdentity(name);
+ selfSignCert = keyChain.selfSign(keyName);
+ }
- io::save(*selfSignCert, std::cout);
-
- return 0;
+ if (static_cast<bool>(selfSignCert)) {
+ io::save(*selfSignCert, std::cout);
+ return 0;
+ }
+ else {
+ std::cerr << "ERROR: Public key does not exist" << std::endl;
+ return 1;
+ }
}
-#endif //NDNSEC_SIGN_REQ_HPP
+#endif // NDNSEC_SIGN_REQ_HPP