On 11/22/2013 10:54 AM, zhuyj wrote:
On 11/22/2013 02:45 AM, Bart Van Assche wrote:
On 10/16/13 10:31, zhuyj wrote:
If this patch is used in net-snmp-5.7.2, the following should be used,
too. If not, snmp-trap could not work well.
Hello Zhu,

Please make yourself familiar with git and start from the V5-7-patches
or master branch when preparing patches. The patch that was attached to
your e-mail doesn't apply on the V5-7-branch:

$ git checkout V5-7-patches
Switched to branch 'V5-7-patches'
Your branch is behind 'origin/V5-7-patches' by 2 commits, and can be
fast-forwarded.
   (use "git pull" to update your local branch)
$ git rebase origin/V5-7-patches
First, rewinding head to replay your work on top of it...
Fast-forwarded V5-7-patches to origin/V5-7-patches.
$ git apply -p1 ~/net-snmp-5.7.2-fix-param-length.patch
error: patch failed: agent/mibgroup/notification/snmpNotifyTable.c:338
error: agent/mibgroup/notification/snmpNotifyTable.c: patch does not apply

Bart.


Hi, Bart

Sorry. I prepared these patches based on net-snmp-5.7.2 release. I will prepare these patches based on V5-7-branch.

Best Regards!
Zhu Yanjun

Hi, Bart

I prepared 3 patches based on V5-7-branch.
I made tests following these steps. It can apply well.

1.git clone git://git.code.sf.net/p/net-snmp/code

2.git checkout V5-7-patches

3.git pull

4.patch -p1 < V5-7-patches-snmpTargetParam_support_zero_OID.patch
   patch -p1 < V5-7-patches-fix-param-length.patch
   patch -p1 < V5-7-patches-conf-support.patch

5../configure --enable-developer --disable-embeded-perl

6.sudo make && sudo make install

The three patches are in the attachment. Please make tests.

If any problem, please let me know.

Best Regards!
Zhu Yanjun
diff --git a/agent/mibgroup/target/snmpTargetAddrEntry.c b/agent/mibgroup/target/snmpTargetAddrEntry.c
index f2cb2ab..b3b2340 100644
--- a/agent/mibgroup/target/snmpTargetAddrEntry.c
+++ b/agent/mibgroup/target/snmpTargetAddrEntry.c
@@ -483,32 +483,6 @@ snmpTargetAddr_addTagList(struct targetAddrTable_struct *entry, char *cptr)
     return (1);
 }                               /* snmpTargetAddr_addTagList */
 
-
-int
-snmpTargetAddr_addParams(struct targetAddrTable_struct *entry, char *cptr)
-{
-    size_t          len;
-    if (cptr == NULL) {
-        DEBUGMSGTL(("snmpTargetAddrEntry",
-                    "ERROR snmpTargetAddrEntry: no params in config string\n"));
-        return (0);
-    } else {
-        len = strlen(cptr);
-        /*
-         * spec check for string 1-32 
-         */
-        if (len < 1 || len > 32) {
-            DEBUGMSGTL(("snmpTargetAddrEntry",
-                        "ERROR snmpTargetAddrEntry: params out of range in config string\n"));
-            return (0);
-        }
-        entry->params = strdup(cptr);
-        entry->paramsLen = len;
-    }
-    return (1);
-}                               /* snmpTargetAddr_addParams */
-
-
 int
 snmpTargetAddr_addStorageType(struct targetAddrTable_struct *entry,
                               char *cptr)
@@ -583,7 +557,7 @@ void
 snmpd_parse_config_targetAddr(const char *token, char *char_ptr)
 {
     const char     *cptr = char_ptr;
-    char            buff[1024], *bptr;
+    char            buff[1024], *bptr, tmp[1024], temp[1024];
     struct targetAddrTable_struct *newEntry;
     int             i;
     size_t          bufl;
@@ -641,11 +615,17 @@ snmpd_parse_config_targetAddr(const char *token, char *char_ptr)
         snmpTargetAddrTable_dispose(newEntry);
         return;
     }
-    cptr = copy_nword_const(cptr, buff, sizeof(buff));
-    if (snmpTargetAddr_addParams(newEntry, buff) == 0) {
-        snmpTargetAddrTable_dispose(newEntry);
-        return;
-    }
+    cptr =
+        read_config_read_octet_string_const(cptr,
+                                      (u_char **) &newEntry->params,
+                                      &bufl);
+    if (bufl < 1 || bufl > 32) {
+        DEBUGMSGTL(("snmpTargetAddrEntry",
+                    "ERROR snmpTargetAddrEntry: params out of range in config string\n"));
+         snmpTargetAddrTable_dispose(newEntry);
+         return;
+     }
+    newEntry->paramsLen = bufl;
     cptr = copy_nword_const(cptr, buff, sizeof(buff));
     if (snmpTargetAddr_addStorageType(newEntry, buff) == 0) {
         snmpTargetAddrTable_dispose(newEntry);
@@ -665,11 +645,15 @@ snmpd_parse_config_targetAddr(const char *token, char *char_ptr)
         bptr += snprintf(bptr, buff + sizeof(buff) - bptr,
                          ".%d", (int) newEntry->tDomain[i]);
     }
