Fixed an invalid read/write caused by deleted temporary
authorErich Keane <erich.keane@intel.com>
Fri, 10 Jul 2015 22:42:07 +0000 (15:42 -0700)
committerErich Keane <erich.keane@intel.com>
Fri, 10 Jul 2015 23:56:25 +0000 (23:56 +0000)
The copy used a std::copy mechanism on optionData, which
resulted in the temporary being deleted before the function
returned.  This creates a variable to hold the temporary so that
the string won't be deleted before use.

Change-Id: I5da2601b730e27d42e244b52ba6cdd69a0e28fb4
Signed-off-by: Erich Keane <erich.keane@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1622
Reviewed-by: Mandeep Shetty <mandeep.shetty@intel.com>
Reviewed-by: Omkar Hegde <omkar.m.hegde@intel.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
resource/src/InProcServerWrapper.cpp

index d4f65df..7731952 100644 (file)
@@ -560,8 +560,9 @@ namespace OC
                     static_cast<uint16_t>(it->getOptionID());
                 response.sendVendorSpecificHeaderOptions[i].optionLength =
                     (it->getOptionData()).length() + 1;
-                std::copy(it->getOptionData().begin(),
-                         it->getOptionData().end(),
+                std::string optionData = it->getOptionData();
+                std::copy(optionData.begin(),
+                         optionData.end(),
                          response.sendVendorSpecificHeaderOptions[i].optionData);
                 response.sendVendorSpecificHeaderOptions[i].optionData[it->getOptionData().length()]
                     = '\0';