On Wed, 2013-07-10 at 10:34 +0800, zhuyj wrote:
> Hi,
>
> Attempting to create a new entry with a zero index fails silently.
Ok, You want to index your entry with the string <NUL><EM>.
The mess up is, just as usual, that people believes that <NUL> is a
string terminator. That is wrong.
Your idea of using \xff as a string terminator is, while not wrong (\xff
is forbidden in utf-8 strings), confusing for a casual reader of the
code.
The correct solution is to store the length of the passed in octet
sequence.
A completely untested patch against master is attached.
Does it help you?
Note - the rename of name to nameData and get_addrForName to
get_addrForName2 was to make it easier to find unconverted code.
/MF
> root@localhost:/root> snmpset -v 2c -c public 192.168.2.15
> .1.3.6.1.6.3.12.1.2.1.9.0.25 i 5
> SNMP-TARGET-MIB::snmpTargetAddrRowStatus.'..' = INTEGER: createAndWait(5)
> root@localhost:/root> snmpget -v 2c -c NETMAN 192.168.2.15
> .1.3.6.1.6.3.12.1.2.1.9.0.25 i 5
> snmp_build: unknown failuresnmpget: Error building ASN.1 representation
> (Can't build OID for variable)
>
> Notice that there is no error when setting, only when trying to get.
>
> The version:
>
> usr@ubuntu1004:~$ snmpset --version
> NET-SNMP version: 5.7.2
> usr@ubuntu1004:~$ snmpget --version
> NET-SNMP version: 5.7.2
> usr@ubuntu1004:~$ snmpd --version
>
> NET-SNMP version: 5.7.2
> Web: http://www.net-snmp.org/
> Email: net-snmp-coders@lists.sourceforge.net
>
> I want to support 0.25 in snmpAdminString. What should I pay attention to?
>
> Best regards.
>
> zhuyj
>
> ------------------------------------------------------------------------------
> See everything from the browser to the database with AppDynamics
> Get end-to-end visibility with application monitoring from AppDynamics
> Isolate bottlenecks and diagnose root cause in seconds.
> Start your free trial of AppDynamics Pro today!
> http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
> _______________________________________________
> Net-snmp-coders mailing list
> Net-snmp-coders@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/net-snmp-coders
diff --git a/agent/mibgroup/notification/snmpNotifyTable.c b/agent/mibgroup/notification/snmpNotifyTable.c
index 8d09c59..352358e 100644
--- a/agent/mibgroup/notification/snmpNotifyTable.c
+++ b/agent/mibgroup/notification/snmpNotifyTable.c
@@ -285,7 +285,7 @@ notifyTable_register_notifications(int major, int minor,
struct targetAddrTable_struct *ptr;
struct targetParamTable_struct *pptr;
struct snmpNotifyTable_data *nptr;
- int confirm, i;
+ int confirm, i, bufLen;
char buf[SNMP_MAXBUF_SMALL];
netsnmp_transport *t = NULL;
struct agent_add_trap_args *args =
@@ -302,8 +302,9 @@ notifyTable_register_notifications(int major, int minor,
* XXX: START move target creation to target code
*/
for (i = 0; i < MAX_ENTRIES; i++) {
- sprintf(buf, "internal%d", i);
- if (get_addrForName(buf) == NULL && get_paramEntry(buf) == NULL)
+ bufLen = sprintf(buf, "internal%d", i);
+ if (get_addrForName2(buf, bufLen) == NULL &&
+ get_paramEntry(buf) == NULL)
break;
}
if (i == MAX_ENTRIES) {
@@ -325,7 +326,8 @@ notifyTable_register_notifications(int major, int minor,
return 0;
}
ptr = snmpTargetAddrTable_create();
- ptr->name = strdup(buf);
+ ptr->nameData = strdup(buf);
+ ptr->nameLen = bufLen;
memcpy(ptr->tDomain, t->domain, t->domain_length * sizeof(oid));
ptr->tDomainLen = t->domain_length;
ptr->tAddressLen = t->remote_length;
@@ -334,8 +336,8 @@ notifyTable_register_notifications(int major, int minor,
ptr->timeout = ss->timeout / 1000;
ptr->retryCount = ss->retries;
SNMP_FREE(ptr->tagList);
- ptr->tagList = strdup(ptr->name);
- ptr->params = strdup(ptr->name);
+ ptr->tagList = strdup(buf);
+ ptr->params = strdup(buf);
ptr->storageType = ST_READONLY;
ptr->rowStatus = RS_ACTIVE;
ptr->sess = ss;
diff --git a/agent/mibgroup/target/snmpTargetAddrEntry.c b/agent/mibgroup/target/snmpTargetAddrEntry.c
index a77b467..484674c 100644
--- a/agent/mibgroup/target/snmpTargetAddrEntry.c
+++ b/agent/mibgroup/target/snmpTargetAddrEntry.c
@@ -42,11 +42,12 @@ get_addrTable(void)
}
struct targetAddrTable_struct *
-get_addrForName(char *name)
+get_addrForName2(char *name, unsigned char nameLen)
{
struct targetAddrTable_struct *ptr;
for (ptr = aAddrTable; ptr != NULL; ptr = ptr->next) {
- if (ptr->name && strcmp(ptr->name, name) == 0)
+ if (ptr->nameLen == nameLen &&
+ memcmp(ptr->nameData, name, nameLen) == 0)
return ptr;
}
return NULL;
@@ -67,7 +68,8 @@ snmpTargetAddrTable_create(void)
malloc(sizeof(struct targetAddrTable_struct));
if (newEntry) {
- newEntry->name = NULL;
+ newEntry->nameData = NULL;
+ newEntry->nameLen = 0;
newEntry->tDomainLen = 0;
newEntry->tAddress = NULL;
@@ -99,7 +101,7 @@ snmpTargetAddrTable_dispose(struct targetAddrTable_struct *reaped)
snmp_close(reaped->sess);
else
SNMP_FREE(reaped->tAddress);
- SNMP_FREE(reaped->name);
+ SNMP_FREE(reaped->nameData);
SNMP_FREE(reaped->tagList);
SNMP_FREE(reaped->params);
@@ -119,8 +121,6 @@ snmpTargetAddrTable_addToList(struct targetAddrTable_struct *newEntry,
{
static struct targetAddrTable_struct *curr_struct, *prev_struct;
int i;
- size_t newOIDLen = 0, currOIDLen = 0;
- oid newOID[128], currOID[128];
/*
* if the list is empty, add the new entry to the top
@@ -130,23 +130,17 @@ snmpTargetAddrTable_addToList(struct targetAddrTable_struct *newEntry,
return;
} else {
/*
- * get the 'OID' value of the new entry
- */
- newOIDLen = strlen(newEntry->name);
- for (i = 0; i < (int) newOIDLen; i++) {
- newOID[i] = newEntry->name[i];
- }
-
- /*
* search through the list for an equal or greater OID value
*/
while (curr_struct != NULL) {
- currOIDLen = strlen(curr_struct->name);
- for (i = 0; i < (int) currOIDLen; i++) {
- currOID[i] = curr_struct->name[i];
- }
+ if (newEntry->nameLen < curr_struct->nameLen)
+ i = -1;
+ else if (newEntry->nameLen > curr_struct->nameLen)
+ i = 1;
+ else
+ i = memcmp(newEntry->nameData, curr_struct->nameData,
+ newEntry->nameLen);
- i = snmp_oid_compare(newOID, newOIDLen, currOID, currOIDLen);
if (i == 0) { /* Exact match, overwrite with new struct */
newEntry->next = curr_struct->next;
/*
@@ -236,10 +230,10 @@ search_snmpTargetAddrTable(oid * baseName,
for (temp_struct = aAddrTable; temp_struct != NULL;
temp_struct = temp_struct->next) {
- for (i = 0; i < (int) strlen(temp_struct->name); i++) {
- newNum[baseNameLen + i] = temp_struct->name[i];
+ for (i = 0; i < temp_struct->nameLen; i++) {
+ newNum[baseNameLen + i] = temp_struct->nameData[i];
}
- myOIDLen = baseNameLen + strlen(temp_struct->name);
+ myOIDLen = baseNameLen + temp_struct->nameLen;
i = snmp_oid_compare(name, *length, newNum, myOIDLen);
/*
* Assumes that the linked list sorted by OID, low to high
@@ -372,7 +366,8 @@ snmpTargetAddr_addName(struct targetAddrTable_struct *entry, char *cptr)
"ERROR snmpTargetAddrEntry: name out of range in config string\n"));
return (0);
}
- entry->name = strdup(cptr);
+ entry->nameData = strdup(cptr);
+ entry->nameLen = len;
}
return (1);
} /* addName */
@@ -666,7 +661,7 @@ snmpd_parse_config_targetAddr(const char *token, char *char_ptr)
return;
}
snprintf(buff, sizeof(buff), "snmp_parse_config_targetAddr, read: %s\n",
- newEntry->name);
+ newEntry->nameData);
buff[ sizeof(buff)-1 ] = 0;
for (i = 0; i < newEntry->tDomainLen; i++) {
snprintf(&buff[strlen(buff)], sizeof(buff)-strlen(buff)-1,
@@ -711,7 +706,7 @@ store_snmpTargetAddrEntry(int majorID, int minorID, void *serverarg,
(curr_struct->rowStatus == SNMP_ROW_ACTIVE ||
curr_struct->rowStatus == SNMP_ROW_NOTINSERVICE)) {
snprintf(line, sizeof(line),
- "targetAddr %s ", curr_struct->name);
+ "targetAddr %s ", curr_struct->nameData);
line[ sizeof(line)-1 ] = 0;
for (i = 0; i < curr_struct->tDomainLen; i++) {
snprintf(&line[strlen(line)],
@@ -1465,18 +1460,19 @@ snmpTargetAddr_createNewRow(oid * name, size_t name_len)
temp_struct = snmpTargetAddrTable_create();
if (!temp_struct)
return SNMP_ERR_GENERR;
- temp_struct->name = (char *) malloc(newNameLen + 1);
- if (temp_struct->name == NULL) {
+ temp_struct->nameData = (char *) malloc(newNameLen + 1);
+ if (temp_struct->nameData == NULL) {
SNMP_FREE(temp_struct->tagList);
SNMP_FREE(temp_struct);
return 0;
}
+ temp_struct->nameLen = newNameLen;
for (i = 0; i < (int) newNameLen; i++) {
- temp_struct->name[i] = (char) name[i + snmpTargetAddrOIDLen];
+ temp_struct->nameData[i] = (char) name[i + snmpTargetAddrOIDLen];
}
- temp_struct->name[newNameLen] = '\0';
+ temp_struct->nameData[newNameLen] = '\0';
temp_struct->rowStatus = SNMP_ROW_NOTREADY;
snmpTargetAddrTable_addToList(temp_struct, &aAddrTable);
diff --git a/agent/mibgroup/target/snmpTargetAddrEntry.h b/agent/mibgroup/target/snmpTargetAddrEntry.h
index 790ed66..3b89ce2 100644
--- a/agent/mibgroup/target/snmpTargetAddrEntry.h
+++ b/agent/mibgroup/target/snmpTargetAddrEntry.h
@@ -46,7 +46,8 @@ config_add_mib(SNMPv2-TM)
* structure definitions
*/
struct targetAddrTable_struct {
- char *name;
+ char *nameData;
+ unsigned char nameLen;
oid tDomain[MAX_OID_LEN];
int tDomainLen;
unsigned char *tAddress;
@@ -74,7 +75,8 @@ config_add_mib(SNMPv2-TM)
FindVarMethod var_snmpTargetAddrEntry;
struct targetAddrTable_struct *get_addrTable(void);
- struct targetAddrTable_struct *get_addrForName(char *name);
+struct targetAddrTable_struct *get_addrForName2(char *name,
+ unsigned char nameLen);
struct targetAddrTable_struct *snmpTargetAddrTable_create(void);
void snmpTargetAddrTable_add(struct targetAddrTable_struct
*newEntry);
diff --git a/agent/mibgroup/target/target.c b/agent/mibgroup/target/target.c
index e6aa07f..fad9a64 100644
--- a/agent/mibgroup/target/target.c
+++ b/agent/mibgroup/target/target.c
@@ -71,7 +71,7 @@ get_target_sessions(char *taglist, TargetFilterFunction * filterfunct,
(targaddrs->tDomain, targaddrs->tDomainLen, NULL, NULL) == 0) {
snmp_log(LOG_ERR,
"unsupported domain for target address table entry %s\n",
- targaddrs->name);
+ targaddrs->nameData);
}
/*
@@ -253,7 +253,7 @@ get_target_sessions(char *taglist, TargetFilterFunction * filterfunct,
snmp_log(LOG_ERR,
"unsupported mpModel/secModel combo %d/%d for target %s\n",
param->mpModel, param->secModel,
- targaddrs->name);
+ targaddrs->nameData);
/*
* XXX: memleak
*/
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders