Catch leftover boost exceptions in simdaemonctl 12/193912/2
authorIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Tue, 27 Nov 2018 08:57:26 +0000 (09:57 +0100)
committerIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Tue, 27 Nov 2018 11:14:29 +0000 (12:14 +0100)
Change-Id: Ife030baba09cee90f7bfe1e9648c02f55aaf98a3
Signed-off-by: Igor Kotrasinski <i.kotrasinsk@partner.samsung.com>
simulatordaemon/daemonctl/src/SimulatorDaemonCtl.cpp
simulatordaemon/daemonctl/src/handlers/DebugPortHandler.cpp

index 65b8686..f87eca4 100644 (file)
@@ -70,7 +70,7 @@ int communicateWithDaemon(ControlCommand outHeader,
                                                            sizeof(inHeader)));
                boost::asio::read(sock, boost::asio::buffer(inBuf, inBufSize));
        } catch (boost::system::system_error &e) {
-               std::cerr << "Failed to communicate with simulator daemon:"
+               std::cerr << "Failed to communicate with simulator daemon: "
                          << e.what() << std::endl;
                return 1;
        }
@@ -83,11 +83,19 @@ int main(int argc, char *argv[])
                printUsage();
                return 1;
        }
-       if (strcmp(argv[1], "debugport") == 0) {
-               DebugPortHandler handler{};
-               handler.handle(argc - 1, argv + 1);
-       } else {
-               printUsage();
-               return 1;
+       try {
+               if (strcmp(argv[1], "debugport") == 0) {
+                       DebugPortHandler handler{};
+                       handler.handle(argc - 1, argv + 1);
+               } else {
+                       printUsage();
+                       return 1;
+               }
+       } catch (boost::system::system_error &e) {
+               std::cerr << "Internal error: " << e.what() << std::endl;
+       } catch (std::exception &e) {
+               std::cerr << "Internal error: " << e.what() << std::endl;
+       } catch (...) {
+               std::cerr << "Internal error" << std::endl;
        }
 }
index 05d9a6d..1fe279d 100644 (file)
@@ -104,7 +104,16 @@ TEEC_UUID DebugPortHandler::getUuidArgument()
        TEEC_UUID uuid;
        if (!m_opts.count("uuid"))
                throw boost::program_options::required_option("uuid");
-       ret = uuidStringToUuid(m_opts["uuid"].as<std::string>(), uuid);
+
+       try {
+               ret = uuidStringToUuid(m_opts["uuid"].as<std::string>(), uuid);
+       } catch(boost::bad_any_cast &e) {
+               /* This is thrown for missing and wrong-type values. It should
+                * be covered by notify and above m_opts.count check, but let's
+                * catch this pro forma
+                */
+               throw boost::program_options::error("Invalid UUID format");
+       }
        if (ret)
                throw boost::program_options::error(
                        "Invalid UUID format, expected x{8}-x{4}-x{4}-x{4}-x{12}");
@@ -113,9 +122,19 @@ TEEC_UUID DebugPortHandler::getUuidArgument()
 
 int32_t DebugPortHandler::getPortArgument()
 {
+       int32_t port;
        if (!m_opts.count("port"))
                throw boost::program_options::required_option("port");
-       int32_t port = m_opts["port"].as<int32_t>();
+
+       try {
+               port = m_opts["port"].as<int32_t>();
+       } catch(boost::bad_any_cast &e) {
+               /* This is thrown for missing and wrong-type values. It should
+                * be covered by notify and above m_opts.count check, but let's
+                * catch this pro forma
+                */
+               throw boost::program_options::error("Invalid port number");
+       }
        if (port < 0)
                throw boost::program_options::error(
                                "Port number cannot be negative!");