The malloc and free at least should be avoided if the SaNameT provided by the
client is already
wellformed and nullterminated. I think one of the existing
osaf_extended_name_... functions already
Does performs the null termination check. But it can in this case be used only
if it does not assert
on failure.
This is a generic pattern-check that nees to be plugged as close to the API
source as possible
for all IMM APIs where the client provides an SaNameT value.
The other cases are coverde by enhancement ticket #1269
https://sourceforge.net/p/opensaf/tickets/1269/
/AndersBj
-----Original Message-----
From: Zoran Milinkovic
Sent: den 25 mars 2015 15:04
To: Hung Nguyen D; Anders Björnerstedt
Cc: [email protected]
Subject: RE: [devel] [PATCH 1 of 1] imm: Ensure strings sent to IMM server are
null terminated [#1277]
Ack from me.
The code is reverted, as it was before #643.
The code can also be improved with adding a char array of 256 on the stack.
Then malloc() and free() can be avoided. This is just a small performance issue.
Best regards,
Zoran
-----Original Message-----
From: Hung Nguyen [mailto:[email protected]]
Sent: Monday, March 23, 2015 2:18 PM
To: Anders Björnerstedt
Cc: [email protected]
Subject: [devel] [PATCH 1 of 1] imm: Ensure strings sent to IMM server are null
terminated [#1277]
osaf/libs/agents/saf/imma/imma_oi_api.c | 13 ++++++++++++-
osaf/libs/agents/saf/imma/imma_om_api.c | 13 ++++++++++++-
2 files changed, 24 insertions(+), 2 deletions(-)
Ensure strings sent to IMM server are null terminated.
diff --git a/osaf/libs/agents/saf/imma/imma_oi_api.c
b/osaf/libs/agents/saf/imma/imma_oi_api.c
--- a/osaf/libs/agents/saf/imma/imma_oi_api.c
+++ b/osaf/libs/agents/saf/imma/imma_oi_api.c
@@ -2839,7 +2839,13 @@ static SaAisErrorT rt_object_create_comm
size_t parentNameLen = 0;
if (parentName && (parentNameLen =
osaf_extended_name_length(parentName)) > 0) {
evt.info.immnd.info.objCreate.parentOrObjectDn.size =
parentNameLen + 1;
- evt.info.immnd.info.objCreate.parentOrObjectDn.buf =
(char *)osaf_extended_name_borrow(parentName);
+ evt.info.immnd.info.objCreate.parentOrObjectDn.buf =
(char*) malloc((parentNameLen + 1) * sizeof(char));
+ if
(!evt.info.immnd.info.objCreate.parentOrObjectDn.buf) {
+ rc = SA_AIS_ERR_NO_MEMORY;
+ goto mds_send_fail;
+ }
+
memcpy(evt.info.immnd.info.objCreate.parentOrObjectDn.buf,
osaf_extended_name_borrow(parentName), parentNameLen);
+
evt.info.immnd.info.objCreate.parentOrObjectDn.buf[parentNameLen] =
+'\0';
} else {
evt.info.immnd.info.objCreate.parentOrObjectDn.size = 0;
evt.info.immnd.info.objCreate.parentOrObjectDn.buf =
NULL; @@ -2988,6 +2994,11 @@ static SaAisErrorT rt_object_create_comm
evt.info.immnd.info.objCreate.className.buf = NULL;
}
+ if (parentName && evt.info.immnd.info.objCreate.parentOrObjectDn.buf) {
+ free(evt.info.immnd.info.objCreate.parentOrObjectDn.buf);
+ evt.info.immnd.info.objCreate.parentOrObjectDn.buf = NULL;
+ }
+
while (evt.info.immnd.info.objCreate.attrValues) {
IMMSV_ATTR_VALUES_LIST *p =
evt.info.immnd.info.objCreate.attrValues;
evt.info.immnd.info.objCreate.attrValues = p->next; 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
@@ -1838,7 +1838,13 @@ static SaAisErrorT ccb_object_create_com
}
evt.info.immnd.info.objCreate.parentOrObjectDn.size =
parentNameLength + 1;
- evt.info.immnd.info.objCreate.parentOrObjectDn.buf = (char
*)osaf_extended_name_borrow(parentName);
+ evt.info.immnd.info.objCreate.parentOrObjectDn.buf = (char*)
malloc((parentNameLength + 1) * sizeof(char));
+ if (!evt.info.immnd.info.objCreate.parentOrObjectDn.buf) {
+ rc = SA_AIS_ERR_NO_MEMORY;
+ goto mds_send_fail;
+ }
+ memcpy(evt.info.immnd.info.objCreate.parentOrObjectDn.buf,
osaf_extended_name_borrow(parentName), parentNameLength);
+
evt.info.immnd.info.objCreate.parentOrObjectDn.buf[parentNameLength]
+= '\0';
} else if (objectName) {
size_t objectNameLength = strlen(objectName);
if(!osaf_is_extended_names_enabled() && objectNameLength >=
SA_MAX_UNEXTENDED_NAME_LENGTH) { @@ -1987,6 +1993,11 @@ static SaAisErrorT
ccb_object_create_com
evt.info.immnd.info.objCreate.className.buf = NULL;
}
+ if (parentName && evt.info.immnd.info.objCreate.parentOrObjectDn.buf) {
+ free(evt.info.immnd.info.objCreate.parentOrObjectDn.buf);
+ evt.info.immnd.info.objCreate.parentOrObjectDn.buf = NULL;
+ }
+
while (evt.info.immnd.info.objCreate.attrValues) {
IMMSV_ATTR_VALUES_LIST *p =
evt.info.immnd.info.objCreate.attrValues;
evt.info.immnd.info.objCreate.attrValues = p->next;
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel