osaf/libs/agents/saf/imma/imma_om_api.c |  22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)


Add missing check for the case that root name length is great than 0, and root 
name value length is 0.

diff --git a/osaf/libs/agents/saf/imma/imma_om_api.c 
b/osaf/libs/agents/saf/imma/imma_om_api.c
--- a/osaf/libs/agents/saf/imma/imma_om_api.c
+++ b/osaf/libs/agents/saf/imma/imma_om_api.c
@@ -6204,13 +6204,21 @@ SaAisErrorT saImmOmSearchInitialize_2(Sa
        evt.info.immnd.type = IMMND_EVT_A2ND_SEARCHINIT;
        IMMSV_OM_SEARCH_INIT *req = &(evt.info.immnd.info.searchInit);
        req->client_hdl = immHandle;
-       if (rootName && rootName->length && (rootName->length < 
SA_MAX_NAME_LENGTH)) {
-               req->rootName.size = strlen((char *)rootName->value) + 1;
-               if (rootName->length + 1 < req->rootName.size)
-                       req->rootName.size = rootName->length + 1;
+
+       int rootNameLength = 0;
+       if(rootName) {
+               if(rootName->length >= SA_MAX_NAME_LENGTH) {
+                       rc = SA_AIS_ERR_INVALID_PARAM;
+                       TRACE_3("ERR_INVALID_PARAM: root name length is too 
long: %u bytes", rootName->length);
+                       goto bad_sync;
+               }
+               rootNameLength = strnlen((char *)rootName->value, 
rootName->length);
+       }
+       if (rootNameLength) {
+               req->rootName.size = rootNameLength + 1;
                req->rootName.buf = malloc(req->rootName.size); /* alloc-1 */
-               strncpy(req->rootName.buf, (char *)rootName->value, 
(size_t)req->rootName.size);
-               req->rootName.buf[req->rootName.size - 1] = 0;
+               memcpy(req->rootName.buf, (char *)rootName->value, 
(size_t)rootNameLength);
+               req->rootName.buf[rootNameLength] = 0;
        } else {
                req->rootName.size = 0;
                req->rootName.buf = NULL;
@@ -6265,7 +6273,7 @@ SaAisErrorT saImmOmSearchInitialize_2(Sa
                }
        }
 
-       if (rootName && rootName->length) {
+       if (rootName && rootNameLength) {
                TRACE("root: %s param:%p", rootName->value, searchParam);
        }
 

------------------------------------------------------------------------------
Slashdot TV.  Videos for Nerds.  Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to