Fix Klocwork Issue - Dereferencing iterators

In the current implementation, the iterator "paths" is being checked
for end(), but is being dereferenced in the code even if the iterator
is being equal to end().
This commit fixes this issue by returning if iterator equals end()
and performing the remaining tasks otherwise.

Tested:
 - websocket_test.py Passed
 - When there was no "paths" provided from the script, the connection
   was closed with "Unable to find paths in json data" message.

Signed-off-by: P Dheeraj Srujan Kumar <p.dheeraj.srujan.kumar@intel.com>
Change-Id: I8651768c057971367dc35b8fd7ae168ab40e3453
diff --git a/include/dbus_monitor.hpp b/include/dbus_monitor.hpp
index 7fd346e..a6c86c6 100644
--- a/include/dbus_monitor.hpp
+++ b/include/dbus_monitor.hpp
@@ -142,20 +142,23 @@
             }
 
             nlohmann::json::iterator paths = j.find("paths");
-            if (paths != j.end())
+            if (paths == j.end())
             {
-                size_t interfaceCount = thisSession.interfaces.size();
-                if (interfaceCount == 0)
-                {
-                    interfaceCount = 1;
-                }
-                // Reserve our matches upfront.  For each path there is 1 for
-                // interfacesAdded, and InterfaceCount number for
-                // PropertiesChanged
-                thisSession.matches.reserve(thisSession.matches.size() +
-                                            paths->size() *
-                                                (1U + interfaceCount));
+                BMCWEB_LOG_ERROR << "Unable to find paths in json data";
+                conn.close("Unable to find paths in json data");
+                return;
             }
+
+            size_t interfaceCount = thisSession.interfaces.size();
+            if (interfaceCount == 0)
+            {
+                interfaceCount = 1;
+            }
+            // Reserve our matches upfront.  For each path there is 1 for
+            // interfacesAdded, and InterfaceCount number for
+            // PropertiesChanged
+            thisSession.matches.reserve(thisSession.matches.size() +
+                                        paths->size() * (1U + interfaceCount));
             std::string objectManagerMatchString;
             std::string propertiesMatchString;
             std::string objectManagerInterfacesMatchString;