more fixes
---
 src/ntf/apitest/test_ntf_imcn.cc | 53 +++++++++++++++++++++++---------
 src/plm/plmcd/plmc_read_config.c |  2 +-
 2 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/src/ntf/apitest/test_ntf_imcn.cc b/src/ntf/apitest/test_ntf_imcn.cc
index b1a1e87b4..51b9076c6 100644
--- a/src/ntf/apitest/test_ntf_imcn.cc
+++ b/src/ntf/apitest/test_ntf_imcn.cc
@@ -47,6 +47,14 @@ static SaImmOiHandleT immOiHnd = 0;
 static char extended_name_string_01[DEFAULT_EXT_NAME_LENGTH];
 static char extended_name_string_02[DEFAULT_EXT_NAME_LENGTH];
 
+static char NAME1_STR[sizeof(NAME1) + 1] = { '\0' };
+static char NAME2_STR[sizeof(NAME2) + 1] = { '\0' };
+static char NAME3_STR[sizeof(NAME3) + 1] = { '\0' };
+
+static char BUF1_STR[sizeof(BUF1) + 1] = { '\0' };
+static char BUF2_STR[sizeof(BUF2) + 1] = { '\0' };
+static char BUF3_STR[sizeof(BUF3) + 1] = { '\0' };
+
 /**
  * Callback routine, called when subscribed notification arrives.
  */
@@ -1131,7 +1139,8 @@ static SaAisErrorT set_add_info(
                               reinterpret_cast<void **>(&temp),
                               &nHeader->additionalInfo[idx].infoValue);
   if (error == SA_AIS_OK) {
-    strncpy(reinterpret_cast<char *>(temp), infoValue, strlen(infoValue) + 1);
+    strcpy(reinterpret_cast<char *>(temp), infoValue);
+    temp[strlen(infoValue) - 1] = '\0';
     nHeader->additionalInfo[idx].infoId = infoId;
     nHeader->additionalInfo[idx].infoType = SA_NTF_VALUE_STRING;
   }
