We copied the original object name `state->objectName` using the function
osaf_extended_name_lend(state->objectName, &objectName).

In case of long dn object, objectName contained a reference to the string
which was stored in `state->objectName`, any change to `state->objectName`,
in this case it was the code line `state->objectName[DNlen] = '\0',
would impact the backup `objectName`.

As the `objectName` had been changed unintentionally to non-existing object dn,
`saImmOmAccessorGet_2` returned `SA_AIS_ERR_NOT_EXIST` unexpectedly.

To fix this bug, using C++ string to save a copy of the original object
`state->objectName` string. Do so, the string value is not changed when
we play with `state->objectName`.
---
 src/imm/tools/imm_import.cc | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/imm/tools/imm_import.cc b/src/imm/tools/imm_import.cc
index 5397c67..d4f7c08 100644
--- a/src/imm/tools/imm_import.cc
+++ b/src/imm/tools/imm_import.cc
@@ -633,7 +633,7 @@ static void createImmObject(ParserState *state) {
   SaAisErrorT errorCode = SA_AIS_OK;
   int i = 0;
   size_t DNlen;
-  SaNameT objectName;
+  std::string objectName;
   std::list<SaImmAttrValuesT_2>::iterator it;
 
   TRACE_8("CREATE IMM OBJECT %s, %s", state->objectClass, state->objectName);
@@ -647,7 +647,7 @@ static void createImmObject(ParserState *state) {
   osaf_extended_name_clear(&parentName);
   if (state->objectName != NULL) {
     char *parent;
-    osaf_extended_name_lend(state->objectName, &objectName);
+    objectName = std::string{state->objectName};
 
     /* ',' is the delimeter */
     /* but '\' is the escape character, used for association objects */
@@ -746,6 +746,7 @@ static void createImmObject(ParserState *state) {
       SaImmAttrValuesT_2 **existing_attributes;
       SaImmAttrValuesT_2 *attr;
       const char *existing_className;
+      SaNameT dn;
 
       LOG_IN("OBJECT %s already exist, verifying...", state->objectName);
 
@@ -759,7 +760,8 @@ static void createImmObject(ParserState *state) {
         goto done;
       }
 
-      errorCode = immutil_saImmOmAccessorGet_2(accessorHandle, &objectName,
+      osaf_extended_name_lend(objectName.c_str(), &dn);
+      errorCode = immutil_saImmOmAccessorGet_2(accessorHandle, &dn,
                                                NULL,  // get all attributes
                                                &existing_attributes);
       if (SA_AIS_OK != errorCode) {
-- 
1.9.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to