On 11/18/2013 07:08 PM, Bart Van Assche wrote:
On 11/18/13 11:48, zhuyj wrote:
On 09/10/2013 01:41 PM, Bart Van Assche wrote:
On 09/10/13 04:04, zhuyj wrote:
Please help me to merge this patch into trunk. Thanks a lot.
Hello Zhu,
The code in snmpd_parse_config_targetAddr() and
store_snmpTargetAddrEntry() assumes that targetAddTable_struct.params
is an ASCII string that does *not* contain an ASCII '\0' nor any ASCII
control characters nor any whitespace. I'm afraid that your patch
would break the code for saving and restoring the target address.
If I fixed these problems with snmpd_parse_config_targetAddr() and
store_snmpTargetAddrEntry(). Would you like to merge these patches into
the trunk?
Sorry but I can't promise anything if I haven't seen the patch first.
Bart.
Hi, Bart
I made a patch based on net-snmp-5.7.2. Maybe it can fix the problem
that you mentioned. Would you like to comment on this patch?
This patch and the above 3 patches can support snmpTarget mib well.
Now the patch is in the attachment. Please check it.
If you have any advice , please let me know. I will follow your advice
to make this series patches better.
In the end, please merge this series patches to trunk to support zero
OID in snmpTarget mib.
Thanks a lot.
Zhu Yanjun
diff -urpN ./5.7.2/net-snmp-5.7.2/agent/mibgroup/target/snmpTargetAddrEntry.c ./net-snmp-5.7.2/agent/mibgroup/target/snmpTargetAddrEntry.c
--- ./5.7.2/net-snmp-5.7.2/agent/mibgroup/target/snmpTargetAddrEntry.c
+++ ./net-snmp-5.7.2/agent/mibgroup/target/snmpTargetAddrEntry.c
@@ -612,17 +612,33 @@ snmpTargetAddr_addRowStatus(struct targe
void
snmpd_parse_config_targetAddr(const char *token, char *char_ptr)
{
- char *cptr = char_ptr, buff[1024];
+ char *cptr = char_ptr, buff[1024], tmp[1024], temp[1024];
struct targetAddrTable_struct *newEntry;
int i, j, buff_len;
+ size_t bufl;
newEntry = snmpTargetAddrTable_create();
+ cptr = skip_white_const(cptr);
+ if (cptr == NULL) {
+ DEBUGMSGTL(("snmpTargetAddrEntry",
+ "ERROR snmpTargetAddrEntry: no name in config string\n"));
+ snmpTargetAddrTable_dispose(newEntry);
+ return;
+ }
- cptr = copy_nword(cptr, buff, sizeof(buff));
- if (snmpTargetAddr_addName(newEntry, buff) == 0) {
+ bufl = 0;
+ cptr = read_config_read_octet_string_const(cptr,
+ (u_char**)&newEntry->nameData,
+ &bufl);
+ if (bufl < 1 || bufl > 32) {
+ DEBUGMSGTL(("snmpTargetAddrEntry",
+ "ERROR snmpTargetAddrEntry: name out of range in config "
+ "string\n"));
snmpTargetAddrTable_dispose(newEntry);
return;
}
+ newEntry->nameLen = bufl;
+
cptr = copy_nword(cptr, buff, sizeof(buff));
if (snmpTargetAddr_addTDomain(newEntry, buff) == 0) {
snmpTargetAddrTable_dispose(newEntry);
@@ -653,11 +669,18 @@ snmpd_parse_config_targetAddr(const char
snmpTargetAddrTable_dispose(newEntry);
return;
}
- cptr = copy_nword(cptr, buff, sizeof(buff));
- if (snmpTargetAddr_addParams(newEntry, buff) == 0) {
+ 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(cptr, buff, sizeof(buff));
if (snmpTargetAddr_addStorageType(newEntry, buff) == 0) {
snmpTargetAddrTable_dispose(newEntry);
@@ -668,8 +691,8 @@ snmpd_parse_config_targetAddr(const char
snmpTargetAddrTable_dispose(newEntry);
return;
}
-// snprintf(buff, sizeof(buff), "snmp_parse_config_targetAddr, read: %s\n",
-// newEntry->nameData);
+ snprintf(buff, sizeof(buff), "snmp_parse_config_targetAddr, read: %s\n",
+ newEntry->nameData);
memset(buff, 0, sizeof(buff));
snprintf(buff, sizeof(buff), "snmp_parse_config_targetAddr, read: ");
buff_len = strlen(buff);
@@ -681,18 +704,19 @@ snmpd_parse_config_targetAddr(const char
buff[ sizeof(buff)-1 ] = 0;
for (i = 0; i < newEntry->tDomainLen; i++) {
-// snprintf(&buff[strlen(buff)], sizeof(buff)-strlen(buff)-1,
-// ".%d", (int) newEntry->tDomain[i]);
- char tmp[1024]={0};
- snprintf(tmp, sizeof(tmp), ".%d", (int) newEntry->tDomain[i]);
- strncpy(&buff[buff_len], tmp, strlen(tmp));
- buff_len += strlen(tmp);
+ snprintf(&buff[strlen(buff)], sizeof(buff)-strlen(buff)-1,
+ ".%d", (int) newEntry->tDomain[i]);
buff[ sizeof(buff)-1 ] = 0;
}
+
+ 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);
snprintf(&buff[buff_len], sizeof(buff)-buff_len-1,
" %s %d %d %s %s %d %d\n",
- newEntry->tAddress, newEntry->timeout, newEntry->retryCount,
- newEntry->tagList, newEntry->params, newEntry->storageType,
+ tmp, newEntry->timeout, newEntry->retryCount,
+ newEntry->tagList, temp, newEntry->storageType,
newEntry->rowStatus);
buff[ sizeof(buff)-1 ] = 0;
DEBUGMSGTL(("snmpTargetAddrEntry", "%s", buff));
@@ -716,8 +740,8 @@ store_snmpTargetAddrEntry(int majorID, i
void *clientarg)
{
struct targetAddrTable_struct *curr_struct;
- char line[1024];
- int i, j, line_len;
+ char line[1024], tmp[1024];
+ int i, line_len;
if ((curr_struct = aAddrTable) != NULL) {
while (curr_struct != NULL) {
@@ -726,36 +750,35 @@ store_snmpTargetAddrEntry(int majorID, i
&&
(curr_struct->rowStatus == SNMP_ROW_ACTIVE ||
curr_struct->rowStatus == SNMP_ROW_NOTINSERVICE)) {
-// snprintf(line, sizeof(line),
-// "targetAddr %s ", curr_struct->nameData);
- snprintf(line, sizeof(line),"targetAddr ");
- line_len = strlen(line);
- for (j=0; j<curr_struct->nameLen; j++){
- line[line_len+j] = curr_struct->nameData[j];
- }
- line_len += curr_struct->nameLen;
- line[line_len++] = 32;
+ memset(tmp, 0, sizeof(tmp));
+ read_config_save_octet_string(tmp,
+ (u_char*)curr_struct->nameData,
+ curr_struct->nameLen);
+
+ snprintf(line, sizeof(line),
+ "targetAddr %s ", tmp);
line[ sizeof(line)-1 ] = 0;
for (i = 0; i < curr_struct->tDomainLen; i++) {
- // snprintf(&line[line_len],
- // sizeof(line)-line_len-1, ".%i",
- // (int) curr_struct->tDomain[i]);
- char tmp[1024] = {0};
- snprintf(tmp, sizeof(tmp), ".%i", (int) curr_struct->tDomain[i]);
- strncpy(&line[line_len], tmp, strlen(tmp));
- line_len += strlen(tmp);
+ snprintf(&line[strlen(line)],
+ sizeof(line)-strlen(line)-1, ".%i",
+ (int) curr_struct->tDomain[i]);
line[ sizeof(line)-1 ] = 0;
}
strlcat(line, " ", sizeof(line));
- read_config_save_octet_string(&line[line_len],
+ read_config_save_octet_string(&line[strlen(line)],
curr_struct->tAddress,
curr_struct->tAddressLen);
- snprintf(&line[line_len], sizeof(line)-line_len-1,
+ memset(tmp, 0, sizeof(tmp));
+ read_config_save_octet_string(tmp,
+ (u_char*)curr_struct->params,
+ curr_struct->paramsLen);
+
+ snprintf(&line[strlen(line)], sizeof(line)-strlen(line)-1,
" %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;
------------------------------------------------------------------------------
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