@@ -1154,7 +1163,7 @@ static SaAisErrorT set_attr_str(
         &n_exp->c_d_notif_ptr->objectAttributes[idx]
        .attributeValue);
     if (error == SA_AIS_OK) {
-      strncpy(reinterpret_cast<char *>(temp), attrValue, strlen(attrValue) + 
1);
+      strcpy(reinterpret_cast<char *>(temp), attrValue);
       n_exp->c_d_notif_ptr->objectAttributes[idx]
           .attributeId = attrId;
       n_exp->c_d_notif_ptr->objectAttributes[idx]
@@ -1285,7 +1294,7 @@ static SaAisErrorT set_attr_change_str(
         &n_exp->a_c_notif_ptr->changedAttributes[idx]
        .newAttributeValue);
     if (error == SA_AIS_OK) {
-      strncpy(reinterpret_cast<char *>(temp), newValue, strlen(newValue) + 1);
+      strcpy(reinterpret_cast<char *>(temp), newValue);
       n_exp->a_c_notif_ptr->changedAttributes[idx]
           .attributeId = attrId;
       n_exp->a_c_notif_ptr->changedAttributes[idx]
@@ -3155,7 +3164,7 @@ void objectCreateTest_20(void) {
   /* create an object */
   snprintf(command, MAX_DATA, "immcfg -t 20 -c OsafNtfCmTestCFG %s"
            " -a testNameCfg=%s -a testStringCfg=%s -a testAnyCfg=%s",
-          DNTESTCFG, NAME1, STRINGVAR1, BUF1);
+          DNTESTCFG, NAME1_STR, STRINGVAR1, BUF1_STR);
   assert(system(command) != -1);
 
   /*
@@ -3364,7 +3373,7 @@ void objectModifyTest_22(void) {
 
   /* modify an object */
   snprintf(command, MAX_DATA, "immcfg -t 20 -a testNameCfg=%s "
-           "-a testAnyCfg=%s %s", NAME2, BUF2, DNTESTCFG);
+           "-a testAnyCfg=%s %s", NAME2_STR, BUF2_STR, DNTESTCFG);
   assert(system(command) != -1);
 
   /*
@@ -4044,7 +4053,9 @@ void objectModifyTest_31(void) {
   memcpy(oldvar.value, NAME2, sizeof(NAME2));
   SaNameT addvar = {.length = sizeof(NAME3)};
   memcpy(addvar.value, NAME3, sizeof(NAME3));
-  snprintf(command, MAX_DATA, "immcfg -a testNameCfg+=%s %s", NAME3, 
DNTESTCFG);
+
+  snprintf(command, MAX_DATA, "immcfg -a testNameCfg+=%s %s", NAME3_STR,
+           DNTESTCFG);
   assert(system(command) != -1);
 
   /*
@@ -4120,8 +4131,12 @@ void objectModifyTest_32(void) {
        .bufferAddr = const_cast<SaUint8T *>(BUF2)};
   SaAnyT addvar = {.bufferSize = sizeof(BUF3),
        .bufferAddr = const_cast<SaUint8T *>(BUF3)};
+
+  char buf3[SA_MAX_NAME_LENGTH] = { '\0' };
+  memcpy(buf3, BUF3, sizeof(BUF3));
+
   snprintf(command, MAX_DATA, "immcfg -t 20 -a testAnyCfg+=%s %s",
-           BUF3, DNTESTCFG);
+           BUF3_STR, DNTESTCFG);
   assert(system(command) != -1);
 
   /*
@@ -4546,7 +4561,7 @@ void objectModifyTest_37(void) {
     " -a testTimeCfg+=%lld -a testStringCfg+=%s"
     " -a testNameCfg+=%s -a testAnyCfg+=%s %s",
     i32var11, ui32var2, i64var333, ui64var444, fvar5, dvar66,
-    tvar77, svar8, NAME1, BUF1, DNTESTCFG);
+    tvar77, svar8, NAME1_STR, BUF1_STR, DNTESTCFG);
   assert(system(command) != -1);
 
   /*
@@ -5821,7 +5836,7 @@ void objectCreateTest_3505(void) {
   /* create an object */
   snprintf(command, MAX_DATA, "immcfg -t 20 -c OsafNtfCmTestCFG %s"
       " -a testNameCfg=%s -a testStringCfg=%s -a testAnyCfg=%s",
-      DNTESTCFG, extended_name_string_01, STRINGVAR1, BUF1);
+      DNTESTCFG, extended_name_string_01, STRINGVAR1, BUF1_STR);
   assert(system(command) != -1);
 
   /*
@@ -5955,7 +5970,7 @@ void objectModifyTest_3506(void) {
 
   /* modify an object */
   snprintf(command, MAX_DATA, "immcfg -t 20 -a testNameCfg=%s"
-      " -a testAnyCfg=%s %s", extended_name_string_02, BUF2, DNTESTCFG);
+      " -a testAnyCfg=%s %s", extended_name_string_02, BUF2_STR, DNTESTCFG);
   assert(system(command) != -1);
 
   /*
@@ -6185,10 +6200,12 @@ __attribute__((constructor)) static void 
ntf_imcn_constructor(void) {
           if (strstr(line, ".xml") != NULL) {
             char cp_cmd[80];
             snprintf(cp_cmd, sizeof(cp_cmd), "cp ");
-            strncat(
-                cp_cmd, line,
-                strlen(line) -
-              1);  // don't add newline
+            if ((strlen(line) - 1) > (sizeof(cp_cmd) - sizeof("cp "))) {
+              printf("line: %s too long", line);
+              return;
+            }
+            line[strlen(line)] = '\0';
+            strcat(cp_cmd, line);  // don't add newline
             strncat(cp_cmd, " /tmp/.", 80 - strlen(cp_cmd));
             rc = system(cp_cmd);
           } else {
@@ -6215,6 +6232,14 @@ __attribute__((constructor)) static void 
ntf_imcn_constructor(void) {
   memset(&extended_name_string_02, 'D', DEFAULT_EXT_NAME_LENGTH - 1);
   extended_name_string_02[DEFAULT_EXT_NAME_LENGTH - 1] = '\0';
 
+  memcpy(&NAME1_STR, NAME1, sizeof(NAME1));
+  memcpy(&NAME2_STR, NAME2, sizeof(NAME2));
+  memcpy(&NAME3_STR, NAME3, sizeof(NAME3));
+
+  memcpy(&BUF1_STR, BUF1, sizeof(BUF1));
+  memcpy(&BUF2_STR, BUF2, sizeof(BUF2));
+  memcpy(&BUF3_STR, BUF3, sizeof(BUF3));
+
   test_suite_add(32, "CM notifications test");
   test_case_add(32, objectCreateTest_01,
           "CREATE, runtime (OsafNtfCmTestRT) object");
diff --git a/src/plm/plmcd/plmc_read_config.c b/src/plm/plmcd/plmc_read_config.c
index 30daa1815..acda7c72e 100644
--- a/src/plm/plmcd/plmc_read_config.c
+++ b/src/plm/plmcd/plmc_read_config.c
@@ -42,7 +42,7 @@ static int checkfile(char *buf)
        int ii;
        char cmd[PLMC_MAX_TAG_LEN];
 
-       strncpy(cmd, buf, PLMC_MAX_TAG_LEN);
+       strncpy(cmd, buf, PLMC_MAX_TAG_LEN - 1);
        for (ii = 0; ii < strlen(cmd); ii++)
                if (cmd[ii] == ' ')
                        cmd[ii] = '\0';
-- 
2.21.1


-----------------------------------------------------------------------------------------------------------------------
Notice: This e-mail together with any attachments may contain information of 
Ribbon Communications Inc. that
is confidential and/or proprietary for the sole use of the intended recipient.  
Any review, disclosure, reliance or
distribution by others or forwarding without express permission is strictly 
prohibited.  If you are not the intended
recipient, please notify the sender immediately and then delete all copies, 
including any attachments.
-----------------------------------------------------------------------------------------------------------------------

_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to