[IOT-1052] Resource container fixes
authorMarkus Jung <markus.jung@samsung.com>
Thu, 31 Mar 2016 07:39:54 +0000 (16:39 +0900)
committerJungHo Kim <jhyo.kim@samsung.com>
Fri, 1 Apr 2016 06:10:55 +0000 (06:10 +0000)
Resource container fixes:
- Using strncat instead of strcat and including a length check for
configured paths.
- Checks for non-null references in Configuration.cpp
- Member initializiation in BundleInfoInternal.cpp

Change-Id: Ifb4c50a76b22e7c2b06465187c90a8328eda5a90
Signed-off-by: Markus Jung <markus.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/7509
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
Reviewed-by: JungHo Kim <jhyo.kim@samsung.com>
service/resource-container/src/BundleInfoInternal.cpp
service/resource-container/src/Configuration.cpp
service/resource-container/src/ResourceContainerImpl.cpp
service/resource-container/src/ResourceContainerImpl.h

index c6e7706..a15ae9c 100644 (file)
@@ -32,6 +32,7 @@ namespace OIC
             m_resourceCreator = nullptr;
             m_resourceDestroyer = nullptr;
             m_bundleHandle = nullptr;
+            m_so_bundle = nullptr;
 
             m_loaded = false;
             m_activated = false;
index 96f9526..c1dd082 100644 (file)
@@ -95,9 +95,10 @@ namespace OIC
             {
                 try
                 {
-                    if (m_xmlDoc.first_node())
+                    bundle = m_xmlDoc.first_node();
+                    if (bundle)
                     {
-                        for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
+                        for (bundle = bundle->first_node(BUNDLE_TAG); bundle; bundle =
                                  bundle->next_sibling())
                         {
                             std::map< std::string, std::string > bundleMap;
@@ -139,9 +140,10 @@ namespace OIC
                     std::map< std::string, std::string > bundleConfigMap;
 
                     // <bundle>
-                    if (m_xmlDoc.first_node())
+                    bundle = m_xmlDoc.first_node();
+                    if (bundle)
                     {
-                        for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
+                        for (bundle = bundle->first_node(BUNDLE_TAG); bundle; bundle =
                                  bundle->next_sibling())
                         {
                             // <id>
@@ -207,9 +209,10 @@ namespace OIC
                 try
                 {
                     // <bundle>
-                    if (m_xmlDoc.first_node())
+                    bundle = m_xmlDoc.first_node();
+                    if (bundle)
                     {
-                        for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle;
+                        for (bundle = bundle->first_node(BUNDLE_TAG); bundle;
                             bundle = bundle->next_sibling())
                         {
                             // <id>
@@ -222,9 +225,9 @@ namespace OIC
                             {
                                 OIC_LOG_V(INFO, CONTAINER_TAG, "Inspecting");
                                 // <resourceInfo>
-                                if (bundle->first_node(OUTPUT_RESOURCES_TAG)){
-                                    for (resource = bundle->first_node(OUTPUT_RESOURCES_TAG)->
-                                            first_node(OUTPUT_RESOURCE_INFO);
+                                bundle = bundle->first_node(OUTPUT_RESOURCES_TAG);
+                                if (bundle){
+                                    for (resource = bundle->first_node(OUTPUT_RESOURCE_INFO);
                                          resource; resource = resource->next_sibling())
                                     {
 
@@ -324,9 +327,10 @@ namespace OIC
                 try
                 {
                     // <bundle>
-                    if (m_xmlDoc.first_node())
+                    bundle = m_xmlDoc.first_node();
+                    if (bundle)
                     {
-                        for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
+                        for (bundle = bundle->first_node(BUNDLE_TAG); bundle; bundle =
                                  bundle->next_sibling())
                         {
                             // <id>
@@ -339,9 +343,10 @@ namespace OIC
                             {
                                 OIC_LOG_V(INFO, CONTAINER_TAG, "Inspecting");
                                 // <resourceInfo>
-                                if (bundle->first_node(OUTPUT_RESOURCES_TAG))
+                                bundle = bundle->first_node(OUTPUT_RESOURCES_TAG);
+                                if (bundle)
                                 {
-                                    for (resource = bundle->first_node(OUTPUT_RESOURCES_TAG)->
+                                    for (resource = bundle->
                                             first_node(OUTPUT_RESOURCE_INFO);
                                          resource; resource = resource->next_sibling())
                                     {
index b8dfd46..a25bc9a 100644 (file)
@@ -1001,7 +1001,7 @@ namespace OIC
             options[0].optionString = optionString;
             char classpath[1000];
             strcpy(classpath, "-Djava.class.path=");
-            strcat(classpath, bundleInfo->getPath().c_str());
+            strncat(classpath, bundleInfo->getPath().c_str(), BUNDLE_PATH_MAXLEN);
 
             OIC_LOG(INFO, CONTAINER_TAG,
                    std::string("Configured classpath: ").append(classpath).c_str());
@@ -1010,7 +1010,7 @@ namespace OIC
 
             char libraryPath[1000];
             strcpy(libraryPath, "-Djava.library.path=");
-            strcat(libraryPath, bundleInfo->getLibraryPath().c_str());
+            strncat(libraryPath, bundleInfo->getLibraryPath().c_str(), BUNDLE_PATH_MAXLEN);
             options[2].optionString = libraryPath;
 
             OIC_LOG(INFO, CONTAINER_TAG,
index 1428514..b7cb614 100644 (file)
@@ -42,6 +42,7 @@
 
 #define BUNDLE_ACTIVATION_WAIT_SEC 10
 #define BUNDLE_SET_GET_WAIT_SEC 10
+#define BUNDLE_PATH_MAXLEN 300
 
 using namespace OIC::Service;