Hi Vu,

Your solution will probably work but is a bit problematic. The actual problem 
is that state is an in-parameter and in this case state->objectName is changed 
by the createImmObject() function and this change is without any meaning in the 
place where createImmObject() is called. Furthermore it seems as if the only 
reason for changing is a trace, TRACE_8("OBJECT NAME: %s", state->objectName);
I think you should fix this in an "opposite" way. Instead of creating a string 
variable to preserve the scope you should remove the code that manipulates 
state->objectName, the variable is not owned by createImmObject() so it should 
never change its value. Instead copy the content of state->objectName to a 
temporary string and then manipulate that string in order to create the wanted 
text for the trace.

Should also be fixed (maybe later?):
The loadImmXML() is where state is created and initialized. This means that 
this function is the "owner" of the ParserState structure. It also means that 
ParserState (state) shall be within scope as long as this function is in scope. 
If changes are done to variables in the structure by some function it must be 
clearly stated that this is the case (then state is not an in parameter but an 
in/out parameter) also if state is supposed to be an in-parameter it should be 
const. The structure itself should have a constructor for initializing its 
variables (is now done in the loadImmXML() function) and a destructor for 
cleaning up. Now freeing variables is done is several functions!!

Thanks
Lennart

> -----Original Message-----
> From: Vu Minh Nguyen <[email protected]>
> Sent: den 11 juni 2018 11:51
> To: Gary Lee <[email protected]>; Hans Nordebäck
> <[email protected]>
> Cc: [email protected]
> Subject: [devel] [PATCH 1/1] imm: fix failure to import file containing 
> existing
> long dn object [#2874]
> 
> 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

------------------------------------------------------------------------------
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