+    memset(tmp, 0, sizeof(tmp));
+    memset(temp, 0, sizeof(temp));
+    read_config_save_octet_string(tmp, newEntry->tAddress, newEntry->tAddressLen);
+    read_config_save_octet_string(temp, newEntry->params, newEntry->paramsLen);
     bptr += snprintf(bptr, buff + sizeof(buff) - bptr,
                      " %s %d %d %s %s %d %d\n",
-                     newEntry->tAddress, newEntry->timeout,
+                     tmp, newEntry->timeout,
                      newEntry->retryCount, newEntry->tagList,
-                     newEntry->params, newEntry->storageType,
+                     temp, newEntry->storageType,
                      newEntry->rowStatus);
     buff[ sizeof(buff) - 1 ] = 0;
     DEBUGMSGTL(("snmpTargetAddrEntry", "%s", buff));
@@ -693,7 +677,7 @@ store_snmpTargetAddrEntry(int majorID, int minorID, void *serverarg,
                           void *clientarg)
 {
     const struct targetAddrTable_struct *curr_struct;
-    char            line[1024], *cur, *ep = line + sizeof(line);
+    char            line[1024],tmp[1024], *cur, *ep = line + sizeof(line);
     int             i;
 
     curr_struct = aAddrTable;
@@ -713,10 +697,14 @@ store_snmpTargetAddrEntry(int majorID, int minorID, void *serverarg,
             *cur++ = ' ';
             cur = read_config_save_octet_string(
                 cur, curr_struct->tAddress, curr_struct->tAddressLen);
+            memset(tmp, 0, sizeof(tmp));
+            read_config_save_octet_string(tmp,
+                         (u_char*)curr_struct->params,
+                         curr_struct->paramsLen);
             cur += snprintf(cur, ep - cur, " %i %i \"%s\" %s %i %i",
                             curr_struct->timeout,
                             curr_struct->retryCount, curr_struct->tagList,
-                            curr_struct->params, curr_struct->storageType,
+                            tmp, curr_struct->storageType,
                             curr_struct->rowStatus);
             line[ sizeof(line)-1 ] = 0;
 
diff --git a/agent/mibgroup/notification/snmpNotifyTable.c b/agent/mibgroup/notification/snmpNotifyTable.c
index 54def03..20e00bf 100644
--- a/agent/mibgroup/notification/snmpNotifyTable.c
+++ b/agent/mibgroup/notification/snmpNotifyTable.c
@@ -338,6 +338,7 @@ notifyTable_register_notifications(int major, int minor,
     SNMP_FREE(ptr->tagList);
     ptr->tagList = strdup(buf); /* strdup ok since buf contains 'internal%d' */
     ptr->params = strdup(buf);
+    ptr->paramsLen = bufLen;
     ptr->storageType = ST_READONLY;
     ptr->rowStatus = RS_ACTIVE;
     ptr->sess = ss;
@@ -349,6 +350,7 @@ notifyTable_register_notifications(int major, int minor,
      */
     pptr = snmpTargetParamTable_create();
     pptr->paramName = strdup(buf);
+    pptr->paramNameLen = bufLen;
     pptr->mpModel = ss->version;
     if (ss->version == SNMP_VERSION_3) {
         pptr->secModel = ss->securityModel;
diff --git a/agent/mibgroup/notification/snmpNotifyTable.c b/agent/mibgroup/notification/snmpNotifyTable.c
index 91adb2f..54def03 100644
--- a/agent/mibgroup/notification/snmpNotifyTable.c
+++ b/agent/mibgroup/notification/snmpNotifyTable.c
@@ -304,7 +304,7 @@ notifyTable_register_notifications(int major, int minor,
     for (i = 0; i < MAX_ENTRIES; i++) {
         bufLen = sprintf(buf, "internal%d", i);
         if (get_addrForName2(buf, bufLen) == NULL &&
-            get_paramEntry(buf) == NULL)
+            get_paramEntry(buf, bufLen) == NULL)
             break;
     }
     if (i == MAX_ENTRIES) {
diff --git a/agent/mibgroup/target/snmpTargetAddrEntry.c b/agent/mibgroup/target/snmpTargetAddrEntry.c
index b1eb00a..f2cb2ab 100644
--- a/agent/mibgroup/target/snmpTargetAddrEntry.c
+++ b/agent/mibgroup/target/snmpTargetAddrEntry.c
@@ -80,6 +80,7 @@ struct targetAddrTable_struct *snmpTargetAddrTable_create(void)
 
         newEntry->tagList = strdup("");
         newEntry->params = NULL;
+        newEntry->paramsLen = 0;
 
         newEntry->storageType = SNMP_STORAGE_NONVOLATILE;
         newEntry->rowStatus = SNMP_ROW_NONEXISTENT;
@@ -103,8 +104,10 @@ snmpTargetAddrTable_dispose(struct targetAddrTable_struct *reaped)
     else
         SNMP_FREE(reaped->tAddress);
     SNMP_FREE(reaped->nameData);
+    reaped->nameLen = 0;
     SNMP_FREE(reaped->tagList);
     SNMP_FREE(reaped->params);
+    reaped->paramsLen = 0;
 
     SNMP_FREE(reaped);
 }                               /* snmpTargetAddrTable_dispose  */
@@ -500,6 +503,7 @@ snmpTargetAddr_addParams(struct targetAddrTable_struct *entry, char *cptr)
             return (0);
         }
         entry->params = strdup(cptr);
+        entry->paramsLen = len;
     }
     return (1);
 }                               /* snmpTargetAddr_addParams */
@@ -1294,6 +1298,7 @@ write_snmpTargetAddrParams(int action,
 {
     struct targetAddrTable_struct *target = NULL;
     static char    *old_params = NULL;
+    static char    old_paramsLen = 0;
 
     if (action == RESERVE1) {
         if (var_val_type != ASN_OCTET_STR) {
@@ -1326,12 +1331,14 @@ write_snmpTargetAddrParams(int action,
             }
 
             old_params = target->params;
+            old_paramsLen = target->paramsLen;
             target->params = malloc(var_val_len + 1);
             if (target->params == NULL) {
                 return SNMP_ERR_RESOURCEUNAVAILABLE;
             }
             memcpy(target->params, var_val, var_val_len);
             target->params[var_val_len] = '\0';
+            target->paramsLen = var_val_len;
 
             /*
              * If row is new, check if its status can be updated.  
@@ -1344,6 +1351,7 @@ write_snmpTargetAddrParams(int action,
     } else if (action == COMMIT) {
         SNMP_FREE(old_params);
         old_params = NULL;
+        old_paramsLen = 0;
         snmp_store_needed(NULL);
     } else if (action == FREE || action == UNDO) {
         /*
@@ -1359,6 +1367,7 @@ write_snmpTargetAddrParams(int action,
                 && target->rowStatus != SNMP_ROW_ACTIVE) {
                 SNMP_FREE(target->params);
                 target->params = old_params;
+                target->paramsLen = old_paramsLen;
                 if (target->rowStatus == SNMP_ROW_NOTINSERVICE &&
                     snmpTargetAddr_rowStatusCheck(target) == 0) {
                     target->rowStatus = SNMP_ROW_NOTREADY;
diff --git a/agent/mibgroup/target/snmpTargetAddrEntry.h b/agent/mibgroup/target/snmpTargetAddrEntry.h
index 0b70af5..43c0e01 100644
--- a/agent/mibgroup/target/snmpTargetAddrEntry.h
+++ b/agent/mibgroup/target/snmpTargetAddrEntry.h
@@ -56,6 +56,7 @@ config_add_mib(SNMPv2-TM)
          int             retryCount;
          char           *tagList;
          char           *params;
+         unsigned char   paramsLen;
          int             storageType;
          int             rowStatus;
          struct targetAddrTable_struct *next;
diff --git a/agent/mibgroup/target/snmpTargetParamsEntry.c b/agent/mibgroup/target/snmpTargetParamsEntry.c
index 4e1f4e2..b75e2f7 100644
--- a/agent/mibgroup/target/snmpTargetParamsEntry.c
+++ b/agent/mibgroup/target/snmpTargetParamsEntry.c
@@ -49,6 +49,7 @@ snmpTargetParamTable_create(void)
         malloc(sizeof(struct targetParamTable_struct));
 
     newEntry->paramName = NULL;
+    newEntry->paramNameLen = 0;
     newEntry->mpModel = -1;
 
     newEntry->secModel = -1;
@@ -70,6 +71,7 @@ void
 snmpTargetParamTable_dispose(struct targetParamTable_struct *reaped)
 {
     free(reaped->paramName);
+    reaped->paramNameLen = 0;
     free(reaped->secName);
 
     free(reaped);
@@ -102,7 +104,7 @@ snmpTargetParamTable_addToList(struct targetParamTable_struct *newEntry,
         /*
          * get the 'OID' value of the new entry 
          */
-        newOIDLen = strlen(newEntry->paramName);
+        newOIDLen = (size_t) newEntry->paramNameLen;
         for (i = 0; i < (int) newOIDLen; i++) {
             newOID[i] = newEntry->paramName[i];
         }
@@ -111,7 +113,7 @@ snmpTargetParamTable_addToList(struct targetParamTable_struct *newEntry,
          * search through the list for an equal or greater OID value 
          */
         while (curr_struct != NULL) {
-            currOIDLen = strlen(curr_struct->paramName);
+            currOIDLen = (size_t) curr_struct->paramNameLen;
             for (i = 0; i < (int) currOIDLen; i++) {
                 currOID[i] = curr_struct->paramName[i];
             }
@@ -204,10 +206,10 @@ search_snmpTargetParamsTable(oid * baseName,
 
     for (temp_struct = aPTable; temp_struct != NULL;
          temp_struct = temp_struct->next) {
-        for (i = 0; i < (int) strlen(temp_struct->paramName); i++) {
+        for (i = 0; i < (int) temp_struct->paramNameLen; i++) {
             newNum[baseNameLen + i] = temp_struct->paramName[i];
         }
-        myOIDLen = baseNameLen + strlen(temp_struct->paramName);
+        myOIDLen = baseNameLen + temp_struct->paramNameLen;
         i = snmp_oid_compare(name, *length, newNum, myOIDLen);
         /*
          * Assumes that the linked list sorted by OID, low to high 
@@ -320,6 +322,7 @@ snmpTargetParams_addParamName(struct targetParamTable_struct *entry,
             return (0);
         }
         entry->paramName = strdup(cptr);
+        entry->paramNameLen = len;
     }
     return (1);
 }
@@ -1233,6 +1236,7 @@ snmpTargetParams_createNewRow(oid * name, size_t name_len)
         }
 
         temp_struct->paramName[pNameLen] = '\0';
+        temp_struct->paramNameLen = pNameLen;
         temp_struct->rowStatus = SNMP_ROW_NOTREADY;
 
         update_timestamp(temp_struct);
@@ -1395,11 +1399,12 @@ write_snmpTargetParamsRowStatus(int action,
 
 
 struct targetParamTable_struct *
-get_paramEntry(char *name)
+get_paramEntry(char *name, unsigned char nameLen)
 {
     static struct targetParamTable_struct *ptr;
     for (ptr = aPTable; ptr; ptr = ptr->next) {
-        if (strcmp(ptr->paramName, name) == 0) {
+        if ((memcmp(ptr->paramName, name, ptr->paramNameLen) == 0) &&
+           (ptr->paramNameLen == nameLen)) {
             return ptr;
         }
     }
diff --git a/agent/mibgroup/target/snmpTargetParamsEntry.h b/agent/mibgroup/target/snmpTargetParamsEntry.h
index bd30582..aeb2199 100644
--- a/agent/mibgroup/target/snmpTargetParamsEntry.h
+++ b/agent/mibgroup/target/snmpTargetParamsEntry.h
@@ -29,6 +29,7 @@
        */
        struct targetParamTable_struct {
            char           *paramName;
+           unsigned char   paramNameLen;
            int             mpModel;
            int             secModel;
            char           *secName;
@@ -42,7 +43,7 @@
   /*
    * utility functions 
    */
-       struct targetParamTable_struct *get_paramEntry(char *name);
+       struct targetParamTable_struct *get_paramEntry(char *name, unsigned char nameLen);
        void            snmpTargetParamTable_add(struct
                                                 targetParamTable_struct
                                                 *newEntry);
diff --git a/agent/mibgroup/target/target.c b/agent/mibgroup/target/target.c
index 5619e35..0ea8ac3 100644
--- a/agent/mibgroup/target/target.c
+++ b/agent/mibgroup/target/target.c
@@ -94,7 +94,7 @@ get_target_sessions(char *taglist, TargetFilterFunction * filterfunct,
                                     tags[i]));
 
                         if (targaddrs->params) {
-                            param = get_paramEntry(targaddrs->params);
+                            param = get_paramEntry(targaddrs->params, targaddrs->paramsLen);
                             if (!param
                                 || param->rowStatus != SNMP_ROW_ACTIVE) {
                                 /*
------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing 
conversations that shape the rapidly evolving mobile landscape. Sign up now. 
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to