Hi Lennart,

See my comments inline, started with [Vu].

Regards, Vu

> -----Original Message-----
> From: Lennart Lund <[email protected]>
> Sent: Monday, June 18, 2018 6:02 PM
> To: Vu Minh Nguyen <[email protected]>; Gary Lee
> <[email protected]>; Hans Nordebäck
> <[email protected]>
> Cc: [email protected]
> Subject: RE: [devel] [PATCH 1/1] imm: fix failure to import file
containing
> existing long dn object [#2874]
> 
> 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);
[Vu] The change is there to separate the RDN and the parent DN from
`state->objectName`.
The output of this separation is for ` saImmOmCcbObjectCreate_2`. 

> 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.
[Vu] This is a good idea. I will send out the V2 patch.

> 
> 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
[Vu] immcfg uses libxml to parse XML file, and ParserState is user data
which is updated time to time during processing XML file.
If having any error during that time, following changes/call should be made
at least:
    stopParser(state);
    state->parsingStatus = 1;

Therefore, ParserState should be an in-out parameter.

> 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!!
[Vu] I understand your intention, but it could be a lot of works to refactor
the code using RAII for ParserState. 
Some ParserState data are allocated in this xmlSAXHandler's handler, but
should be freed in another. Not sure the code can be implemented in the way
as your suggestion.

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