summaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-extended/net-snmp/files/sync-with-5.7-branch.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-oe/recipes-extended/net-snmp/files/sync-with-5.7-branch.patch')
-rw-r--r--meta-oe/recipes-extended/net-snmp/files/sync-with-5.7-branch.patch19998
1 files changed, 0 insertions, 19998 deletions
diff --git a/meta-oe/recipes-extended/net-snmp/files/sync-with-5.7-branch.patch b/meta-oe/recipes-extended/net-snmp/files/sync-with-5.7-branch.patch
deleted file mode 100644
index 442e8d0cd..000000000
--- a/meta-oe/recipes-extended/net-snmp/files/sync-with-5.7-branch.patch
+++ /dev/null
@@ -1,19998 +0,0 @@
1Sync with 5.7 branch
2
3This syncs v5.7.1 to 2012-02-08 5.7 GIT branch status
4
5Upstream-Status: Backport
6
7diff --git a/.gitignore b/.gitignore
8index 9d6a15f..9cfb7a3 100644
9--- a/.gitignore
10+++ b/.gitignore
11@@ -1,9 +1,9 @@
12 *.bak
13 *.bs
14-*.la
15-*.lo
16 *.ft
17 *.ft.1
18+*.la
19+*.lo
20 *.made
21 *.o
22 *.obj
23@@ -78,7 +78,10 @@ net-snmp-config
24 net-snmp-config-x
25 net-snmp-create-v3-user
26 NEWS.new*
27+perl/*.yml
28 perl/*/*.def
29+perl/*/*.yml
30+perl/*/*/*.yml
31 perl/agent/agent.c
32 perl/agent/default_store/default_store.c
33 perl/agent/default_store/default_store.def
34@@ -96,6 +99,7 @@ perl/TrapReceiver/const-c.inc
35 perl/TrapReceiver/const-xs.inc
36 perl/TrapReceiver/TrapReceiver.c
37 pm_to_blib
38+python/build
39 sedscript
40 snmplib/snmpsm_init.h
41 snmplib/snmpsm_shutdown.h
42diff --git a/COPYING b/COPYING
43index afe6e6d..d368331 100644
44--- a/COPYING
45+++ b/COPYING
46@@ -135,7 +135,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47
48 ---- Part 5: Sparta, Inc copyright notice (BSD) -----
49
50-Copyright (c) 2003-2011, Sparta, Inc
51+Copyright (c) 2003-2012, Sparta, Inc
52 All rights reserved.
53
54 Redistribution and use in source and binary forms, with or without
55diff --git a/Makefile.in b/Makefile.in
56index f3dd7b7..9664676 100644
57--- a/Makefile.in
58+++ b/Makefile.in
59@@ -85,22 +85,23 @@ libtool: $(LIBTOOL_DEPS)
60 $(SHELL) ./config.status --recheck
61
62
63-snmplib:
64+snmplib: @FEATURETARGS@
65 @(cd snmplib; $(MAKE) )
66
67-agent:
68+agent: @FEATURETARGS@
69 @(cd snmplib; $(MAKE) )
70 @(cd agent; $(MAKE) )
71
72-apps:
73+apps: @FEATURETARGS@
74 @(cd snmplib; $(MAKE) )
75+ @(cd agent; $(MAKE) libs)
76 @(cd apps; $(MAKE) )
77
78-snmpget snmpbulkget snmpwalk snmpbulkwalk snmptranslate snmpstatus snmpdelta snmptable snmptest snmpset snmpusm snmpvacm snmpgetnext encode_keychange snmpdf snmptrap snmptls:
79+snmpget snmpbulkget snmpwalk snmpbulkwalk snmptranslate snmpstatus snmpdelta snmptable snmptest snmpset snmpusm snmpvacm snmpgetnext encode_keychange snmpdf snmptrap snmptls: @FEATURETARGS@
80 @(cd snmplib; $(MAKE) )
81 @(cd apps; $(MAKE) $@ )
82
83-snmptrapd:
84+agentxtrap snmptrapd: @FEATURETARGS@
85 @(cd snmplib; $(MAKE) )
86 @(cd agent; $(MAKE) libs)
87 @(cd apps; $(MAKE) $@ )
88diff --git a/agent/Makefile.in b/agent/Makefile.in
89index 84a5e4c..59cf4ef 100644
90--- a/agent/Makefile.in
91+++ b/agent/Makefile.in
92@@ -114,7 +114,6 @@ USELIBS = ../snmplib/libnetsnmp.$(LIB_EXTENSION)$(LIB_VERSION)
93 AGENTLIB = libnetsnmpagent.$(LIB_EXTENSION)$(LIB_VERSION)
94 MIBLIB = libnetsnmpmibs.$(LIB_EXTENSION)$(LIB_VERSION)
95
96-LOCAL_LIBS = -L../snmplib/.libs -L../snmplib -L./.libs
97 LAGENTLIBS = @LAGENTLIBS@
98 LMIBLIBS = @LMIBLIBS@
99 VAL_LIBS = @VAL_LIBS@
100@@ -282,34 +281,33 @@ all: agentlib subdirs miblib $(INSTALLBINPROGS) $(INSTALLSBINPROGS)
101 # build stuff targets
102 #
103 getkstat: getkstat.o
104- $(CC) $(CFLAGS) -o $@ $? $(LOCAL_LIBS) $(LIBS)
105+ $(CC) $(CFLAGS) -o $@ $? $(LIBS)
106
107 getkstat.o: mibgroup/kernel_sunos5.c
108 $(CC) $(CFLAGS) -o $@ -D_GETKSTAT_TEST -DDODEBUG -c $?
109
110 getmibstat: getmibstat.o
111- $(CC) $(CFLAGS) -o $@ $? $(LOCAL_LIBS) $(LIBS)
112+ $(CC) $(CFLAGS) -o $@ $? $(LIBS)
113
114 getmibstat.o: mibgroup/kernel_sunos5.c
115 $(CC) $(CFLAGS) -o $@ -D_GETMIBSTAT_TEST -DDODEBUG -c $?
116
117-snmpd$(EXEEXT): ${LAGENTOBJS} $(USELIBS) $(AGENTLIB) $(MIBLIB) $(LIBTARG)
118- $(LINK) $(CFLAGS) -o $@ ${LAGENTOBJS} $(LOCAL_LIBS) ${LDFLAGS} ${OUR_AGENT_LIBS}
119-
120+snmpd$(EXEEXT): ${LAGENTOBJS} $(USELIBS) $(AGENTLIB) $(HELPERLIB) $(MIBLIB) $(LIBTARG)
121+ $(LINK) $(CFLAGS) -o $@ ${LAGENTOBJS} ${LDFLAGS} ${OUR_AGENT_LIBS}
122
123 libnetsnmpagent.$(LIB_EXTENSION)$(LIB_VERSION): ${LLIBAGENTOBJS} $(USELIBS)
124 $(LIB_LD_CMD) $(AGENTLIB) ${LLIBAGENTOBJS} $(USELIBS) ${LAGENTLIBS} @LD_NO_UNDEFINED@ $(LDFLAGS) $(PERLLDOPTS_FOR_LIBS) $(LIB_LD_LIBS) @AGENTLIBS@
125 $(RANLIB) $(AGENTLIB)
126
127 libnetsnmpmibs.$(LIB_EXTENSION)$(LIB_VERSION): ${LMIBOBJS} $(AGENTLIB) $(USELIBS)
128- $(LIB_LD_CMD) $(MIBLIB) ${LMIBOBJS} $(AGENTLIB) $(USELIBS) @LD_NO_UNDEFINED@ $(LDFLAGS) ${LMIBLIBS} $(LIB_LD_LIBS) @AGENTLIBS@
129+ $(LIB_LD_CMD) $(MIBLIB) ${LMIBOBJS} $(AGENTLIB) $(USELIBS) @LD_NO_UNDEFINED@ $(LDFLAGS) ${LMIBLIBS} $(PERLLDOPTS_FOR_LIBS) $(LIB_LD_LIBS) @AGENTLIBS@
130 $(RANLIB) $(MIBLIB)
131
132 agentlib: $(AGENTLIB)
133
134 miblib: $(MIBLIB)
135
136-libs: $(INSTALLLIBS)
137+libs: $(AGENTLIB) $(MIBLIB)
138
139 embedperlinstall:
140 @$(SHELL) $(srcdir)/../mkinstalldirs $(INSTALL_PREFIX)$(snmplibdir)
141diff --git a/agent/agent_handler.c b/agent/agent_handler.c
142index da64761..59e9613 100644
143--- a/agent/agent_handler.c
144+++ b/agent/agent_handler.c
145@@ -774,7 +774,7 @@ netsnmp_handler_registration_free(netsnmp_handler_registration *reginfo)
146 /** Duplicates handler registration object and all subsequent handlers.
147 * Creates a copy of the handler registration object and all its data.
148 *
149- * @param handler is the handler registration object to be duplicated
150+ * @param reginfo is the handler registration object to be duplicated
151 *
152 * @return Returns a pointer to the complete copy,
153 * or NULL if any problem occured.
154@@ -922,7 +922,8 @@ netsnmp_free_delegated_cache(netsnmp_delegated_cache *dcache)
155 * Sweeps through given chain of requests and sets 'delegated'
156 * flag accordingly to the isdelegaded parameter.
157 *
158- * @param isdelegaded New value of the 'delegated' flag.
159+ * @param requests Request list.
160+ * @param isdelegated New value of the 'delegated' flag.
161 */
162 void
163 netsnmp_handler_mark_requests_as_delegated(netsnmp_request_info *requests,
164diff --git a/agent/agent_read_config.c b/agent/agent_read_config.c
165index 3514f0f..f9ef1af 100644
166--- a/agent/agent_read_config.c
167+++ b/agent/agent_read_config.c
168@@ -115,13 +115,10 @@ netsnmp_feature_child_of(snmpd_unregister_config_handler, agent_read_config_all)
169 void
170 snmpd_set_agent_user(const char *token, char *cptr)
171 {
172-#if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
173- struct passwd *info;
174-#endif
175-
176 if (cptr[0] == '#') {
177 char *ecp;
178 int uid;
179+
180 uid = strtoul(cptr + 1, &ecp, 10);
181 if (*ecp != 0) {
182 config_perror("Bad number");
183@@ -129,44 +126,47 @@ snmpd_set_agent_user(const char *token, char *cptr)
184 netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
185 NETSNMP_DS_AGENT_USERID, uid);
186 }
187- }
188 #if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
189- else if ((info = getpwnam(cptr)) != NULL) {
190- netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
191- NETSNMP_DS_AGENT_USERID, info->pw_uid);
192 } else {
193- config_perror("User not found in passwd database");
194- }
195- endpwent();
196+ struct passwd *info;
197+
198+ info = getpwnam(cptr);
199+ if (info)
200+ netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
201+ NETSNMP_DS_AGENT_USERID, info->pw_uid);
202+ else
203+ config_perror("User not found in passwd database");
204+ endpwent();
205 #endif
206+ }
207 }
208
209 void
210 snmpd_set_agent_group(const char *token, char *cptr)
211 {
212-#if defined(HAVE_GETGRNAM) && defined(HAVE_GRP_H)
213- struct group *info;
214-#endif
215-
216 if (cptr[0] == '#') {
217 char *ecp;
218 int gid = strtoul(cptr + 1, &ecp, 10);
219+
220 if (*ecp != 0) {
221 config_perror("Bad number");
222 } else {
223 netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
224 NETSNMP_DS_AGENT_GROUPID, gid);
225 }
226- }
227 #if defined(HAVE_GETGRNAM) && defined(HAVE_GRP_H)
228- else if ((info = getgrnam(cptr)) != NULL) {
229- netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
230- NETSNMP_DS_AGENT_GROUPID, info->gr_gid);
231 } else {
232- config_perror("Group not found in group database");
233- }
234- endpwent();
235+ struct group *info;
236+
237+ info = getgrnam(cptr);
238+ if (info)
239+ netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
240+ NETSNMP_DS_AGENT_GROUPID, info->gr_gid);
241+ else
242+ config_perror("Group not found in group database");
243+ endgrent();
244 #endif
245+ }
246 }
247 #endif
248
249@@ -187,9 +187,10 @@ snmpd_set_agent_address(const char *token, char *cptr)
250 /*
251 * append to the older specification string
252 */
253- snprintf(buf, SPRINT_MAX_LEN, "%s,%s", ptr, cptr);
254+ snprintf(buf, sizeof(buf), "%s,%s", ptr, cptr);
255+ buf[sizeof(buf) - 1] = '\0';
256 } else {
257- strncpy(buf, cptr, SPRINT_MAX_LEN);
258+ strlcpy(buf, cptr, sizeof(buf));
259 }
260
261 DEBUGMSGTL(("snmpd_ports", "port spec: %s\n", buf));
262diff --git a/agent/agent_registry.c b/agent/agent_registry.c
263index 5efaeb5..1e2482a 100644
264--- a/agent/agent_registry.c
265+++ b/agent/agent_registry.c
266@@ -555,6 +555,8 @@ netsnmp_subtree_change_prev(netsnmp_subtree *ptr, netsnmp_subtree *theprev)
267 &ptr->oid_off);
268 }
269
270+netsnmp_feature_child_of(netsnmp_subtree_compare,netsnmp_unused)
271+#ifndef NETSNMP_FEATURE_REMOVE_NETSNMP_SUBTREE_COMPARE
272 /** Compares OIDs of given subtrees.
273 *
274 * @param ap,bp Pointers to the subtrees to be compared.
275@@ -563,8 +565,6 @@ netsnmp_subtree_change_prev(netsnmp_subtree *ptr, netsnmp_subtree *theprev)
276 *
277 * @see snmp_oid_compare()
278 */
279-netsnmp_feature_child_of(netsnmp_subtree_compare,netsnmp_unused)
280-#ifndef NETSNMP_FEATURE_REMOVE_NETSNMP_SUBTREE_COMPARE
281 int
282 netsnmp_subtree_compare(const netsnmp_subtree *ap, const netsnmp_subtree *bp)
283 {
284@@ -742,7 +742,7 @@ netsnmp_subtree_split(netsnmp_subtree *current, oid name[], int name_len)
285
286 /** Loads the subtree under given context name.
287 *
288- * @param root The subtree to be loaded into current subtree.
289+ * @param new_sub The subtree to be loaded into current subtree.
290 *
291 * @param context_name Text name of the context we're searching for.
292 *
293@@ -1085,8 +1085,22 @@ netsnmp_subtree_find(const oid *name, size_t len, netsnmp_subtree *subtree,
294
295 /** Registers a MIB handler.
296 *
297+ * @param moduleName
298+ * @param var
299+ * @param varsize
300+ * @param numvars
301+ * @param mibloc
302+ * @param mibloclen
303+ * @param priority
304+ * @param range_subid
305+ * @param range_ubound
306+ * @param ss
307+ * @param context
308+ * @param timeout
309+ * @param flags
310 * @param reginfo Registration handler structure.
311 * In a case of failure, it will be freed.
312+ * @param perform_callback
313 *
314 * @return gives MIB_REGISTERED_OK or MIB_* error code.
315 *
316@@ -1389,6 +1403,7 @@ register_mib_detach(void)
317 * If range_subid is zero, then this parameter is ignored.
318 *
319 * @param ss
320+ * @param context
321 * @param timeout
322 * @param flags
323 *
324@@ -1584,6 +1599,7 @@ netsnmp_subtree_unload(netsnmp_subtree *sub, netsnmp_subtree *prev, const char *
325 DEBUGMSGOID(("register_mib", sub->start_a, sub->start_len));
326 } else {
327 DEBUGMSG(("register_mib", "[NIL]"));
328+ return;
329 }
330 DEBUGMSG(("register_mib", ", "));
331 if (prev != NULL) {
332@@ -1664,7 +1680,7 @@ unregister_mib_context(oid * name, size_t len, int priority,
333 int range_subid, oid range_ubound,
334 const char *context)
335 {
336- netsnmp_subtree *list, *myptr;
337+ netsnmp_subtree *list, *myptr = NULL;
338 netsnmp_subtree *prev, *child, *next; /* loop through children */
339 struct register_parameters reg_parms;
340 int old_lookup_cache_val = netsnmp_get_lookup_cache_size();
341diff --git a/agent/agent_trap.c b/agent/agent_trap.c
342index cc90620..dfa9dcf 100644
343--- a/agent/agent_trap.c
344+++ b/agent/agent_trap.c
345@@ -801,6 +801,7 @@ netsnmp_send_traps(int trap, int specific,
346
347 }
348
349+ if (template_v2pdu) {
350 /* A context name was provided, so copy it and its length to the v2 pdu
351 * template. */
352 if (context != NULL)
353@@ -808,6 +809,7 @@ netsnmp_send_traps(int trap, int specific,
354 template_v2pdu->contextName = strdup(context);
355 template_v2pdu->contextNameLen = strlen(context);
356 }
357+ }
358
359 /*
360 * Now loop through the list of trap sinks
361diff --git a/agent/auto_nlist.c b/agent/auto_nlist.c
362index cb92a5b..bcbdb05 100644
363--- a/agent/auto_nlist.c
364+++ b/agent/auto_nlist.c
365@@ -52,6 +52,9 @@ auto_nlist_value(const char *string)
366 }
367 }
368 if (*ptr == 0) {
369+#if !(defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7))
370+ static char *n_name = NULL;
371+#endif
372 *ptr = (struct autonlist *) malloc(sizeof(struct autonlist));
373 it = *ptr;
374 it->left = 0;
375@@ -66,15 +69,35 @@ auto_nlist_value(const char *string)
376 strcpy(it->nl[0].n_name, string);
377 it->nl[0].n_name[strlen(string)+1] = '\0';
378 #else
379- sprintf(it->nl[0].n_name, "_%s", string);
380+
381+ if (n_name != NULL)
382+ free(n_name);
383+
384+ n_name = malloc(strlen(string) + 2);
385+ if (n_name == NULL) {
386+ snmp_log(LOG_ERR, "nlist err: failed to allocate memory");
387+ return (-1);
388+ }
389+ snprintf(n_name, strlen(string) + 2, "_%s", string);
390+ it->nl[0].n_name = (const char*)n_name;
391 #endif
392 it->nl[1].n_name = 0;
393 init_nlist(it->nl);
394 #if !(defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7) || \
395- defined(netbsd1) || defined(dragonfly))
396+ defined(netbsd1) || defined(dragonfly))
397 if (it->nl[0].n_type == 0) {
398- strcpy(it->nl[0].n_name, string);
399- it->nl[0].n_name[strlen(string)+1] = '\0';
400+ static char *n_name2 = NULL;
401+
402+ if (n_name2 != NULL)
403+ free(n_name2);
404+
405+ n_name2 = malloc(strlen(string) + 1);
406+ if (n_name2 == NULL) {
407+ snmp_log(LOG_ERR, "nlist err: failed to allocate memory");
408+ return (-1);
409+ }
410+ strcpy(n_name2, string);
411+ it->nl[0].n_name = (const char*)n_name2;
412 init_nlist(it->nl);
413 }
414 #endif
415@@ -86,7 +109,8 @@ auto_nlist_value(const char *string)
416 }
417 return (-1);
418 } else {
419- DEBUGMSGTL(("auto_nlist:auto_nlist_value", "found symbol %s at %x.\n",
420+ DEBUGMSGTL(("auto_nlist:auto_nlist_value",
421+ "found symbol %s at %lx.\n",
422 it->symbol, it->nl[0].n_value));
423 return (it->nl[0].n_value);
424 }
425@@ -95,7 +119,7 @@ auto_nlist_value(const char *string)
426 }
427
428 int
429-auto_nlist(const char *string, char *var, int size)
430+auto_nlist(const char *string, char *var, size_t size)
431 {
432 long result;
433 int ret;
434@@ -192,7 +216,7 @@ init_nlist(struct nlist nl[])
435 }
436
437 int
438-KNLookup(struct nlist nl[], int nl_which, char *buf, int s)
439+KNLookup(struct nlist nl[], int nl_which, char *buf, size_t s)
440 {
441 struct nlist *nlp = &nl[nl_which];
442
443diff --git a/agent/helpers/all_helpers.c b/agent/helpers/all_helpers.c
444index 0f2b6a1..e1e1b78 100644
445--- a/agent/helpers/all_helpers.c
446+++ b/agent/helpers/all_helpers.c
447@@ -26,7 +26,7 @@ netsnmp_init_helpers(void)
448 netsnmp_init_bulk_to_next_helper();
449 #ifndef NETSNMP_FEATURE_REMOVE_TABLE_DATASET
450 netsnmp_init_table_dataset();
451-#endif
452+#endif /* NETSNMP_FEATURE_REMOVE_TABLE_DATASET */
453
454 #ifndef NETSNMP_FEATURE_REMOVE_ROW_MERGE
455 netsnmp_init_row_merge();
456diff --git a/agent/helpers/instance.c b/agent/helpers/instance.c
457index 2142909..a187d58 100644
458--- a/agent/helpers/instance.c
459+++ b/agent/helpers/instance.c
460@@ -536,6 +536,8 @@ netsnmp_register_num_file_instance(const char *name,
461 }
462 #endif /* NETSNMP_FEATURE_REMOVE_REGISTER_NUM_FILE_INSTANCE */
463
464+netsnmp_feature_child_of(register_int_instance,instance)
465+#ifndef NETSNMP_FEATURE_REMOVE_REGISTER_INT_INSTANCE
466 /**
467 * This function registers an int helper handler to a specified OID.
468 *
469@@ -554,8 +556,6 @@ netsnmp_register_num_file_instance(const char *name,
470 * MIB_REGISTERED_OK is returned if the registration was a success.
471 * Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION.
472 */
473-netsnmp_feature_child_of(register_int_instance,instance)
474-#ifndef NETSNMP_FEATURE_REMOVE_REGISTER_INT_INSTANCE
475 int
476 netsnmp_register_int_instance(const char *name,
477 const oid * reg_oid, size_t reg_oid_len,
478diff --git a/agent/helpers/old_api.c b/agent/helpers/old_api.c
479index b1630e6..4888cbc 100644
480--- a/agent/helpers/old_api.c
481+++ b/agent/helpers/old_api.c
482@@ -103,8 +103,12 @@ netsnmp_register_old_api(const char *moduleName,
483 reginfo->rootoid_len = (mibloclen + vp->namelen);
484 reginfo->rootoid =
485 (oid *) malloc(reginfo->rootoid_len * sizeof(oid));
486- if (reginfo->rootoid == NULL)
487+ if (reginfo->rootoid == NULL) {
488+ SNMP_FREE(vp);
489+ SNMP_FREE(reginfo->handlerName);
490+ SNMP_FREE(reginfo);
491 return SNMP_ERR_GENERR;
492+ }
493
494 memcpy(reginfo->rootoid, mibloc, mibloclen * sizeof(oid));
495 memcpy(reginfo->rootoid + mibloclen, vp->name, vp->namelen
496@@ -127,7 +131,7 @@ netsnmp_register_old_api(const char *moduleName,
497 */
498 if (netsnmp_register_handler(reginfo) != MIB_REGISTERED_OK) {
499 /** netsnmp_handler_registration_free(reginfo); already freed */
500- SNMP_FREE(vp);
501+ /* SNMP_FREE(vp); already freed */
502 }
503 }
504 return SNMPERR_SUCCESS;
505diff --git a/agent/helpers/snmp_get_statistic.c b/agent/helpers/snmp_get_statistic.c
506index 2e4fed8..efac2ac 100644
507--- a/agent/helpers/snmp_get_statistic.c
508+++ b/agent/helpers/snmp_get_statistic.c
509@@ -58,4 +58,4 @@ netsnmp_register_statistic_handler(netsnmp_handler_registration *reginfo,
510 }
511 #else /* !NETSNMP_FEATURE_REMOVE_HELPER_GET_STATISTICS */
512 netsnmp_feature_unused(helper_statistics);
513-#endif
514+#endif /* !NETSNMP_FEATURE_REMOVE_HELPER_GET_STATISTICS */
515diff --git a/agent/helpers/table_array.c b/agent/helpers/table_array.c
516index 49e0b24..7c98aae 100644
517--- a/agent/helpers/table_array.c
518+++ b/agent/helpers/table_array.c
519@@ -576,8 +576,11 @@ group_requests(netsnmp_agent_request_info *agtreq_info,
520 DEBUGMSG(("table_array:group", "\n"));
521 g = SNMP_MALLOC_TYPEDEF(netsnmp_request_group);
522 i = SNMP_MALLOC_TYPEDEF(netsnmp_request_group_item);
523- if (i == NULL || g == NULL)
524+ if (i == NULL || g == NULL) {
525+ SNMP_FREE(i);
526+ SNMP_FREE(g);
527 return;
528+ }
529 g->list = i;
530 g->table = tad->table;
531 i->ri = current;
532diff --git a/agent/helpers/table_dataset.c b/agent/helpers/table_dataset.c
533index 5160748..0949a8a 100644
534--- a/agent/helpers/table_dataset.c
535+++ b/agent/helpers/table_dataset.c
536@@ -467,7 +467,7 @@ netsnmp_register_table_data_set(netsnmp_handler_registration *reginfo,
537 netsnmp_get_table_data_set_handler(data_set));
538 ret = netsnmp_register_table_data(reginfo, data_set->table,
539 table_info);
540- if (reginfo->handler)
541+ if (ret == SNMPERR_SUCCESS && reginfo->handler)
542 netsnmp_handler_owns_table_info(reginfo->handler->next);
543 return ret;
544 }
545@@ -1105,9 +1105,11 @@ netsnmp_config_parse_table_set(const char *token, char *line)
546 switch (tp->access) {
547 case MIB_ACCESS_CREATE:
548 table_set->allow_creation = 1;
549+ /* fallthrough */
550 case MIB_ACCESS_READWRITE:
551 case MIB_ACCESS_WRITEONLY:
552 canwrite = 1;
553+ /* fallthrough */
554 case MIB_ACCESS_READONLY:
555 DEBUGMSGTL(("table_set_add_table",
556 "adding column %ld of type %d\n", tp->subid, type));
557diff --git a/agent/helpers/table_iterator.c b/agent/helpers/table_iterator.c
558index 64ef2cb..8ed5cd0 100644
559--- a/agent/helpers/table_iterator.c
560+++ b/agent/helpers/table_iterator.c
561@@ -648,6 +648,8 @@ netsnmp_table_iterator_helper_handler(netsnmp_mib_handler *handler,
562 */
563 if (free_this_index_search)
564 snmp_free_varbind(free_this_index_search);
565+ netsnmp_free_request_data_sets(reqtmp);
566+ SNMP_FREE(reqtmp);
567 return SNMP_ERR_GENERR;
568 }
569 coloid[reginfo->rootoid_len + 1] = table_info->colnum;
570@@ -681,6 +683,8 @@ netsnmp_table_iterator_helper_handler(netsnmp_mib_handler *handler,
571 if (free_this_index_search)
572 snmp_free_varbind
573 (free_this_index_search);
574+ netsnmp_free_request_data_sets(reqtmp);
575+ SNMP_FREE(reqtmp);
576 return SNMP_ERR_GENERR;
577 }
578 request_count--; /* One less to look for */
579diff --git a/agent/helpers/watcher.c b/agent/helpers/watcher.c
580index ee80736..9b3933b 100644
581--- a/agent/helpers/watcher.c
582+++ b/agent/helpers/watcher.c
583@@ -245,14 +245,11 @@ netsnmp_watcher_helper_handler(netsnmp_mib_handler *handler,
584 netsnmp_watcher_cache *old_data;
585
586 DEBUGMSGTL(("helper:watcher", "Got request: %d\n", reqinfo->mode));
587-
588 DEBUGMSGTL(( "helper:watcher", " oid:"));
589 DEBUGMSGOID(("helper:watcher", requests->requestvb->name,
590 requests->requestvb->name_length));
591 DEBUGMSG(( "helper:watcher", "\n"));
592
593-
594-
595 switch (reqinfo->mode) {
596 /*
597 * data requests
598@@ -392,14 +389,11 @@ netsnmp_watched_timestamp_handler(netsnmp_mib_handler *handler,
599
600 DEBUGMSGTL(("helper:watcher:timestamp",
601 "Got request: %d\n", reqinfo->mode));
602-
603 DEBUGMSGTL(( "helper:watcher:timestamp", " oid:"));
604 DEBUGMSGOID(("helper:watcher:timestamp", requests->requestvb->name,
605 requests->requestvb->name_length));
606 DEBUGMSG(( "helper:watcher:timestamp", "\n"));
607
608-
609-
610 switch (reqinfo->mode) {
611 /*
612 * data requests
613@@ -481,14 +475,11 @@ netsnmp_watched_spinlock_handler(netsnmp_mib_handler *handler,
614
615 DEBUGMSGTL(("helper:watcher:spinlock",
616 "Got request: %d\n", reqinfo->mode));
617-
618 DEBUGMSGTL(( "helper:watcher:spinlock", " oid:"));
619 DEBUGMSGOID(("helper:watcher:spinlock", requests->requestvb->name,
620 requests->requestvb->name_length));
621 DEBUGMSG(( "helper:watcher:spinlock", "\n"));
622
623-
624-
625 switch (reqinfo->mode) {
626 /*
627 * Ensure the assigned value matches the current one
628diff --git a/agent/mibgroup/Rmon/agutil.c b/agent/mibgroup/Rmon/agutil.c
629index d28bb67..12c6342 100644
630--- a/agent/mibgroup/Rmon/agutil.c
631+++ b/agent/mibgroup/Rmon/agutil.c
632@@ -200,12 +200,7 @@ AGUTIL_get_oid_value(u_char * var_val, u_char var_val_type,
633 u_long
634 AGUTIL_sys_up_time(void)
635 {
636- struct timeval current, delta;
637- const struct timeval* const starttime_ptr = netsnmp_get_agent_starttime();
638-
639- gettimeofday(&current, NULL);
640- NETSNMP_TIMERSUB(&current, starttime_ptr, &delta);
641- return delta.tv_sec * 100 + delta.tv_usec / 10000;
642+ return netsnmp_get_agent_runtime();
643 }
644
645 /*
646diff --git a/agent/mibgroup/Rmon/event.c b/agent/mibgroup/Rmon/event.c
647index 008ebaa..04a8555 100644
648--- a/agent/mibgroup/Rmon/event.c
649+++ b/agent/mibgroup/Rmon/event.c
650@@ -128,6 +128,7 @@ typedef struct {
651
652 static TABLE_DEFINTION_T EventCtrlTable;
653 static TABLE_DEFINTION_T *table_ptr = &EventCtrlTable;
654+static unsigned char zero_octet_string[1];
655
656 /*
657 * Control Table RowApi Callbacks
658@@ -262,7 +263,6 @@ write_eventControl(int action, u_char * var_val, u_char var_val_type,
659 static int prev_action = COMMIT;
660 RMON_ENTRY_T *hdr;
661 CRTL_ENTRY_T *cloned_body;
662- CRTL_ENTRY_T *body;
663
664 switch (action) {
665 case RESERVE1:
666@@ -283,7 +283,6 @@ write_eventControl(int action, u_char * var_val, u_char var_val_type,
667 leaf_id = (int) name[eventEntryFirstIndexBegin - 1];
668 hdr = ROWAPI_find(table_ptr, long_temp); /* it MUST be OK */
669 cloned_body = (CRTL_ENTRY_T *) hdr->tmp;
670- body = (CRTL_ENTRY_T *) hdr->body;
671 switch (leaf_id) {
672 case Leaf_event_description:
673 char_temp = AGMALLOC(1 + MAX_event_description);
674@@ -406,7 +405,7 @@ var_eventTable(struct variable *vp,
675 return (unsigned char *) theEntry.event_description;
676 } else {
677 *var_len = 0;
678- return NETSNMP_REMOVE_CONST(unsigned char *, "");
679+ return zero_octet_string;
680 }
681 case EVENTTYPE:
682 long_ret = theEntry.event_type;
683@@ -417,7 +416,7 @@ var_eventTable(struct variable *vp,
684 return (unsigned char *) theEntry.event_community;
685 } else {
686 *var_len = 0;
687- return NETSNMP_REMOVE_CONST(unsigned char *, "");
688+ return zero_octet_string;
689 }
690 case EVENTLASTTIMESENT:
691 long_ret = theEntry.event_last_time_sent;
692@@ -428,7 +427,7 @@ var_eventTable(struct variable *vp,
693 return (unsigned char *) hdr->owner;
694 } else {
695 *var_len = 0;
696- return NETSNMP_REMOVE_CONST(unsigned char *, "");
697+ return zero_octet_string;
698 }
699 case EVENTSTATUS:
700 long_ret = hdr->status;
701@@ -457,7 +456,6 @@ var_logTable(struct variable *vp,
702 static long long_ret;
703 static DATA_ENTRY_T theEntry;
704 RMON_ENTRY_T *hdr;
705- CRTL_ENTRY_T *ctrl;
706
707 *write_method = NULL;
708 hdr = ROWDATAAPI_header_DataEntry(vp, name, length, exact, var_len,
709@@ -467,8 +465,6 @@ var_logTable(struct variable *vp,
710 if (!hdr)
711 return NULL;
712
713- ctrl = (CRTL_ENTRY_T *) hdr->body;
714-
715 *var_len = sizeof(long); /* default */
716
717 switch (vp->magic) {
718@@ -487,7 +483,7 @@ var_logTable(struct variable *vp,
719 return (unsigned char *) theEntry.log_description;
720 } else {
721 *var_len = 0;
722- return NETSNMP_REMOVE_CONST(unsigned char *, "");
723+ return zero_octet_string;
724 }
725 default:
726 ERROR_MSG("");
727diff --git a/agent/mibgroup/Rmon/history.c b/agent/mibgroup/Rmon/history.c
728index b962567..c8e9c25 100644
729--- a/agent/mibgroup/Rmon/history.c
730+++ b/agent/mibgroup/Rmon/history.c
731@@ -181,7 +181,7 @@ write_historyControl(int action, u_char * var_val, u_char var_val_type,
732 var_val_len,
733 MIN_historyControlBucketsRequested,
734 MAX_historyControlBucketsRequested,
735- &cloned_body->scrlr.
736+ (long *) &cloned_body->scrlr.
737 data_requested);
738 if (SNMP_ERR_NOERROR != snmp_status) {
739 return snmp_status;
740@@ -198,7 +198,7 @@ write_historyControl(int action, u_char * var_val, u_char var_val_type,
741 var_val_len,
742 MIN_historyControlInterval,
743 MAX_historyControlInterval,
744- &cloned_body->interval);
745+ (long *) &cloned_body->interval);
746 if (SNMP_ERR_NOERROR != snmp_status) {
747 return snmp_status;
748 }
749@@ -257,6 +257,7 @@ var_historyControlTable(struct variable *vp,
750 int exact,
751 size_t * var_len, WriteMethod ** write_method)
752 {
753+ static unsigned char zero_octet_string[1];
754 static long long_ret;
755 static CRTL_ENTRY_T theEntry;
756 RMON_ENTRY_T *hdr;
757@@ -298,7 +299,7 @@ var_historyControlTable(struct variable *vp,
758 return (unsigned char *) hdr->owner;
759 } else {
760 *var_len = 0;
761- return NETSNMP_REMOVE_CONST(unsigned char *, "");
762+ return zero_octet_string;
763 }
764
765 case CTRL_STATUS:
766@@ -530,7 +531,6 @@ var_etherHistoryTable(struct variable *vp,
767 static long long_ret;
768 static DATA_ENTRY_T theBucket;
769 RMON_ENTRY_T *hdr;
770- CRTL_ENTRY_T *ctrl;
771
772 *write_method = NULL;
773 hdr = ROWDATAAPI_header_DataEntry(vp, name, length, exact, var_len,
774@@ -542,8 +542,6 @@ var_etherHistoryTable(struct variable *vp,
775
776 *var_len = sizeof(long); /* default */
777
778- ctrl = (CRTL_ENTRY_T *) hdr->body;
779-
780 switch (vp->magic) {
781 case DATA_INDEX:
782 long_ret = hdr->ctrl_index;
783diff --git a/agent/mibgroup/Rmon/row_api.h b/agent/mibgroup/Rmon/row_api.h
784index 2fb5a88..9f576be 100644
785--- a/agent/mibgroup/Rmon/row_api.h
786+++ b/agent/mibgroup/Rmon/row_api.h
787@@ -62,7 +62,7 @@ typedef struct tagEntry {
788 typedef int (ENTRY_CALLBACK_T) (RMON_ENTRY_T *);
789
790 typedef struct {
791- char *name;
792+ const char *name;
793 RMON_ENTRY_T *first;
794 u_long max_number_of_entries; /* '<0' means without limit */
795 u_long current_number_of_entries;
796diff --git a/agent/mibgroup/Rmon/statistics.c b/agent/mibgroup/Rmon/statistics.c
797index 51f25ee..3ed4acb 100644
798--- a/agent/mibgroup/Rmon/statistics.c
799+++ b/agent/mibgroup/Rmon/statistics.c
800@@ -317,6 +317,7 @@ var_etherStatsEntry(struct variable * vp, oid * name, size_t * length,
801 int exact, size_t * var_len,
802 WriteMethod ** write_method)
803 {
804+ static unsigned char zero_octet_string[1];
805 static long long_return;
806 static CRTL_ENTRY_T theEntry;
807 RMON_ENTRY_T *hdr;
808@@ -397,7 +398,7 @@ var_etherStatsEntry(struct variable * vp, oid * name, size_t * length,
809 return (unsigned char *) hdr->owner;
810 } else {
811 *var_len = 0;
812- return NETSNMP_REMOVE_CONST(unsigned char *, "");
813+ return zero_octet_string;
814 }
815 case IDetherStatsStatus:
816 long_return = hdr->status;
817diff --git a/agent/mibgroup/agent/extend.c b/agent/mibgroup/agent/extend.c
818index ddef4fb..8268559 100644
819--- a/agent/mibgroup/agent/extend.c
820+++ b/agent/mibgroup/agent/extend.c
821@@ -120,7 +120,8 @@ _register_extend( oid *base, size_t len )
822 netsnmp_table_data *dinfo;
823 netsnmp_table_registration_info *tinfo;
824 netsnmp_watcher_info *winfo;
825- netsnmp_handler_registration *reg;
826+ netsnmp_handler_registration *reg = NULL;
827+ int rc;
828
829 for ( eptr=ereg_head; eptr; eptr=eptr->next ) {
830 if (!snmp_oid_compare( base, len, eptr->root_oid, eptr->oid_len))
831@@ -128,6 +129,8 @@ _register_extend( oid *base, size_t len )
832 }
833 if (!eptr) {
834 eptr = SNMP_MALLOC_TYPEDEF( extend_registration_block );
835+ if (!eptr)
836+ return NULL;
837 eptr->root_oid = snmp_duplicate_objid( base, len );
838 eptr->oid_len = len;
839 eptr->num_entries = 0;
840@@ -157,7 +160,10 @@ _register_extend( oid *base, size_t len )
841 "nsExtendConfigTable", handle_nsExtendConfigTable,
842 oid_buf, len+1, HANDLER_CAN_RONLY);
843 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
844- netsnmp_register_table_data( reg, dinfo, tinfo );
845+ rc = netsnmp_register_table_data( reg, dinfo, tinfo );
846+ if (rc != SNMPERR_SUCCESS) {
847+ goto bail;
848+ }
849 netsnmp_handler_owns_table_info(reg->handler->next);
850 eptr->reg[0] = reg;
851
852@@ -175,7 +181,9 @@ _register_extend( oid *base, size_t len )
853 reg = netsnmp_create_handler_registration(
854 "nsExtendOut1Table", handle_nsExtendOutput1Table,
855 oid_buf, len+1, HANDLER_CAN_RONLY);
856- netsnmp_register_table_data( reg, dinfo, tinfo );
857+ rc = netsnmp_register_table_data( reg, dinfo, tinfo );
858+ if (rc != SNMPERR_SUCCESS)
859+ goto bail;
860 netsnmp_handler_owns_table_info(reg->handler->next);
861 eptr->reg[1] = reg;
862
863@@ -195,7 +203,9 @@ _register_extend( oid *base, size_t len )
864 reg = netsnmp_create_handler_registration(
865 "nsExtendOut2Table", handle_nsExtendOutput2Table,
866 oid_buf, len+1, HANDLER_CAN_RONLY);
867- netsnmp_register_table( reg, tinfo );
868+ rc = netsnmp_register_table( reg, tinfo );
869+ if (rc != SNMPERR_SUCCESS)
870+ goto bail;
871 netsnmp_handler_owns_table_info(reg->handler->next);
872 eptr->reg[2] = reg;
873
874@@ -209,9 +219,20 @@ _register_extend( oid *base, size_t len )
875 winfo = netsnmp_create_watcher_info(
876 &(eptr->num_entries), sizeof(eptr->num_entries),
877 ASN_INTEGER, WATCHER_FIXED_SIZE);
878- netsnmp_register_watched_scalar2( reg, winfo );
879+ rc = netsnmp_register_watched_scalar2( reg, winfo );
880+ if (rc != SNMPERR_SUCCESS)
881+ goto bail;
882
883 return eptr;
884+
885+bail:
886+ if (eptr->reg[2])
887+ netsnmp_unregister_handler(eptr->reg[2]);
888+ if (eptr->reg[1])
889+ netsnmp_unregister_handler(eptr->reg[1]);
890+ if (eptr->reg[0])
891+ netsnmp_unregister_handler(eptr->reg[0]);
892+ return NULL;
893 }
894
895 static void
896@@ -406,9 +427,9 @@ _free_extension( netsnmp_extend *extension, extend_registration_block *ereg )
897 eprev->next = eptr->next;
898 else
899 ereg->ehead = eptr->next;
900+ netsnmp_table_data_remove_and_delete_row( ereg->dinfo, extension->row);
901 }
902
903- netsnmp_table_data_remove_and_delete_row( ereg->dinfo, extension->row);
904 SNMP_FREE( extension->token );
905 SNMP_FREE( extension->cache );
906 SNMP_FREE( extension->command );
907diff --git a/agent/mibgroup/agent/nsDebug.c b/agent/mibgroup/agent/nsDebug.c
908index 0a629cc..89a90b0 100644
909--- a/agent/mibgroup/agent/nsDebug.c
910+++ b/agent/mibgroup/agent/nsDebug.c
911@@ -423,8 +423,9 @@ handle_nsDebugTable(netsnmp_mib_handler *handler,
912 */
913 debug_entry = (netsnmp_token_descr*)
914 netsnmp_extract_iterator_context(request);
915- debug_entry->enabled =
916- (*request->requestvb->val.integer == RS_ACTIVE);
917+ if (debug_entry)
918+ debug_entry->enabled =
919+ (*request->requestvb->val.integer == RS_ACTIVE);
920 break;
921
922 case RS_CREATEANDWAIT:
923diff --git a/agent/mibgroup/agent/nsLogging.c b/agent/mibgroup/agent/nsLogging.c
924index c06a18a..7f20bdb 100644
925--- a/agent/mibgroup/agent/nsLogging.c
926+++ b/agent/mibgroup/agent/nsLogging.c
927@@ -363,7 +363,7 @@ handle_nsLoggingTable(netsnmp_mib_handler *handler,
928 switch ( *request->requestvb->val.integer ) {
929 case RS_ACTIVE:
930 case RS_CREATEANDGO:
931- if ( !logh->type ) {
932+ if ( !logh || !logh->type ) {
933 netsnmp_set_request_error(reqinfo, request,
934 SNMP_ERR_INCONSISTENTVALUE);
935 return SNMP_ERR_INCONSISTENTVALUE;
936diff --git a/agent/mibgroup/agent/nsVacmAccessTable.c b/agent/mibgroup/agent/nsVacmAccessTable.c
937index 22d2154..79fa97d 100644
938--- a/agent/mibgroup/agent/nsVacmAccessTable.c
939+++ b/agent/mibgroup/agent/nsVacmAccessTable.c
940@@ -174,11 +174,11 @@ nsVacmAccessTable_handler(netsnmp_mib_handler *handler,
941 /* Extract the authType token from the list of indexes */
942 idx = table_info->indexes->next_variable->next_variable->next_variable->next_variable;
943 memset(atype, 0, sizeof(atype));
944- strncpy(atype, (char *)idx->val.string, idx->val_len);
945+ memcpy(atype, (char *)idx->val.string, idx->val_len);
946 viewIdx = se_find_value_in_slist(VACM_VIEW_ENUM_NAME, atype);
947 DEBUGMSGTL(("nsVacm", "GET %s (%d)\n", idx->val.string, viewIdx));
948
949- if (!entry)
950+ if (!entry || viewIdx < 0)
951 continue;
952
953 switch (table_info->colnum) {
954@@ -248,7 +248,7 @@ nsVacmAccessTable_handler(netsnmp_mib_handler *handler,
955 */
956 idx = table_info->indexes->next_variable->next_variable->next_variable->next_variable;
957 memset(atype, 0, sizeof(atype));
958- strncpy(atype, (char *)idx->val.string, idx->val_len);
959+ memcpy(atype, (char *)idx->val.string, idx->val_len);
960 viewIdx = se_find_value_in_slist(VACM_VIEW_ENUM_NAME, atype);
961 if ( viewIdx < 0 ) {
962 ret = SNMP_ERR_NOCREATION;
963@@ -322,8 +322,10 @@ nsVacmAccessTable_handler(netsnmp_mib_handler *handler,
964 /* Extract the authType token from the list of indexes */
965 idx = table_info->indexes->next_variable->next_variable->next_variable->next_variable;
966 memset(atype, 0, sizeof(atype));
967- strncpy(atype, (char *)idx->val.string, idx->val_len);
968+ memcpy(atype, (char *)idx->val.string, idx->val_len);
969 viewIdx = se_find_value_in_slist(VACM_VIEW_ENUM_NAME, atype);
970+ if (viewIdx < 0)
971+ continue;
972
973 switch (table_info->colnum) {
974 case COLUMN_NSVACMCONTEXTMATCH:
975diff --git a/agent/mibgroup/agentx/agentx_config.c b/agent/mibgroup/agentx/agentx_config.c
976index b590c7a..ea453c2 100644
977--- a/agent/mibgroup/agentx/agentx_config.c
978+++ b/agent/mibgroup/agentx/agentx_config.c
979@@ -180,10 +180,8 @@ agentx_config_init(void)
980 */
981 netsnmp_register_default_domain("agentx", "unix tcp");
982 netsnmp_register_default_target("agentx", "unix", NETSNMP_AGENTX_SOCKET);
983-#define val(x) __STRING(x)
984 netsnmp_register_default_target("agentx", "tcp",
985- "localhost:" val(AGENTX_PORT));
986-#undef val
987+ "localhost:" __STRING(AGENTX_PORT));
988 agentx_register_config_handler("agentxsocket",
989 agentx_parse_agentx_socket, NULL,
990 "AgentX bind address");
991diff --git a/agent/mibgroup/agentx/master_admin.c b/agent/mibgroup/agentx/master_admin.c
992index 3f4b33d..f16f392 100644
993--- a/agent/mibgroup/agentx/master_admin.c
994+++ b/agent/mibgroup/agentx/master_admin.c
995@@ -64,7 +64,6 @@ int
996 open_agentx_session(netsnmp_session * session, netsnmp_pdu *pdu)
997 {
998 netsnmp_session *sp;
999- struct timeval now;
1000
1001 DEBUGMSGTL(("agentx/master", "open %8p\n", session));
1002 sp = (netsnmp_session *) malloc(sizeof(netsnmp_session));
1003@@ -104,8 +103,7 @@ open_agentx_session(netsnmp_session * session, netsnmp_pdu *pdu)
1004 name_length);
1005 sp->securityAuthProtoLen = pdu->variables->name_length;
1006 sp->securityName = strdup((char *) pdu->variables->val.string);
1007- gettimeofday(&now, NULL);
1008- sp->engineTime = calculate_sectime_diff(&now, netsnmp_get_agent_starttime());
1009+ sp->engineTime = (netsnmp_get_agent_runtime() + 50) / 100;
1010
1011 sp->subsession = session; /* link back to head */
1012 sp->flags |= SNMP_FLAGS_SUBSESSION;
1013diff --git a/agent/mibgroup/agentx/protocol.c b/agent/mibgroup/agentx/protocol.c
1014index 09c149f..6e3daf3 100644
1015--- a/agent/mibgroup/agentx/protocol.c
1016+++ b/agent/mibgroup/agentx/protocol.c
1017@@ -453,6 +453,7 @@ agentx_realloc_build_varbind(u_char ** buf, size_t * buf_len,
1018 case ASN_COUNTER:
1019 case ASN_GAUGE:
1020 case ASN_TIMETICKS:
1021+ case ASN_UINTEGER:
1022 if (!agentx_realloc_build_int(buf, buf_len, out_len, allow_realloc,
1023 *(vp->val.integer), network_order)) {
1024 DEBUGINDENTLESS();
1025@@ -1372,6 +1373,7 @@ agentx_parse_varbind(u_char * data, size_t * length, int *type,
1026 case ASN_COUNTER:
1027 case ASN_GAUGE:
1028 case ASN_TIMETICKS:
1029+ case ASN_UINTEGER:
1030 int_val = agentx_parse_int(bufp, network_byte_order);
1031 memmove(data_buf, &int_val, 4);
1032 *data_len = 4;
1033@@ -1429,6 +1431,7 @@ agentx_parse_varbind(u_char * data, size_t * length, int *type,
1034 break;
1035
1036 default:
1037+ DEBUGMSG(("recv", "Can not parse type %x", *type));
1038 DEBUGINDENTLESS();
1039 return NULL;
1040 }
1041diff --git a/agent/mibgroup/agentx/subagent.c b/agent/mibgroup/agentx/subagent.c
1042index 5d51834..76b1acf 100644
1043--- a/agent/mibgroup/agentx/subagent.c
1044+++ b/agent/mibgroup/agentx/subagent.c
1045@@ -243,6 +243,24 @@ free_set_vars(netsnmp_session * ss, netsnmp_pdu *pdu)
1046 }
1047 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
1048
1049+static void
1050+send_agentx_error(netsnmp_session *session, netsnmp_pdu *pdu, int errstat, int errindex)
1051+{
1052+ pdu = snmp_clone_pdu(pdu);
1053+ pdu->command = AGENTX_MSG_RESPONSE;
1054+ pdu->version = session->version;
1055+ pdu->errstat = errstat;
1056+ pdu->errindex = errindex;
1057+ snmp_free_varbind(pdu->variables);
1058+ pdu->variables = NULL;
1059+
1060+ DEBUGMSGTL(("agentx/subagent", "Sending AgentX response error stat %d idx %d\n",
1061+ errstat, errindex));
1062+ if (!snmp_send(session, pdu)) {
1063+ snmp_free_pdu(pdu);
1064+ }
1065+}
1066+
1067 int
1068 handle_agentx_packet(int operation, netsnmp_session * session, int reqid,
1069 netsnmp_pdu *pdu, void *magic)
1070@@ -298,8 +316,10 @@ handle_agentx_packet(int operation, netsnmp_session * session, int reqid,
1071 * agentx_reopen_session unregisters itself if it succeeds in talking
1072 * to the master agent.
1073 */
1074- snmp_alarm_register(period, SA_REPEAT, agentx_reopen_session,
1075- NULL);
1076+ snmp_alarm_register(period, SA_REPEAT, agentx_reopen_session, NULL);
1077+ snmp_log(LOG_INFO, "AgentX master disconnected us, reconnecting in %d\n", period);
1078+ } else {
1079+ snmp_log(LOG_INFO, "AgentX master disconnected us, not reconnecting\n");
1080 }
1081 return 0;
1082 } else if (operation != NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE) {
1083@@ -325,6 +345,7 @@ handle_agentx_packet(int operation, netsnmp_session * session, int reqid,
1084 (ns_subagent_magic *) calloc(1, sizeof(ns_subagent_magic));
1085 if (smagic == NULL) {
1086 DEBUGMSGTL(("agentx/subagent", "couldn't malloc() smagic\n"));
1087+ /* would like to send_agentx_error(), but it needs memory too */
1088 return 1;
1089 }
1090 smagic->original_command = pdu->command;
1091@@ -389,6 +410,7 @@ handle_agentx_packet(int operation, netsnmp_session * session, int reqid,
1092 if (asi == NULL) {
1093 SNMP_FREE(smagic);
1094 snmp_log(LOG_WARNING, "save_set_vars() failed\n");
1095+ send_agentx_error(session, pdu, AGENTX_ERR_PARSE_FAILED, 0);
1096 return 1;
1097 }
1098 asi->mode = pdu->command = SNMP_MSG_INTERNAL_SET_RESERVE1;
1099@@ -402,6 +424,7 @@ handle_agentx_packet(int operation, netsnmp_session * session, int reqid,
1100 if (asi == NULL) {
1101 SNMP_FREE(smagic);
1102 snmp_log(LOG_WARNING, "restore_set_vars() failed\n");
1103+ send_agentx_error(session, pdu, AGENTX_ERR_PROCESSING_ERROR, 0);
1104 return 1;
1105 }
1106 if (asi->mode != SNMP_MSG_INTERNAL_SET_RESERVE2) {
1107@@ -409,6 +432,7 @@ handle_agentx_packet(int operation, netsnmp_session * session, int reqid,
1108 snmp_log(LOG_WARNING,
1109 "dropping bad AgentX request (wrong mode %d)\n",
1110 asi->mode);
1111+ send_agentx_error(session, pdu, AGENTX_ERR_PROCESSING_ERROR, 0);
1112 return 1;
1113 }
1114 asi->mode = pdu->command = SNMP_MSG_INTERNAL_SET_ACTION;
1115@@ -422,6 +446,7 @@ handle_agentx_packet(int operation, netsnmp_session * session, int reqid,
1116 if (asi == NULL) {
1117 SNMP_FREE(smagic);
1118 snmp_log(LOG_WARNING, "restore_set_vars() failed\n");
1119+ send_agentx_error(session, pdu, AGENTX_ERR_PROCESSING_ERROR, 0);
1120 return 1;
1121 }
1122 if (asi->mode == SNMP_MSG_INTERNAL_SET_RESERVE1 ||
1123@@ -446,6 +471,7 @@ handle_agentx_packet(int operation, netsnmp_session * session, int reqid,
1124 if (asi == NULL) {
1125 SNMP_FREE(smagic);
1126 snmp_log(LOG_WARNING, "restore_set_vars() failed\n");
1127+ send_agentx_error(session, pdu, AGENTX_ERR_PROCESSING_ERROR, 0);
1128 return 1;
1129 }
1130 asi->mode = pdu->command = SNMP_MSG_INTERNAL_SET_UNDO;
1131@@ -484,6 +510,26 @@ handle_agentx_packet(int operation, netsnmp_session * session, int reqid,
1132 return 1;
1133 }
1134
1135+static int
1136+_invalid_op_and_magic(int op, ns_subagent_magic *smagic)
1137+{
1138+ int invalid = 0;
1139+
1140+ if (smagic && (snmp_sess_pointer(smagic->session) == NULL ||
1141+ op == NETSNMP_CALLBACK_OP_TIMED_OUT)) {
1142+ if (smagic->ovars != NULL) {
1143+ snmp_free_varbind(smagic->ovars);
1144+ }
1145+ free(smagic);
1146+ invalid = 1;
1147+ }
1148+
1149+ if (op != NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE || smagic == NULL)
1150+ invalid = 1;
1151+
1152+ return invalid;
1153+}
1154+
1155 int
1156 handle_subagent_response(int op, netsnmp_session * session, int reqid,
1157 netsnmp_pdu *pdu, void *magic)
1158@@ -492,13 +538,7 @@ handle_subagent_response(int op, netsnmp_session * session, int reqid,
1159 netsnmp_variable_list *u = NULL, *v = NULL;
1160 int rc = 0;
1161
1162- if (op != NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE || magic == NULL) {
1163- if (op == NETSNMP_CALLBACK_OP_TIMED_OUT && magic != NULL) {
1164- if (smagic->ovars != NULL) {
1165- snmp_free_varbind(smagic->ovars);
1166- }
1167- free(smagic);
1168- }
1169+ if (_invalid_op_and_magic(op, magic)) {
1170 return 1;
1171 }
1172
1173@@ -778,6 +818,7 @@ subagent_open_master_session(void)
1174 {
1175 netsnmp_transport *t;
1176 netsnmp_session sess;
1177+ const char *agentx_socket;
1178
1179 DEBUGMSGTL(("agentx/subagent", "opening session...\n"));
1180
1181@@ -795,9 +836,9 @@ subagent_open_master_session(void)
1182 sess.callback = handle_agentx_packet;
1183 sess.authenticator = NULL;
1184
1185- t = netsnmp_transport_open_client(
1186- "agentx", netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID,
1187- NETSNMP_DS_AGENT_X_SOCKET));
1188+ agentx_socket = netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID,
1189+ NETSNMP_DS_AGENT_X_SOCKET);
1190+ t = netsnmp_transport_open_client("agentx", agentx_socket);
1191 if (t == NULL) {
1192 /*
1193 * Diagnose snmp_open errors with the input
1194@@ -806,12 +847,9 @@ subagent_open_master_session(void)
1195 if (!netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
1196 NETSNMP_DS_AGENT_NO_CONNECTION_WARNINGS)) {
1197 char buf[1024];
1198- const char *socket =
1199- netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID,
1200- NETSNMP_DS_AGENT_X_SOCKET);
1201 snprintf(buf, sizeof(buf), "Warning: "
1202 "Failed to connect to the agentx master agent (%s)",
1203- socket ? socket : "[NIL]");
1204+ agentx_socket ? agentx_socket : "[NIL]");
1205 if (!netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
1206 NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) {
1207 netsnmp_sess_log_error(LOG_WARNING, buf, &sess);
1208@@ -832,8 +870,7 @@ subagent_open_master_session(void)
1209 char buf[1024];
1210 snprintf(buf, sizeof(buf), "Error: "
1211 "Failed to create the agentx master agent session (%s)",
1212- netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID,
1213- NETSNMP_DS_AGENT_X_SOCKET));
1214+ agentx_socket);
1215 snmp_sess_perror(buf, &sess);
1216 }
1217 netsnmp_transport_free(t);
1218diff --git a/agent/mibgroup/disman/event/mteEventConf.c b/agent/mibgroup/disman/event/mteEventConf.c
1219index 949d6e5..24192a6 100644
1220--- a/agent/mibgroup/disman/event/mteEventConf.c
1221+++ b/agent/mibgroup/disman/event/mteEventConf.c
1222@@ -296,6 +296,11 @@ parse_setEvent( const char *token, char *line )
1223 if (cp && *cp == '=') {
1224 cp = skip_token( cp ); /* skip the '=' assignment character */
1225 }
1226+ if (!cp) {
1227+ config_perror("syntax error: missing set value");
1228+ return;
1229+ }
1230+
1231 value = strtol( cp, NULL, 0);
1232
1233 /*
1234diff --git a/agent/mibgroup/disman/event/mteEventNotificationTable.c b/agent/mibgroup/disman/event/mteEventNotificationTable.c
1235index 9095f0e..7d2c94a 100644
1236--- a/agent/mibgroup/disman/event/mteEventNotificationTable.c
1237+++ b/agent/mibgroup/disman/event/mteEventNotificationTable.c
1238@@ -98,6 +98,9 @@ mteEventNotificationTable_handler(netsnmp_mib_handler *handler,
1239 */
1240 case MODE_GET:
1241 for (request = requests; request; request = request->next) {
1242+ if (request->processed)
1243+ continue;
1244+
1245 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
1246 tinfo = netsnmp_extract_table_info(request);
1247
1248@@ -136,6 +139,9 @@ mteEventNotificationTable_handler(netsnmp_mib_handler *handler,
1249 */
1250 case MODE_SET_RESERVE1:
1251 for (request = requests; request; request = request->next) {
1252+ if (request->processed)
1253+ continue;
1254+
1255 tinfo = netsnmp_extract_table_info(request);
1256
1257 /*
1258@@ -204,6 +210,9 @@ mteEventNotificationTable_handler(netsnmp_mib_handler *handler,
1259
1260 case MODE_SET_ACTION:
1261 for (request = requests; request; request = request->next) {
1262+ if (request->processed)
1263+ continue;
1264+
1265 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
1266 if (!entry) {
1267 /*
1268@@ -225,6 +234,9 @@ mteEventNotificationTable_handler(netsnmp_mib_handler *handler,
1269 * (reasonably) safe to apply them in the Commit phase
1270 */
1271 for (request = requests; request; request = request->next) {
1272+ if (request->processed)
1273+ continue;
1274+
1275 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
1276 tinfo = netsnmp_extract_table_info(request);
1277
1278diff --git a/agent/mibgroup/disman/event/mteEventSetTable.c b/agent/mibgroup/disman/event/mteEventSetTable.c
1279index 67a8170..ee696f1 100644
1280--- a/agent/mibgroup/disman/event/mteEventSetTable.c
1281+++ b/agent/mibgroup/disman/event/mteEventSetTable.c
1282@@ -100,6 +100,9 @@ mteEventSetTable_handler(netsnmp_mib_handler *handler,
1283 */
1284 case MODE_GET:
1285 for (request = requests; request; request = request->next) {
1286+ if (request->processed)
1287+ continue;
1288+
1289 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
1290 tinfo = netsnmp_extract_table_info(request);
1291
1292@@ -151,6 +154,9 @@ mteEventSetTable_handler(netsnmp_mib_handler *handler,
1293 */
1294 case MODE_SET_RESERVE1:
1295 for (request = requests; request; request = request->next) {
1296+ if (request->processed)
1297+ continue;
1298+
1299 tinfo = netsnmp_extract_table_info(request);
1300
1301 /*
1302@@ -233,6 +239,9 @@ mteEventSetTable_handler(netsnmp_mib_handler *handler,
1303
1304 case MODE_SET_ACTION:
1305 for (request = requests; request; request = request->next) {
1306+ if (request->processed)
1307+ continue;
1308+
1309 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
1310 if (!entry) {
1311 /*
1312@@ -254,6 +263,9 @@ mteEventSetTable_handler(netsnmp_mib_handler *handler,
1313 * (reasonably) safe to apply them in the Commit phase
1314 */
1315 for (request = requests; request; request = request->next) {
1316+ if (request->processed)
1317+ continue;
1318+
1319 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
1320 tinfo = netsnmp_extract_table_info(request);
1321
1322diff --git a/agent/mibgroup/disman/event/mteEventTable.c b/agent/mibgroup/disman/event/mteEventTable.c
1323index 5603715..c5b534e 100644
1324--- a/agent/mibgroup/disman/event/mteEventTable.c
1325+++ b/agent/mibgroup/disman/event/mteEventTable.c
1326@@ -106,6 +106,9 @@ mteEventTable_handler(netsnmp_mib_handler *handler,
1327 */
1328 case MODE_GET:
1329 for (request = requests; request; request = request->next) {
1330+ if (request->processed)
1331+ continue;
1332+
1333 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
1334 tinfo = netsnmp_extract_table_info(request);
1335 if (!entry || !(entry->flags & MTE_EVENT_FLAG_VALID))
1336@@ -142,6 +145,9 @@ mteEventTable_handler(netsnmp_mib_handler *handler,
1337 */
1338 case MODE_SET_RESERVE1:
1339 for (request = requests; request; request = request->next) {
1340+ if (request->processed)
1341+ continue;
1342+
1343 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
1344 tinfo = netsnmp_extract_table_info(request);
1345
1346@@ -223,6 +229,9 @@ mteEventTable_handler(netsnmp_mib_handler *handler,
1347
1348 case MODE_SET_RESERVE2:
1349 for (request = requests; request; request = request->next) {
1350+ if (request->processed)
1351+ continue;
1352+
1353 tinfo = netsnmp_extract_table_info(request);
1354
1355 switch (tinfo->colnum) {
1356@@ -255,6 +264,9 @@ mteEventTable_handler(netsnmp_mib_handler *handler,
1357
1358 case MODE_SET_FREE:
1359 for (request = requests; request; request = request->next) {
1360+ if (request->processed)
1361+ continue;
1362+
1363 tinfo = netsnmp_extract_table_info(request);
1364
1365 switch (tinfo->colnum) {
1366@@ -280,6 +292,9 @@ mteEventTable_handler(netsnmp_mib_handler *handler,
1367
1368 case MODE_SET_ACTION:
1369 for (request = requests; request; request = request->next) {
1370+ if (request->processed)
1371+ continue;
1372+
1373 tinfo = netsnmp_extract_table_info(request);
1374 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
1375 if (!entry) {
1376@@ -304,6 +319,9 @@ mteEventTable_handler(netsnmp_mib_handler *handler,
1377 * (reasonably) safe to apply them in the Commit phase
1378 */
1379 for (request = requests; request; request = request->next) {
1380+ if (request->processed)
1381+ continue;
1382+
1383 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
1384 tinfo = netsnmp_extract_table_info(request);
1385
1386diff --git a/agent/mibgroup/disman/event/mteObjectsTable.c b/agent/mibgroup/disman/event/mteObjectsTable.c
1387index 443c5cc..f7f6e02 100644
1388--- a/agent/mibgroup/disman/event/mteObjectsTable.c
1389+++ b/agent/mibgroup/disman/event/mteObjectsTable.c
1390@@ -101,6 +101,9 @@ mteObjectsTable_handler(netsnmp_mib_handler *handler,
1391 */
1392 case MODE_GET:
1393 for (request = requests; request; request = request->next) {
1394+ if (request->processed)
1395+ continue;
1396+
1397 entry = (struct mteObject *) netsnmp_tdata_extract_entry(request);
1398 tinfo = netsnmp_extract_table_info(request);
1399
1400@@ -135,6 +138,9 @@ mteObjectsTable_handler(netsnmp_mib_handler *handler,
1401 case MODE_SET_RESERVE1:
1402
1403 for (request = requests; request; request = request->next) {
1404+ if (request->processed)
1405+ continue;
1406+
1407 entry = (struct mteObject *) netsnmp_tdata_extract_entry(request);
1408 tinfo = netsnmp_extract_table_info(request);
1409
1410@@ -198,8 +204,10 @@ mteObjectsTable_handler(netsnmp_mib_handler *handler,
1411 break;
1412
1413 case MODE_SET_RESERVE2:
1414-
1415 for (request = requests; request; request = request->next) {
1416+ if (request->processed)
1417+ continue;
1418+
1419 tinfo = netsnmp_extract_table_info(request);
1420
1421 switch (tinfo->colnum) {
1422@@ -232,8 +240,10 @@ mteObjectsTable_handler(netsnmp_mib_handler *handler,
1423 break;
1424
1425 case MODE_SET_FREE:
1426-
1427 for (request = requests; request; request = request->next) {
1428+ if (request->processed)
1429+ continue;
1430+
1431 tinfo = netsnmp_extract_table_info(request);
1432
1433 switch (tinfo->colnum) {
1434@@ -259,6 +269,9 @@ mteObjectsTable_handler(netsnmp_mib_handler *handler,
1435
1436 case MODE_SET_ACTION:
1437 for (request = requests; request; request = request->next) {
1438+ if (request->processed)
1439+ continue;
1440+
1441 entry = (struct mteObject *) netsnmp_tdata_extract_entry(request);
1442 if (!entry) {
1443 /*
1444@@ -282,6 +295,9 @@ mteObjectsTable_handler(netsnmp_mib_handler *handler,
1445 * (reasonably) safe to apply them in the Commit phase
1446 */
1447 for (request = requests; request; request = request->next) {
1448+ if (request->processed)
1449+ continue;
1450+
1451 entry = (struct mteObject *) netsnmp_tdata_extract_entry(request);
1452 tinfo = netsnmp_extract_table_info(request);
1453
1454diff --git a/agent/mibgroup/disman/event/mteTrigger.c b/agent/mibgroup/disman/event/mteTrigger.c
1455index 002b543..7fca1b0 100644
1456--- a/agent/mibgroup/disman/event/mteTrigger.c
1457+++ b/agent/mibgroup/disman/event/mteTrigger.c
1458@@ -255,6 +255,7 @@ mteTrigger_run( unsigned int reg, void *clientarg)
1459 DEBUGMSGTL(( "disman:event:trigger:monitor", "Trigger query (%s) failed: %d\n",
1460 (( entry->flags & MTE_TRIGGER_FLAG_VWILD ) ? "walk" : "get"), n));
1461 _mteTrigger_failure( "failed to run mteTrigger query" );
1462+ snmp_free_varbind(var);
1463 return;
1464 }
1465
1466@@ -299,6 +300,7 @@ mteTrigger_run( unsigned int reg, void *clientarg)
1467 if (!vtmp) {
1468 _mteTrigger_failure(
1469 "failed to create mteTrigger temp varbind");
1470+ snmp_free_varbind(var);
1471 return;
1472 }
1473 vtmp->type = ASN_NULL;
1474@@ -336,6 +338,7 @@ mteTrigger_run( unsigned int reg, void *clientarg)
1475 if (!vtmp) {
1476 _mteTrigger_failure(
1477 "failed to create mteTrigger temp varbind");
1478+ snmp_free_varbind(var);
1479 return;
1480 }
1481 vtmp->type = ASN_NULL;
1482@@ -377,6 +380,7 @@ mteTrigger_run( unsigned int reg, void *clientarg)
1483 if (!vtmp) {
1484 _mteTrigger_failure(
1485 "failed to create mteTrigger temp varbind");
1486+ snmp_free_varbind(var);
1487 return;
1488 }
1489 vtmp->type = ASN_NULL;
1490@@ -712,6 +716,7 @@ mteTrigger_run( unsigned int reg, void *clientarg)
1491 if (!vtmp) {
1492 _mteTrigger_failure(
1493 "failed to create mteTrigger discontinuity varbind");
1494+ snmp_free_varbind(dvar);
1495 return;
1496 }
1497 snmp_set_var_objid(vtmp, entry->mteDeltaDiscontID,
1498diff --git a/agent/mibgroup/disman/event/mteTriggerBooleanTable.c b/agent/mibgroup/disman/event/mteTriggerBooleanTable.c
1499index a34ad30..ed1ec30 100644
1500--- a/agent/mibgroup/disman/event/mteTriggerBooleanTable.c
1501+++ b/agent/mibgroup/disman/event/mteTriggerBooleanTable.c
1502@@ -97,6 +97,9 @@ mteTriggerBooleanTable_handler(netsnmp_mib_handler *handler,
1503 */
1504 case MODE_GET:
1505 for (request = requests; request; request = request->next) {
1506+ if (request->processed)
1507+ continue;
1508+
1509 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1510 tinfo = netsnmp_extract_table_info(request);
1511
1512@@ -105,8 +108,10 @@ mteTriggerBooleanTable_handler(netsnmp_mib_handler *handler,
1513 * rows where the mteTriggerTest 'boolean(1)' bit is set.
1514 * So skip entries where this isn't the case.
1515 */
1516- if (!entry || !(entry->mteTriggerTest & MTE_TRIGGER_BOOLEAN ))
1517+ if (!entry || !(entry->mteTriggerTest & MTE_TRIGGER_BOOLEAN )) {
1518+ netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE);
1519 continue;
1520+ }
1521
1522 switch (tinfo->colnum) {
1523 case COLUMN_MTETRIGGERBOOLEANCOMPARISON:
1524@@ -152,6 +157,9 @@ mteTriggerBooleanTable_handler(netsnmp_mib_handler *handler,
1525 */
1526 case MODE_SET_RESERVE1:
1527 for (request = requests; request; request = request->next) {
1528+ if (request->processed)
1529+ continue;
1530+
1531 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1532 tinfo = netsnmp_extract_table_info(request);
1533
1534@@ -236,6 +244,9 @@ mteTriggerBooleanTable_handler(netsnmp_mib_handler *handler,
1535
1536 case MODE_SET_ACTION:
1537 for (request = requests; request; request = request->next) {
1538+ if (request->processed)
1539+ continue;
1540+
1541 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1542 if (!entry) {
1543 /*
1544@@ -256,6 +267,9 @@ mteTriggerBooleanTable_handler(netsnmp_mib_handler *handler,
1545 * (reasonably) safe to apply them in the Commit phase
1546 */
1547 for (request = requests; request; request = request->next) {
1548+ if (request->processed)
1549+ continue;
1550+
1551 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1552 tinfo = netsnmp_extract_table_info(request);
1553
1554diff --git a/agent/mibgroup/disman/event/mteTriggerDeltaTable.c b/agent/mibgroup/disman/event/mteTriggerDeltaTable.c
1555index 47f112c..c2c2e8e 100644
1556--- a/agent/mibgroup/disman/event/mteTriggerDeltaTable.c
1557+++ b/agent/mibgroup/disman/event/mteTriggerDeltaTable.c
1558@@ -27,6 +27,7 @@ init_mteTriggerDeltaTable(void)
1559 size_t mteTDeltaTable_oid_len = OID_LENGTH(mteTDeltaTable_oid);
1560 netsnmp_handler_registration *reg;
1561 netsnmp_table_registration_info *table_info;
1562+ int rc;
1563
1564 /*
1565 * Ensure the (combined) table container is available...
1566@@ -61,7 +62,9 @@ init_mteTriggerDeltaTable(void)
1567 table_info->max_column = COLUMN_MTETRIGGERDELTADISCONTINUITYIDTYPE;
1568
1569 /* Register this using the (common) trigger_table_data container */
1570- netsnmp_tdata_register(reg, trigger_table_data, table_info);
1571+ rc = netsnmp_tdata_register(reg, trigger_table_data, table_info);
1572+ if (rc != SNMPERR_SUCCESS)
1573+ return;
1574 netsnmp_handler_owns_table_info(reg->handler->next);
1575 DEBUGMSGTL(("disman:event:init", "Trigger Delta Table\n"));
1576 }
1577@@ -89,6 +92,9 @@ mteTriggerDeltaTable_handler(netsnmp_mib_handler *handler,
1578 */
1579 case MODE_GET:
1580 for (request = requests; request; request = request->next) {
1581+ if (request->processed)
1582+ continue;
1583+
1584 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1585 tinfo = netsnmp_extract_table_info(request);
1586
1587@@ -97,8 +103,10 @@ mteTriggerDeltaTable_handler(netsnmp_mib_handler *handler,
1588 * rows where the mteTriggerSampleType is 'deltaValue(2)'
1589 * So skip entries where this isn't the case.
1590 */
1591- if (!entry || !(entry->flags & MTE_TRIGGER_FLAG_DELTA ))
1592+ if (!entry || !(entry->flags & MTE_TRIGGER_FLAG_DELTA )) {
1593+ netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE);
1594 continue;
1595+ }
1596
1597 switch (tinfo->colnum) {
1598 case COLUMN_MTETRIGGERDELTADISCONTINUITYID:
1599@@ -125,6 +133,9 @@ mteTriggerDeltaTable_handler(netsnmp_mib_handler *handler,
1600 */
1601 case MODE_SET_RESERVE1:
1602 for (request = requests; request; request = request->next) {
1603+ if (request->processed)
1604+ continue;
1605+
1606 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1607 tinfo = netsnmp_extract_table_info(request);
1608
1609@@ -199,6 +210,9 @@ mteTriggerDeltaTable_handler(netsnmp_mib_handler *handler,
1610
1611 case MODE_SET_ACTION:
1612 for (request = requests; request; request = request->next) {
1613+ if (request->processed)
1614+ continue;
1615+
1616 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1617 if (!entry) {
1618 /*
1619@@ -219,6 +233,9 @@ mteTriggerDeltaTable_handler(netsnmp_mib_handler *handler,
1620 * (reasonably) safe to apply them in the Commit phase
1621 */
1622 for (request = requests; request; request = request->next) {
1623+ if (request->processed)
1624+ continue;
1625+
1626 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1627 tinfo = netsnmp_extract_table_info(request);
1628
1629diff --git a/agent/mibgroup/disman/event/mteTriggerExistenceTable.c b/agent/mibgroup/disman/event/mteTriggerExistenceTable.c
1630index ce1299f..22b683e 100644
1631--- a/agent/mibgroup/disman/event/mteTriggerExistenceTable.c
1632+++ b/agent/mibgroup/disman/event/mteTriggerExistenceTable.c
1633@@ -27,6 +27,7 @@ init_mteTriggerExistenceTable(void)
1634 static oid mteTExistTable_oid[] = { 1, 3, 6, 1, 2, 1, 88, 1, 2, 4 };
1635 size_t mteTExistTable_oid_len = OID_LENGTH(mteTExistTable_oid);
1636 netsnmp_handler_registration *reg;
1637+ int rc;
1638
1639 /*
1640 * Ensure the (combined) table container is available...
1641@@ -61,7 +62,10 @@ init_mteTriggerExistenceTable(void)
1642 table_info->max_column = COLUMN_MTETRIGGEREXISTENCEEVENT;
1643
1644 /* Register this using the (common) trigger_table_data container */
1645- netsnmp_tdata_register(reg, trigger_table_data, table_info);
1646+ rc = netsnmp_tdata_register(reg, trigger_table_data, table_info);
1647+ if (rc != SNMPERR_SUCCESS)
1648+ return;
1649+
1650 netsnmp_handler_owns_table_info(reg->handler->next);
1651 DEBUGMSGTL(("disman:event:init", "Trigger Exist Table\n"));
1652 }
1653@@ -89,6 +93,9 @@ mteTriggerExistenceTable_handler(netsnmp_mib_handler *handler,
1654 */
1655 case MODE_GET:
1656 for (request = requests; request; request = request->next) {
1657+ if (request->processed)
1658+ continue;
1659+
1660 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1661 tinfo = netsnmp_extract_table_info(request);
1662
1663@@ -97,8 +104,10 @@ mteTriggerExistenceTable_handler(netsnmp_mib_handler *handler,
1664 * rows where the mteTriggerTest 'existence(0)' bit is set.
1665 * So skip entries where this isn't the case.
1666 */
1667- if (!entry || !(entry->mteTriggerTest & MTE_TRIGGER_EXISTENCE ))
1668+ if (!entry || !(entry->mteTriggerTest & MTE_TRIGGER_EXISTENCE )) {
1669+ netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE);
1670 continue;
1671+ }
1672
1673 switch (tinfo->colnum) {
1674 case COLUMN_MTETRIGGEREXISTENCETEST:
1675@@ -139,6 +148,9 @@ mteTriggerExistenceTable_handler(netsnmp_mib_handler *handler,
1676 */
1677 case MODE_SET_RESERVE1:
1678 for (request = requests; request; request = request->next) {
1679+ if (request->processed)
1680+ continue;
1681+
1682 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1683 tinfo = netsnmp_extract_table_info(request);
1684
1685@@ -212,6 +224,9 @@ mteTriggerExistenceTable_handler(netsnmp_mib_handler *handler,
1686
1687 case MODE_SET_ACTION:
1688 for (request = requests; request; request = request->next) {
1689+ if (request->processed)
1690+ continue;
1691+
1692 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1693 if (!entry) {
1694 /*
1695@@ -233,6 +248,9 @@ mteTriggerExistenceTable_handler(netsnmp_mib_handler *handler,
1696 * (reasonably) safe to apply them in the Commit phase
1697 */
1698 for (request = requests; request; request = request->next) {
1699+ if (request->processed)
1700+ continue;
1701+
1702 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1703 tinfo = netsnmp_extract_table_info(request);
1704
1705diff --git a/agent/mibgroup/disman/event/mteTriggerTable.c b/agent/mibgroup/disman/event/mteTriggerTable.c
1706index d738ab5..88c2f8b 100644
1707--- a/agent/mibgroup/disman/event/mteTriggerTable.c
1708+++ b/agent/mibgroup/disman/event/mteTriggerTable.c
1709@@ -109,6 +109,9 @@ mteTriggerTable_handler(netsnmp_mib_handler *handler,
1710 */
1711 case MODE_GET:
1712 for (request = requests; request; request = request->next) {
1713+ if (request->processed)
1714+ continue;
1715+
1716 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1717 tinfo = netsnmp_extract_table_info(request);
1718
1719@@ -186,6 +189,9 @@ mteTriggerTable_handler(netsnmp_mib_handler *handler,
1720 */
1721 case MODE_SET_RESERVE1:
1722 for (request = requests; request; request = request->next) {
1723+ if (request->processed)
1724+ continue;
1725+
1726 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1727 tinfo = netsnmp_extract_table_info(request);
1728
1729@@ -292,6 +298,9 @@ mteTriggerTable_handler(netsnmp_mib_handler *handler,
1730
1731 case MODE_SET_RESERVE2:
1732 for (request = requests; request; request = request->next) {
1733+ if (request->processed)
1734+ continue;
1735+
1736 tinfo = netsnmp_extract_table_info(request);
1737
1738 switch (tinfo->colnum) {
1739@@ -324,6 +333,9 @@ mteTriggerTable_handler(netsnmp_mib_handler *handler,
1740
1741 case MODE_SET_FREE:
1742 for (request = requests; request; request = request->next) {
1743+ if (request->processed)
1744+ continue;
1745+
1746 tinfo = netsnmp_extract_table_info(request);
1747
1748 switch (tinfo->colnum) {
1749@@ -349,6 +361,9 @@ mteTriggerTable_handler(netsnmp_mib_handler *handler,
1750
1751 case MODE_SET_ACTION:
1752 for (request = requests; request; request = request->next) {
1753+ if (request->processed)
1754+ continue;
1755+
1756 tinfo = netsnmp_extract_table_info(request);
1757 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1758 if (!entry) {
1759@@ -373,6 +388,9 @@ mteTriggerTable_handler(netsnmp_mib_handler *handler,
1760 * (reasonably) safe to apply them in the Commit phase
1761 */
1762 for (request = requests; request; request = request->next) {
1763+ if (request->processed)
1764+ continue;
1765+
1766 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1767 tinfo = netsnmp_extract_table_info(request);
1768
1769diff --git a/agent/mibgroup/disman/event/mteTriggerThresholdTable.c b/agent/mibgroup/disman/event/mteTriggerThresholdTable.c
1770index 37d35e0..5aed0c8 100644
1771--- a/agent/mibgroup/disman/event/mteTriggerThresholdTable.c
1772+++ b/agent/mibgroup/disman/event/mteTriggerThresholdTable.c
1773@@ -97,6 +97,9 @@ mteTriggerThresholdTable_handler(netsnmp_mib_handler *handler,
1774 */
1775 case MODE_GET:
1776 for (request = requests; request; request = request->next) {
1777+ if (request->processed)
1778+ continue;
1779+
1780 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1781 tinfo = netsnmp_extract_table_info(request);
1782
1783@@ -105,8 +108,10 @@ mteTriggerThresholdTable_handler(netsnmp_mib_handler *handler,
1784 * rows where the mteTriggerTest 'threshold(2)' bit is set.
1785 * So skip entries where this isn't the case.
1786 */
1787- if (!entry || !(entry->mteTriggerTest & MTE_TRIGGER_THRESHOLD ))
1788+ if (!entry || !(entry->mteTriggerTest & MTE_TRIGGER_THRESHOLD )) {
1789+ netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE);
1790 continue;
1791+ }
1792
1793 switch (tinfo->colnum) {
1794 case COLUMN_MTETRIGGERTHRESHOLDSTARTUP:
1795@@ -189,6 +194,9 @@ mteTriggerThresholdTable_handler(netsnmp_mib_handler *handler,
1796 */
1797 case MODE_SET_RESERVE1:
1798 for (request = requests; request; request = request->next) {
1799+ if (request->processed)
1800+ continue;
1801+
1802 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1803 tinfo = netsnmp_extract_table_info(request);
1804
1805@@ -276,6 +284,9 @@ mteTriggerThresholdTable_handler(netsnmp_mib_handler *handler,
1806
1807 case MODE_SET_ACTION:
1808 for (request = requests; request; request = request->next) {
1809+ if (request->processed)
1810+ continue;
1811+
1812 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1813 if (!entry) {
1814 /*
1815@@ -296,6 +307,9 @@ mteTriggerThresholdTable_handler(netsnmp_mib_handler *handler,
1816 * (reasonably) safe to apply them in the Commit phase
1817 */
1818 for (request = requests; request; request = request->next) {
1819+ if (request->processed)
1820+ continue;
1821+
1822 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
1823 tinfo = netsnmp_extract_table_info(request);
1824
1825diff --git a/agent/mibgroup/disman/expr/expErrorTable.c b/agent/mibgroup/disman/expr/expErrorTable.c
1826index 6640a41..a759e2d 100644
1827--- a/agent/mibgroup/disman/expr/expErrorTable.c
1828+++ b/agent/mibgroup/disman/expr/expErrorTable.c
1829@@ -77,6 +77,9 @@ expErrorTable_handler(netsnmp_mib_handler *handler,
1830 */
1831 case MODE_GET:
1832 for (request = requests; request; request = request->next) {
1833+ if (request->processed)
1834+ continue;
1835+
1836 entry = (struct expExpression *)
1837 netsnmp_tdata_extract_entry(request);
1838 tinfo = netsnmp_extract_table_info(request);
1839diff --git a/agent/mibgroup/disman/expr/expExpressionTable.c b/agent/mibgroup/disman/expr/expExpressionTable.c
1840index ced9e0c..79aa715 100644
1841--- a/agent/mibgroup/disman/expr/expExpressionTable.c
1842+++ b/agent/mibgroup/disman/expr/expExpressionTable.c
1843@@ -88,6 +88,9 @@ expExpressionTable_handler(netsnmp_mib_handler *handler,
1844 */
1845 case MODE_GET:
1846 for (request = requests; request; request = request->next) {
1847+ if (request->processed)
1848+ continue;
1849+
1850 entry = (struct expExpression *)
1851 netsnmp_tdata_extract_entry(request);
1852 tinfo = netsnmp_extract_table_info(request);
1853@@ -150,6 +153,9 @@ expExpressionTable_handler(netsnmp_mib_handler *handler,
1854 */
1855 case MODE_SET_RESERVE1:
1856 for (request = requests; request; request = request->next) {
1857+ if (request->processed)
1858+ continue;
1859+
1860 entry = (struct expExpression *)
1861 netsnmp_tdata_extract_entry(request);
1862 tinfo = netsnmp_extract_table_info(request);
1863@@ -204,6 +210,9 @@ expExpressionTable_handler(netsnmp_mib_handler *handler,
1864
1865 case MODE_SET_RESERVE2:
1866 for (request = requests; request; request = request->next) {
1867+ if (request->processed)
1868+ continue;
1869+
1870 tinfo = netsnmp_extract_table_info(request);
1871
1872 switch (tinfo->colnum) {
1873@@ -236,6 +245,9 @@ expExpressionTable_handler(netsnmp_mib_handler *handler,
1874
1875 case MODE_SET_FREE:
1876 for (request = requests; request; request = request->next) {
1877+ if (request->processed)
1878+ continue;
1879+
1880 tinfo = netsnmp_extract_table_info(request);
1881
1882 switch (tinfo->colnum) {
1883@@ -261,6 +273,9 @@ expExpressionTable_handler(netsnmp_mib_handler *handler,
1884
1885 case MODE_SET_ACTION:
1886 for (request = requests; request; request = request->next) {
1887+ if (request->processed)
1888+ continue;
1889+
1890 tinfo = netsnmp_extract_table_info(request);
1891 entry = (struct expExpression *)
1892 netsnmp_tdata_extract_entry(request);
1893@@ -286,6 +301,9 @@ expExpressionTable_handler(netsnmp_mib_handler *handler,
1894 * (reasonably) safe to apply them in the Commit phase
1895 */
1896 for (request = requests; request; request = request->next) {
1897+ if (request->processed)
1898+ continue;
1899+
1900 entry = (struct expExpression *)
1901 netsnmp_tdata_extract_entry(request);
1902 tinfo = netsnmp_extract_table_info(request);
1903diff --git a/agent/mibgroup/disman/expr/expObject.c b/agent/mibgroup/disman/expr/expObject.c
1904index 28fbac6..c27437b 100644
1905--- a/agent/mibgroup/disman/expr/expObject.c
1906+++ b/agent/mibgroup/disman/expr/expObject.c
1907@@ -240,7 +240,6 @@ void
1908 expObject_getData( struct expExpression *expr, struct expObject *obj )
1909 {
1910 netsnmp_variable_list *var;
1911- int res;
1912
1913 /*
1914 * Retrieve and store the basic object value(s)
1915@@ -279,7 +278,7 @@ expObject_getData( struct expExpression *expr, struct expObject *obj )
1916 expr->expPrefix_len,
1917 expr->pvars );
1918 }
1919- res = netsnmp_query_get( var, expr->session );
1920+ netsnmp_query_get( var, expr->session );
1921 }
1922
1923 if ( obj->expObjectSampleType != EXPSAMPLETYPE_ABSOLUTE ) {
1924@@ -312,7 +311,7 @@ expObject_getData( struct expExpression *expr, struct expObject *obj )
1925 else
1926 var = _expObject_buildList( obj->expObjDeltaD,
1927 obj->expObjDeltaD_len, 0, NULL );
1928- res = netsnmp_query_get( var, expr->session );
1929+ netsnmp_query_get( var, expr->session );
1930 if ( obj->old_dvars )
1931 snmp_free_varbind( obj->old_dvars );
1932 obj->old_dvars = obj->dvars;
1933@@ -338,7 +337,7 @@ expObject_getData( struct expExpression *expr, struct expObject *obj )
1934 *
1935 * (The MIB description seems bogus?)
1936 */
1937- res = netsnmp_query_get( var, expr->session );
1938+ netsnmp_query_get( var, expr->session );
1939 if ( obj->cvars )
1940 snmp_free_varbind( obj->cvars );
1941 obj->cvars = var;
1942diff --git a/agent/mibgroup/disman/expr/expObjectTable.c b/agent/mibgroup/disman/expr/expObjectTable.c
1943index 4182b3e..adda438 100644
1944--- a/agent/mibgroup/disman/expr/expObjectTable.c
1945+++ b/agent/mibgroup/disman/expr/expObjectTable.c
1946@@ -90,6 +90,9 @@ expObjectTable_handler(netsnmp_mib_handler *handler,
1947 */
1948 case MODE_GET:
1949 for (request = requests; request; request = request->next) {
1950+ if (request->processed)
1951+ continue;
1952+
1953 entry = (struct expObject *)netsnmp_tdata_extract_entry(request);
1954 tinfo = netsnmp_extract_table_info(request);
1955 if (!entry || !(entry->flags & EXP_OBJ_FLAG_VALID))
1956@@ -159,6 +162,9 @@ expObjectTable_handler(netsnmp_mib_handler *handler,
1957 */
1958 case MODE_SET_RESERVE1:
1959 for (request = requests; request; request = request->next) {
1960+ if (request->processed)
1961+ continue;
1962+
1963 entry = (struct expObject *)
1964 netsnmp_tdata_extract_entry(request);
1965 tinfo = netsnmp_extract_table_info(request);
1966@@ -211,6 +217,9 @@ expObjectTable_handler(netsnmp_mib_handler *handler,
1967
1968 case MODE_SET_RESERVE2:
1969 for (request = requests; request; request = request->next) {
1970+ if (request->processed)
1971+ continue;
1972+
1973 tinfo = netsnmp_extract_table_info(request);
1974
1975 switch (tinfo->colnum) {
1976@@ -245,6 +254,9 @@ expObjectTable_handler(netsnmp_mib_handler *handler,
1977
1978 case MODE_SET_FREE:
1979 for (request = requests; request; request = request->next) {
1980+ if (request->processed)
1981+ continue;
1982+
1983 tinfo = netsnmp_extract_table_info(request);
1984
1985 switch (tinfo->colnum) {
1986@@ -270,6 +282,9 @@ expObjectTable_handler(netsnmp_mib_handler *handler,
1987
1988 case MODE_SET_ACTION:
1989 for (request = requests; request; request = request->next) {
1990+ if (request->processed)
1991+ continue;
1992+
1993 tinfo = netsnmp_extract_table_info(request);
1994 entry = (struct expObject *)
1995 netsnmp_tdata_extract_entry(request);
1996@@ -296,6 +311,9 @@ expObjectTable_handler(netsnmp_mib_handler *handler,
1997 */
1998 ret = 0; /* Flag to re-check expExpressionPrefix settings */
1999 for (request = requests; request; request = request->next) {
2000+ if (request->processed)
2001+ continue;
2002+
2003 entry = (struct expObject *) netsnmp_tdata_extract_entry(request);
2004 tinfo = netsnmp_extract_table_info(request);
2005
2006diff --git a/agent/mibgroup/disman/expr/expValueTable.c b/agent/mibgroup/disman/expr/expValueTable.c
2007index eac5faa..d74dbd1 100644
2008--- a/agent/mibgroup/disman/expr/expValueTable.c
2009+++ b/agent/mibgroup/disman/expr/expValueTable.c
2010@@ -124,7 +124,7 @@ NEXT_EXP:
2011 }
2012 if ( vp->val.objid[0] != 0 ) {
2013 DEBUGMSGTL(( "disman:expr:val",
2014- "non-zero instance (%d)\n", vp->val.objid[0]));
2015+ "non-zero instance (%" NETSNMP_PRIo "d)\n", vp->val.objid[0]));
2016 return NULL; /* Invalid instance */
2017 }
2018
2019@@ -158,7 +158,7 @@ NEXT_EXP:
2020 */
2021 if ( vp->val_len > 0 && vp->val.objid[0] != 0 ) {
2022 DEBUGMSGTL(( "disman:expr:val",
2023- "non-zero next instance (%d)\n", vp->val.objid[0]));
2024+ "non-zero next instance (%" NETSNMP_PRIo "d)\n", vp->val.objid[0]));
2025 return NULL; /* All valid instances start with .0 */
2026 }
2027 plen = exp->expPrefix_len;
2028@@ -231,6 +231,8 @@ NEXT_EXP:
2029 len = vp2->name_length - exp->expPrefix_len;
2030 snmp_set_var_typed_value( vp, ASN_PRIV_IMPLIED_OBJECT_ID,
2031 (u_char*)(vp2->name+exp->expPrefix_len), len);
2032+ } else {
2033+ len = 1;
2034 }
2035 res = expValue_evaluateExpression( exp, vp->val.objid+1, len-1);
2036 DEBUGMSGTL(( "disman:expr:val", "w/card next returned (%p)\n", res));
2037diff --git a/agent/mibgroup/disman/expression/expValueTable.c b/agent/mibgroup/disman/expression/expValueTable.c
2038index feace8c..6b315c6 100644
2039--- a/agent/mibgroup/disman/expression/expValueTable.c
2040+++ b/agent/mibgroup/disman/expression/expValueTable.c
2041@@ -133,7 +133,7 @@ init_expValueTable(void)
2042 * Initialize a "session" that defines who we're going to talk to
2043 */
2044 snmp_sess_init(&session); /* set up defaults */
2045- session.peername = "localhost";
2046+ session.peername = strdup("localhost");
2047
2048 DEBUGMSGTL(("expValueTable", "done.\n"));
2049 }
2050@@ -272,8 +272,7 @@ Evaluate_Expression(struct expValueTable_data *vtable_data)
2051 break;
2052 }
2053 }
2054- strncpy(temp, expression + 1, j - 1);
2055- *(temp + j - 1) = '\0';
2056+ sprintf(temp, "%.*s", j - 1, expression + 1);
2057 l = atoi(temp);
2058 expression = expression + j;
2059 /*
2060@@ -434,24 +433,12 @@ expValueTable_clean(void *data)
2061 void
2062 build_valuetable(void)
2063 {
2064- struct expExpressionTable_data *expstorage, *expfound;
2065+ struct expExpressionTable_data *expstorage;
2066 struct expObjectTable_data *objstorage, *objfound = NULL;
2067 struct header_complex_index *hcindex, *object_hcindex;
2068 char *expression;
2069- size_t expression_len;
2070 oid *index;
2071-
2072-
2073- char *result, *resultbak;
2074- char *temp, *tempbak;
2075 int i = 0, j, l;
2076- temp = malloc(100);
2077- result = malloc(100);
2078- tempbak = temp;
2079- memset(result, 0, 100);
2080- *result = '\0';
2081- resultbak = result;
2082-
2083
2084 DEBUGMSGTL(("expValueTable", "building valuetable... \n"));
2085
2086@@ -460,7 +447,6 @@ build_valuetable(void)
2087 expstorage = (struct expExpressionTable_data *) hcindex->data;
2088 if (expstorage->expExpressionEntryStatus == RS_ACTIVE) {
2089 expression = expstorage->expExpression;
2090- expression_len = expstorage->expExpressionLen;
2091 while (*expression != '\0') {
2092 if (*expression == '$') {
2093 i++;
2094@@ -475,9 +461,12 @@ build_valuetable(void)
2095 break;
2096 }
2097 }
2098- strncpy(temp, expression + 1, j - 1);
2099- *(temp + j - 1) = '\0';
2100- l = atoi(temp);
2101+ {
2102+ char temp[100];
2103+
2104+ sprintf(temp, "%.*s", j - 1, expression + 1);
2105+ l = atoi(temp);
2106+ }
2107 for (object_hcindex = expObjectTableStorage;
2108 object_hcindex != NULL;
2109 object_hcindex = object_hcindex->next) {
2110@@ -495,7 +484,6 @@ build_valuetable(void)
2111 expstorage->expExpressionNameLen)
2112 && (l == objstorage->expObjectIndex)) {
2113 if (objfound == NULL) {
2114- expfound = expstorage;
2115 objfound = objstorage;
2116 }
2117 if (objstorage->expObjectIDWildcard ==
2118diff --git a/agent/mibgroup/disman/ping/pingCtlTable.c b/agent/mibgroup/disman/ping/pingCtlTable.c
2119index a4fd3a8..a5036e2 100644
2120--- a/agent/mibgroup/disman/ping/pingCtlTable.c
2121+++ b/agent/mibgroup/disman/ping/pingCtlTable.c
2122@@ -340,12 +340,11 @@ pingProbeHistoryTable_addall(struct pingCtlTable_data *thedata)
2123 void
2124 pingCtlTable_cleaner(struct header_complex_index *thestuff)
2125 {
2126- struct header_complex_index *hciptr = NULL;
2127- struct pingCtlTable_data *StorageDel = NULL;
2128+ struct header_complex_index *hciptr;
2129+
2130 DEBUGMSGTL(("pingProbeHistoryTable", "cleanerout "));
2131 for (hciptr = thestuff; hciptr != NULL; hciptr = hciptr->next) {
2132- StorageDel =
2133- header_complex_extract_entry(&pingCtlTableStorage, hciptr);
2134+ header_complex_extract_entry(&pingCtlTableStorage, hciptr);
2135 DEBUGMSGTL(("pingProbeHistoryTable", "cleaner "));
2136 }
2137 }
2138@@ -864,7 +863,6 @@ pingProbeHistoryTable_delLast(struct pingCtlTable_data *thedata)
2139 {
2140 struct header_complex_index *hciptr2 = NULL;
2141 struct header_complex_index *hcilast = NULL;
2142- struct pingProbeHistoryTable_data *StorageDel = NULL;
2143 struct pingProbeHistoryTable_data *StorageTmp = NULL;
2144 netsnmp_variable_list *vars = NULL;
2145 oid newoid[MAX_OID_LEN];
2146@@ -895,9 +893,7 @@ pingProbeHistoryTable_delLast(struct pingCtlTable_data *thedata)
2147
2148 }
2149 }
2150- StorageDel =
2151- header_complex_extract_entry(&pingProbeHistoryTableStorage,
2152- hcilast);
2153+ header_complex_extract_entry(&pingProbeHistoryTableStorage, hcilast);
2154 DEBUGMSGTL(("pingProbeHistoryTable",
2155 "delete the last one success!\n"));
2156 }
2157@@ -1231,7 +1227,6 @@ readloop(struct pingCtlTable_data *item, struct addrinfo *ai, int datalen,
2158 unsigned long *minrtt, unsigned long *maxrtt,
2159 unsigned long *averagertt, pid_t pid)
2160 {
2161- int size;
2162 char recvbuf[BUFSIZE];
2163 char sendbuf[BUFSIZE];
2164 int nsent = 1;
2165@@ -1257,8 +1252,6 @@ readloop(struct pingCtlTable_data *item, struct addrinfo *ai, int datalen,
2166 }
2167 setuid(getuid()); /* don't need special permissions any more */
2168
2169- size = 60 * 1024; /* OK if setsockopt fails */
2170-
2171 tv.tv_sec = 5;
2172 tv.tv_usec = 0;
2173 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
2174@@ -1266,11 +1259,13 @@ readloop(struct pingCtlTable_data *item, struct addrinfo *ai, int datalen,
2175 for (current_probe_temp = 1;
2176 current_probe_temp <= item->pingCtlProbeCount;
2177 current_probe_temp++) {
2178+ time_t timep;
2179 (*pr->fsend) (datalen, pid, nsent, sockfd, sendbuf);
2180 nsent++;
2181 len = pr->salen;
2182 if (readable_timeo(sockfd, item->pingCtlTimeOut) == 0) {
2183 /* printf("socket timeout!\n"); */
2184+ n = -1;
2185 fail_probe = fail_probe + 1;
2186 flag = 1;
2187 } else {
2188@@ -1282,18 +1277,17 @@ readloop(struct pingCtlTable_data *item, struct addrinfo *ai, int datalen,
2189
2190 gettimeofday(&tval, NULL);
2191
2192- time_t timep;
2193 time(&timep);
2194
2195 (*pr->fproc) (recvbuf, n, &tval, timep, item, ai, datalen, minrtt,
2196 maxrtt, sumrtt, averagertt, current_probe_temp,
2197 success_probe, fail_probe, flag, &current_var, pid);
2198- printf("receiver success!\n");
2199 if (current_probe_temp >= item->pingCtlProbeCount) {
2200 SNMP_FREE(sumrtt);
2201 return;
2202 }
2203 }
2204+ close(sockfd);
2205 }
2206
2207 unsigned long
2208@@ -1599,7 +1593,6 @@ send_v4(int datalen, pid_t pid, int nsent, int sockfd, char *sendbuf)
2209 {
2210 int len;
2211 struct icmp *icmp = NULL;
2212- struct timeval *temp = NULL;
2213
2214 icmp = (struct icmp *) sendbuf;
2215 icmp->icmp_type = ICMP_ECHO;
2216@@ -1607,7 +1600,6 @@ send_v4(int datalen, pid_t pid, int nsent, int sockfd, char *sendbuf)
2217 icmp->icmp_id = pid;
2218 icmp->icmp_seq = nsent;
2219 gettimeofday((struct timeval *) icmp->icmp_data, NULL);
2220- temp = (struct timeval *) icmp->icmp_data;
2221
2222 len = 8 + datalen; /* checksum ICMP header and data */
2223 icmp->icmp_cksum = 0;
2224@@ -1773,7 +1765,7 @@ run_ping(unsigned int clientreg, void *clientarg)
2225 if (device) {
2226 struct ifreq ifr;
2227 memset(&ifr, 0, sizeof(ifr));
2228- strncpy(ifr.ifr_name, device, IFNAMSIZ - 1);
2229+ strlcpy(ifr.ifr_name, device, IFNAMSIZ);
2230 if (setsockopt
2231 (probe_fd, SOL_SOCKET, SO_BINDTODEVICE, device,
2232 strlen(device) + 1) == -1) {
2233@@ -1936,6 +1928,7 @@ run_ping(unsigned int clientreg, void *clientarg)
2234 (char *) outpack, &ident, &start_time, &screen_width,
2235 &deadline);
2236
2237+ close(icmp_sock);
2238 }
2239 return;
2240 }
2241@@ -2705,8 +2698,7 @@ write_pingCtlAdminStatus(int action,
2242 snmp_alarm_register(StorageTmp->pingCtlFrequency,
2243 SA_REPEAT, run_ping, StorageTmp);
2244 else
2245- StorageTmp->timer_id = snmp_alarm_register(1, (int) NULL,
2246- run_ping,
2247+ StorageTmp->timer_id = snmp_alarm_register(1, 0, run_ping,
2248 StorageTmp);
2249
2250 } else if (StorageTmp->pingCtlAdminStatus == 2
2251@@ -4367,8 +4359,7 @@ write_pingCtlRowStatus(int action,
2252 StorageTmp);
2253 else
2254 StorageTmp->timer_id =
2255- snmp_alarm_register(1, (int) NULL, run_ping,
2256- StorageTmp);
2257+ snmp_alarm_register(1, 0, run_ping, StorageTmp);
2258
2259 }
2260
2261@@ -4451,7 +4442,9 @@ int
2262 __schedule_exit(int next, long *nreceived, long *tmax)
2263 {
2264 unsigned long waittime;
2265+#if 0
2266 struct itimerval it;
2267+#endif
2268
2269 if (*nreceived) {
2270 waittime = 2 * (*tmax);
2271@@ -4463,11 +4456,13 @@ __schedule_exit(int next, long *nreceived, long *tmax)
2272 if (next < 0 || next < waittime / 1000)
2273 next = waittime / 1000;
2274
2275+#if 0
2276 it.it_interval.tv_sec = 0;
2277 it.it_interval.tv_usec = 0;
2278 it.it_value.tv_sec = waittime / 1000000;
2279 it.it_value.tv_usec = waittime % 1000000;
2280- /* setitimer(ITIMER_REAL, &it, NULL); */
2281+ setitimer(ITIMER_REAL, &it, NULL);
2282+#endif
2283 return next;
2284 }
2285
2286@@ -4741,6 +4736,7 @@ setup(int icmp_sock, int options, int uid, int timeout, int preload,
2287
2288 gettimeofday(start_time, NULL);
2289
2290+#if 0
2291 if (*deadline) {
2292 struct itimerval it;
2293
2294@@ -4749,6 +4745,7 @@ setup(int icmp_sock, int options, int uid, int timeout, int preload,
2295 it.it_value.tv_sec = (*deadline);
2296 it.it_value.tv_usec = 0;
2297 }
2298+#endif
2299
2300 if (isatty(STDOUT_FILENO)) {
2301 struct winsize w;
2302diff --git a/agent/mibgroup/disman/ping/pingProbeHistoryTable.c b/agent/mibgroup/disman/ping/pingProbeHistoryTable.c
2303index de398a8..78c75be 100644
2304--- a/agent/mibgroup/disman/ping/pingProbeHistoryTable.c
2305+++ b/agent/mibgroup/disman/ping/pingProbeHistoryTable.c
2306@@ -74,12 +74,10 @@ void
2307 pingProbeHistoryTable_cleaner(struct header_complex_index *thestuff)
2308 {
2309 struct header_complex_index *hciptr = NULL;
2310- struct pingProbeHistoryTable_data *StorageDel = NULL;
2311+
2312 DEBUGMSGTL(("pingProbeHistoryTable", "cleanerout "));
2313 for (hciptr = thestuff; hciptr != NULL; hciptr = hciptr->next) {
2314- StorageDel =
2315- header_complex_extract_entry(&pingProbeHistoryTableStorage,
2316- hciptr);
2317+ header_complex_extract_entry(&pingProbeHistoryTableStorage, hciptr);
2318 DEBUGMSGTL(("pingProbeHistoryTable", "cleaner "));
2319 }
2320
2321diff --git a/agent/mibgroup/disman/ping/pingResultsTable.c b/agent/mibgroup/disman/ping/pingResultsTable.c
2322index bc4a9f4..1445d86 100644
2323--- a/agent/mibgroup/disman/ping/pingResultsTable.c
2324+++ b/agent/mibgroup/disman/ping/pingResultsTable.c
2325@@ -86,12 +86,11 @@ pingResultsTable_inadd(struct pingResultsTable_data *thedata);
2326 void
2327 pingResultsTable_cleaner(struct header_complex_index *thestuff)
2328 {
2329- struct header_complex_index *hciptr = NULL;
2330- struct pingResultsTable_data *StorageDel = NULL;
2331+ struct header_complex_index *hciptr;
2332+
2333 DEBUGMSGTL(("pingResultsTable", "cleanerout "));
2334 for (hciptr = thestuff; hciptr != NULL; hciptr = hciptr->next) {
2335- StorageDel =
2336- header_complex_extract_entry(&pingResultsTableStorage, hciptr);
2337+ header_complex_extract_entry(&pingResultsTableStorage, hciptr);
2338 DEBUGMSGTL(("pingResultsTable", "cleaner "));
2339 }
2340
2341diff --git a/agent/mibgroup/disman/schedule/schedCore.h b/agent/mibgroup/disman/schedule/schedCore.h
2342index 4436711..35866d7 100644
2343--- a/agent/mibgroup/disman/schedule/schedCore.h
2344+++ b/agent/mibgroup/disman/schedule/schedCore.h
2345@@ -44,7 +44,7 @@ struct schedTable_entry {
2346 char schedDay[4+4];
2347 char schedHour[3];
2348 char schedMinute[8];
2349- char schedContextName[SCHED_STR1_LEN];
2350+ char schedContextName[SCHED_STR1_LEN+1];
2351 oid schedVariable[ MAX_OID_LEN ];
2352 size_t schedVariable_len;
2353 long schedValue;
2354diff --git a/agent/mibgroup/disman/schedule/schedTable.c b/agent/mibgroup/disman/schedule/schedTable.c
2355index 943e545..bba48fd 100644
2356--- a/agent/mibgroup/disman/schedule/schedTable.c
2357+++ b/agent/mibgroup/disman/schedule/schedTable.c
2358@@ -98,6 +98,9 @@ schedTable_handler(netsnmp_mib_handler *handler,
2359 */
2360 case MODE_GET:
2361 for (request = requests; request; request = request->next) {
2362+ if (request->processed)
2363+ continue;
2364+
2365 entry = (struct schedTable_entry *)
2366 netsnmp_tdata_extract_entry(request);
2367 tinfo = netsnmp_extract_table_info( request);
2368@@ -210,6 +213,9 @@ schedTable_handler(netsnmp_mib_handler *handler,
2369 */
2370 case MODE_SET_RESERVE1:
2371 for (request = requests; request; request = request->next) {
2372+ if (request->processed)
2373+ continue;
2374+
2375 entry = (struct schedTable_entry *)
2376 netsnmp_tdata_extract_entry(request);
2377 tinfo = netsnmp_extract_table_info( request);
2378@@ -340,6 +346,9 @@ schedTable_handler(netsnmp_mib_handler *handler,
2379
2380 case MODE_SET_RESERVE2:
2381 for (request = requests; request; request = request->next) {
2382+ if (request->processed)
2383+ continue;
2384+
2385 tinfo = netsnmp_extract_table_info(request);
2386
2387 switch (tinfo->colnum) {
2388@@ -370,6 +379,9 @@ schedTable_handler(netsnmp_mib_handler *handler,
2389
2390 case MODE_SET_FREE:
2391 for (request = requests; request; request = request->next) {
2392+ if (request->processed)
2393+ continue;
2394+
2395 tinfo = netsnmp_extract_table_info(request);
2396
2397 switch (tinfo->colnum) {
2398@@ -417,7 +429,11 @@ schedTable_handler(netsnmp_mib_handler *handler,
2399 * All these assignments are "unfailable", so it's
2400 * (reasonably) safe to apply them in the Commit phase
2401 */
2402+ entry = NULL;
2403 for (request = requests; request; request = request->next) {
2404+ if (request->processed)
2405+ continue;
2406+
2407 entry = (struct schedTable_entry *)
2408 netsnmp_tdata_extract_entry(request);
2409 tinfo = netsnmp_extract_table_info( request);
2410@@ -460,7 +476,7 @@ schedTable_handler(netsnmp_mib_handler *handler,
2411 recalculate = 1;
2412 break;
2413 case COLUMN_SCHEDCONTEXTNAME:
2414- memset(entry->schedContextName, 0, SCHED_STR1_LEN+1);
2415+ memset(entry->schedContextName, 0, sizeof(entry->schedContextName));
2416 memcpy(entry->schedContextName,
2417 request->requestvb->val.string,
2418 request->requestvb->val_len);
2419@@ -514,8 +530,10 @@ schedTable_handler(netsnmp_mib_handler *handler,
2420 break;
2421 }
2422 }
2423- if (recalculate)
2424+ if (recalculate) {
2425+ netsnmp_assert(entry);
2426 sched_nextTime(entry);
2427+ }
2428 break;
2429 }
2430 return SNMP_ERR_NOERROR;
2431diff --git a/agent/mibgroup/disman/traceroute/traceRouteCtlTable.c b/agent/mibgroup/disman/traceroute/traceRouteCtlTable.c
2432index 23ac029..04143eb 100644
2433--- a/agent/mibgroup/disman/traceroute/traceRouteCtlTable.c
2434+++ b/agent/mibgroup/disman/traceroute/traceRouteCtlTable.c
2435@@ -713,7 +713,6 @@ traceRouteProbeHistoryTable_delLast(struct traceRouteCtlTable_data
2436 {
2437 struct header_complex_index *hciptr2 = NULL;
2438 struct header_complex_index *hcilast = NULL;
2439- struct traceRouteProbeHistoryTable_data *StorageDel = NULL;
2440 struct traceRouteProbeHistoryTable_data *StorageTmp = NULL;
2441 netsnmp_variable_list *vars = NULL;
2442 oid newoid[MAX_OID_LEN];
2443@@ -745,9 +744,7 @@ traceRouteProbeHistoryTable_delLast(struct traceRouteCtlTable_data
2444
2445 }
2446 }
2447- StorageDel =
2448- header_complex_extract_entry(&traceRouteProbeHistoryTableStorage,
2449- hcilast);
2450+ header_complex_extract_entry(&traceRouteProbeHistoryTableStorage, hcilast);
2451 DEBUGMSGTL(("traceRouteProbeHistoryTable",
2452 "delete the last one success!\n"));
2453 vars = NULL;
2454@@ -1353,7 +1350,6 @@ int
2455 traceRouteResultsTable_del(struct traceRouteCtlTable_data *thedata)
2456 {
2457 struct header_complex_index *hciptr2 = NULL;
2458- struct traceRouteResultsTable_data *StorageDel = NULL;
2459 netsnmp_variable_list *vars = NULL;
2460 oid newoid[MAX_OID_LEN];
2461 size_t newoid_len = 0;
2462@@ -1368,9 +1364,8 @@ traceRouteResultsTable_del(struct traceRouteCtlTable_data *thedata)
2463 hciptr2 = hciptr2->next) {
2464 if (snmp_oid_compare(newoid, newoid_len, hciptr2->name, newoid_len)
2465 == 0) {
2466- StorageDel =
2467- header_complex_extract_entry
2468- (&traceRouteResultsTableStorage, hciptr2);
2469+ header_complex_extract_entry(&traceRouteResultsTableStorage,
2470+ hciptr2);
2471 DEBUGMSGTL(("traceRouteResultsTable", "delete success!\n"));
2472
2473 }
2474@@ -1386,7 +1381,6 @@ int
2475 traceRouteProbeHistoryTable_del(struct traceRouteCtlTable_data *thedata)
2476 {
2477 struct header_complex_index *hciptr2 = NULL;
2478- struct traceRouteProbeHistoryTable_data *StorageDel = NULL;
2479 netsnmp_variable_list *vars = NULL;
2480 oid newoid[MAX_OID_LEN];
2481 size_t newoid_len = 0;
2482@@ -1402,9 +1396,8 @@ traceRouteProbeHistoryTable_del(struct traceRouteCtlTable_data *thedata)
2483 hciptr2 = hciptr2->next) {
2484 if (snmp_oid_compare(newoid, newoid_len, hciptr2->name, newoid_len)
2485 == 0) {
2486- StorageDel =
2487- header_complex_extract_entry
2488- (&traceRouteProbeHistoryTableStorage, hciptr2);
2489+ header_complex_extract_entry(&traceRouteProbeHistoryTableStorage,
2490+ hciptr2);
2491 DEBUGMSGTL(("traceRouteProbeHistoryTable",
2492 "delete success!\n"));
2493
2494@@ -1419,7 +1412,6 @@ int
2495 traceRouteHopsTable_del(struct traceRouteCtlTable_data *thedata)
2496 {
2497 struct header_complex_index *hciptr2 = NULL;
2498- struct traceRouteHopsTable_data *StorageDel = NULL;
2499 netsnmp_variable_list *vars = NULL;
2500 oid newoid[MAX_OID_LEN];
2501 size_t newoid_len = 0;
2502@@ -1435,9 +1427,7 @@ traceRouteHopsTable_del(struct traceRouteCtlTable_data *thedata)
2503 hciptr2 = hciptr2->next) {
2504 if (snmp_oid_compare(newoid, newoid_len, hciptr2->name, newoid_len)
2505 == 0) {
2506- StorageDel =
2507- header_complex_extract_entry(&traceRouteHopsTableStorage,
2508- hciptr2);
2509+ header_complex_extract_entry(&traceRouteHopsTableStorage, hciptr2);
2510 DEBUGMSGTL(("traceRouteHopsTable", "delete success!\n"));
2511
2512 }
2513@@ -3210,8 +3200,7 @@ write_traceRouteCtlAdminStatus(int action,
2514 SA_REPEAT, run_traceRoute,
2515 StorageTmp);
2516 else
2517- StorageTmp->timer_id = snmp_alarm_register(1, (int) NULL,
2518- run_traceRoute,
2519+ StorageTmp->timer_id = snmp_alarm_register(1, 0, run_traceRoute,
2520 StorageTmp);
2521
2522 } else if (StorageTmp->traceRouteCtlAdminStatus == 2
2523@@ -4041,8 +4030,7 @@ write_traceRouteCtlRowStatus(int action,
2524 StorageTmp);
2525 else
2526 StorageTmp->timer_id =
2527- snmp_alarm_register(1, (int) NULL, run_traceRoute,
2528- StorageTmp);
2529+ snmp_alarm_register(1, 0, run_traceRoute, StorageTmp);
2530
2531 }
2532
2533@@ -4924,6 +4912,8 @@ run_traceRoute(unsigned int clientreg, void *clientarg)
2534
2535 }
2536
2537+ close(sndsock);
2538+
2539 if (flag == 1) {
2540 DEBUGMSGTL(("traceRouteProbeHistoryTable", "path changed!\n"));
2541 send_traceRoute_trap(item, traceRoutePathChange,
2542@@ -5556,6 +5546,8 @@ run_traceRoute(unsigned int clientreg, void *clientarg)
2543
2544 }
2545
2546+ close(sndsock);
2547+
2548 if (flag == 1) {
2549 printf("path changed!\n");
2550 send_traceRoute_trap(item, traceRoutePathChange,
2551@@ -6105,7 +6097,7 @@ ifaddrlist(register struct ifaddrlist **ipaddrp, register char *errbuf)
2552 #ifdef HAVE_SOCKADDR_SA_LEN
2553 register int n;
2554 #endif
2555- register struct ifreq *ifrp, *ifend, *ifnext, *mp;
2556+ register struct ifreq *ifrp, *ifend, *ifnext;
2557 register struct sockaddr_in *sin;
2558 register struct ifaddrlist *al;
2559 struct ifconf ifc;
2560@@ -6137,7 +6129,6 @@ ifaddrlist(register struct ifaddrlist **ipaddrp, register char *errbuf)
2561 ifend = (struct ifreq *) ((char *) ibuf + ifc.ifc_len);
2562
2563 al = ifaddrlist;
2564- mp = NULL;
2565 nipaddr = 0;
2566 for (; ifrp < ifend; ifrp = ifnext) {
2567 #ifdef HAVE_SOCKADDR_SA_LEN
2568@@ -6157,7 +6148,7 @@ ifaddrlist(register struct ifaddrlist **ipaddrp, register char *errbuf)
2569 * SIOCGIFFLAGS stomps over it because the requests
2570 * are returned in a union.)
2571 */
2572- strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name));
2573+ strlcpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name));
2574 if (ioctl(fd, SIOCGIFFLAGS, (char *) &ifr) < 0) {
2575 if (errno == ENXIO)
2576 continue;
2577@@ -6174,9 +6165,7 @@ ifaddrlist(register struct ifaddrlist **ipaddrp, register char *errbuf)
2578 if ((ifr.ifr_flags & IFF_UP) == 0)
2579 continue;
2580
2581-
2582- (void) strncpy(device, ifr.ifr_name, sizeof(ifr.ifr_name));
2583- device[sizeof(device) - 1] = '\0';
2584+ sprintf(device, "%.*s", (int) sizeof(ifr.ifr_name), ifr.ifr_name);
2585 #ifdef sun
2586 /*
2587 * Ignore sun virtual interfaces
2588diff --git a/agent/mibgroup/etherlike-mib/data_access/dot3stats_linux.c b/agent/mibgroup/etherlike-mib/data_access/dot3stats_linux.c
2589index efb1b54..00f4bc3 100644
2590--- a/agent/mibgroup/etherlike-mib/data_access/dot3stats_linux.c
2591+++ b/agent/mibgroup/etherlike-mib/data_access/dot3stats_linux.c
2592@@ -47,8 +47,8 @@ dot3stats_interface_name_list_get (struct ifname *list_head, int *retval)
2593 *retval = -2;
2594 return NULL;
2595 }
2596- memset (list_head, 0, sizeof (struct ifname));
2597- strncpy (list_head->name, p->ifa_name, IF_NAMESIZE);
2598+ memset(list_head, 0, sizeof (struct ifname));
2599+ strlcpy(list_head->name, p->ifa_name, IF_NAMESIZE);
2600 continue;
2601 }
2602
2603@@ -69,8 +69,8 @@ dot3stats_interface_name_list_get (struct ifname *list_head, int *retval)
2604 return NULL;
2605 }
2606 nameptr2 = nameptr2->ifn_next;
2607- memset (nameptr2, 0, sizeof (struct ifname));
2608- strncpy (nameptr2->name, p->ifa_name, IF_NAMESIZE);
2609+ memset(nameptr2, 0, sizeof (struct ifname));
2610+ strlcpy(nameptr2->name, p->ifa_name, IF_NAMESIZE);
2611 continue;
2612
2613 }
2614@@ -655,7 +655,7 @@ interface_ioctl_dot3stats_get (dot3StatsTable_rowreq_ctx *rowreq_ctx, int fd, co
2615 "called\n"));
2616
2617 memset(&ifr, 0, sizeof(ifr));
2618- strcpy(ifr.ifr_name, name);
2619+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
2620
2621 memset(&driver_info, 0, sizeof (driver_info));
2622 driver_info.cmd = ETHTOOL_GDRVINFO;
2623@@ -730,8 +730,8 @@ interface_ioctl_dot3stats_get (dot3StatsTable_rowreq_ctx *rowreq_ctx, int fd, co
2624 for (i = 0; i < nstats; i++) {
2625 char s[ETH_GSTRING_LEN];
2626
2627- strncpy(s, (const char *) &eth_strings->data[i * ETH_GSTRING_LEN],
2628- ETH_GSTRING_LEN);
2629+ strlcpy(s, (const char *) &eth_strings->data[i * ETH_GSTRING_LEN],
2630+ sizeof(s));
2631
2632 if (DOT3STATSALIGNMENTERRORS(s)) {
2633 data->dot3StatsAlignmentErrors = (u_long)eth_stats->data[i];
2634@@ -911,8 +911,7 @@ _dot3Stats_ioctl_get(int fd, int which, struct ifreq *ifrq, const char* name)
2635 }
2636 }
2637
2638- strncpy(ifrq->ifr_name, name, sizeof(ifrq->ifr_name));
2639- ifrq->ifr_name[ sizeof(ifrq->ifr_name)-1 ] = 0;
2640+ strlcpy(ifrq->ifr_name, name, sizeof(ifrq->ifr_name));
2641 rc = ioctl(fd, which, ifrq);
2642 if (rc < 0) {
2643 DEBUGMSGTL(("access:dot3StatsTable:ioctl",
2644diff --git a/agent/mibgroup/examples/example.c b/agent/mibgroup/examples/example.c
2645index 8f27ead..50b7e7d 100644
2646--- a/agent/mibgroup/examples/example.c
2647+++ b/agent/mibgroup/examples/example.c
2648@@ -163,7 +163,7 @@ init_example(void)
2649 * Also set a default value for the string object. Note that the
2650 * example integer variable was initialised above.
2651 */
2652- strncpy(example_str, EXAMPLE_STR_DEFAULT, EXAMPLE_STR_LEN);
2653+ strlcpy(example_str, EXAMPLE_STR_DEFAULT, sizeof(example_str));
2654
2655 snmpd_register_config_handler("exampleint",
2656 example_parse_config_exampleint,
2657@@ -209,7 +209,7 @@ example_parse_config_examplestr(const char *token, char *cptr)
2658 /*
2659 * Make sure the string fits in the space allocated for it.
2660 */
2661- if (strlen(cptr) < EXAMPLE_STR_LEN)
2662+ if (strlen(cptr) < sizeof(example_str))
2663 strcpy(example_str, cptr);
2664 else {
2665 /*
2666@@ -217,10 +217,8 @@ example_parse_config_examplestr(const char *token, char *cptr)
2667 * An alternative approach would be to log an error,
2668 * and discard this value altogether.
2669 */
2670- strncpy(example_str, cptr, EXAMPLE_STR_LEN - 4);
2671- example_str[EXAMPLE_STR_LEN - 4] = 0;
2672- strcat(example_str, "...");
2673- example_str[EXAMPLE_STR_LEN - 1] = 0;
2674+ sprintf(example_str, "%.*s...", (int) (sizeof(example_str) - 4), cptr);
2675+ netsnmp_assert(strlen(example_str) < sizeof(example_str));
2676 }
2677 }
2678
2679diff --git a/agent/mibgroup/examples/netSnmpHostsTable_access.c b/agent/mibgroup/examples/netSnmpHostsTable_access.c
2680index f6f933a..3d2e5fb 100644
2681--- a/agent/mibgroup/examples/netSnmpHostsTable_access.c
2682+++ b/agent/mibgroup/examples/netSnmpHostsTable_access.c
2683@@ -177,10 +177,11 @@ void *
2684 netSnmpHostsTable_create_data_context(netsnmp_variable_list * index_data)
2685 {
2686 my_data_info *datactx = SNMP_MALLOC_TYPEDEF(my_data_info);
2687+
2688 if (!datactx)
2689 return NULL;
2690- strncpy(datactx->hostname, index_data->val.string,
2691- strlen(index_data->val.string));
2692+ strlcpy(datactx->hostname, (const char *) index_data->val.string,
2693+ sizeof(datactx->hostname));
2694 return datactx;
2695 }
2696
2697diff --git a/agent/mibgroup/examples/netSnmpHostsTable_checkfns.c b/agent/mibgroup/examples/netSnmpHostsTable_checkfns.c
2698index df47ca4..25a7330 100644
2699--- a/agent/mibgroup/examples/netSnmpHostsTable_checkfns.c
2700+++ b/agent/mibgroup/examples/netSnmpHostsTable_checkfns.c
2701@@ -34,9 +34,6 @@ int
2702 check_netSnmpHostAddressType(int type, long *val, size_t val_len,
2703 long *old_val, size_t old_val_len)
2704 {
2705-
2706- int ret;
2707-
2708 /** Check to see that we were called legally */
2709 if (!val)
2710 return SNMP_ERR_GENERR;
2711@@ -59,8 +56,6 @@ check_netSnmpHostAddressType(int type, long *val, size_t val_len,
2712 default:
2713 return SNMP_ERR_INCONSISTENTVALUE;
2714 }
2715- ret = SNMP_ERR_NOERROR;
2716-
2717
2718 /** looks ok, call the local version of the same function. */
2719 return check_netSnmpHostAddressType_local(type, val, val_len, old_val,
2720@@ -79,9 +74,6 @@ int
2721 check_netSnmpHostAddress(int type, char *val, size_t val_len,
2722 char *old_val, size_t old_val_len)
2723 {
2724-
2725- int ret;
2726-
2727 /** Check to see that we were called legally */
2728 if (!val)
2729 return SNMP_ERR_GENERR;
2730@@ -91,11 +83,8 @@ check_netSnmpHostAddress(int type, char *val, size_t val_len,
2731 return SNMP_ERR_WRONGTYPE;
2732
2733 /** Check the ranges of the passed value for legality */
2734- if (!(val_len >= 0 && val_len <= 255)
2735- ) {
2736+ if (!(val_len >= 0 && val_len <= 255))
2737 return SNMP_ERR_WRONGVALUE;
2738- }
2739-
2740
2741 /** looks ok, call the local version of the same function. */
2742 return check_netSnmpHostAddress_local(type, val, val_len, old_val,
2743@@ -138,11 +127,10 @@ check_netSnmpHostStorage(int type, long *val, size_t val_len,
2744 default:
2745 return SNMP_ERR_INCONSISTENTVALUE;
2746 }
2747- ret = SNMP_ERR_NOERROR;
2748
2749- if (ret =
2750- check_storage_transition((old_val) ? *old_val : SNMP_STORAGE_NONE,
2751- *val))
2752+ ret = check_storage_transition((old_val) ? *old_val : SNMP_STORAGE_NONE,
2753+ *val);
2754+ if (ret)
2755 return ret;
2756
2757 /** looks ok, call the local version of the same function. */
2758@@ -187,11 +175,10 @@ check_netSnmpHostRowStatus(int type, long *val, size_t val_len,
2759 default:
2760 return SNMP_ERR_INCONSISTENTVALUE;
2761 }
2762- ret = SNMP_ERR_NOERROR;
2763
2764- if (ret =
2765- check_rowstatus_transition((old_val) ? *old_val : RS_NONEXISTENT,
2766- *val))
2767+ ret = check_rowstatus_transition((old_val) ? *old_val : RS_NONEXISTENT,
2768+ *val);
2769+ if (ret)
2770 return ret;
2771
2772 /** looks ok, call the local version of the same function. */
2773diff --git a/agent/mibgroup/examples/netSnmpHostsTable_checkfns_local.h b/agent/mibgroup/examples/netSnmpHostsTable_checkfns_local.h
2774index 335a0ae..6cd44c9 100644
2775--- a/agent/mibgroup/examples/netSnmpHostsTable_checkfns_local.h
2776+++ b/agent/mibgroup/examples/netSnmpHostsTable_checkfns_local.h
2777@@ -3,8 +3,8 @@
2778 * : : mib2c.check_values_local.conf,v 5.1 2003/05/30 23:53:15 hardaker Exp $
2779 *
2780 */
2781-#ifndef NETSNMPHOSTSTABLE_CHECKFNS_H
2782-#define NETSNMPHOSTSTABLE_CHECKFNS_H
2783+#ifndef NETSNMPHOSTSTABLE_CHECKFNS_LOCAL_H
2784+#define NETSNMPHOSTSTABLE_CHECKFNS_LOCAL_H
2785
2786 /*
2787 * these functions are designed to check incoming values for
2788@@ -18,19 +18,32 @@
2789 #ifdef __cplusplus
2790 extern "C" {
2791 #endif
2792+#if 0
2793+}
2794+#endif
2795
2796-int check_(int type, long *val, size_t val_len, long *old_val,
2797- size_t old_val_len);
2798-int check_(int type, char *val, size_t val_len, char *old_val,
2799- size_t old_val_len);
2800-int check_(int type, long *val, size_t val_len, long *old_val,
2801- size_t old_val_len);
2802-int check_(int type, long *val, size_t val_len, long *old_val,
2803- size_t old_val_len);
2804-
2805+int check_netSnmpHostAddressType_local(int type, long *val,
2806+ size_t val_len,
2807+ long *old_val,
2808+ size_t old_val_len);
2809+int check_netSnmpHostAddress_local(int type, char *val,
2810+ size_t val_len,
2811+ char *old_val,
2812+ size_t old_val_len);
2813+int check_netSnmpHostStorage_local(int type, long *val,
2814+ size_t val_len,
2815+ long *old_val,
2816+ size_t old_val_len);
2817+int check_netSnmpHostRowStatus_local(int type, long *val,
2818+ size_t val_len,
2819+ long *old_val,
2820+ size_t old_val_len);
2821
2822+#if 0
2823+{
2824+#endif
2825 #ifdef __cplusplus
2826 }
2827 #endif
2828
2829-#endif /* NETSNMPHOSTSTABLE_CHECKFNS_H */
2830+#endif /* NETSNMPHOSTSTABLE_CHECKFNS_LOCAL_H */
2831diff --git a/agent/mibgroup/examples/ucdDemoPublic.c b/agent/mibgroup/examples/ucdDemoPublic.c
2832index e935216..8e9e66a 100644
2833--- a/agent/mibgroup/examples/ucdDemoPublic.c
2834+++ b/agent/mibgroup/examples/ucdDemoPublic.c
2835@@ -25,6 +25,7 @@
2836
2837 #include <net-snmp/net-snmp-includes.h>
2838 #include <net-snmp/agent/net-snmp-agent-includes.h>
2839+#include <net-snmp/library/tools.h>
2840
2841 #include "util_funcs/header_generic.h"
2842 #include "ucdDemoPublic.h"
2843@@ -213,16 +214,9 @@ write_ucdDemoPublicString(int action,
2844 return SNMP_ERR_WRONGLENGTH;
2845 }
2846 if (action == COMMIT) {
2847- if (var_val_len != 0) {
2848- strncpy((char*)publicString, (const char*)var_val, sizeof(publicString)-1);
2849- /* some sanity checks */
2850- if (strlen((const char*)var_val) > sizeof(publicString)-1 ||
2851- strlen((const char*)var_val) != var_val_len)
2852- publicString[sizeof(publicString)-1] = '\0';
2853- else
2854- publicString[var_val_len] = '\0';
2855- } else
2856- publicString[0] = '\0';
2857+ sprintf((char*) publicString, "%.*s",
2858+ (int) SNMP_MIN(sizeof(publicString) - 1, var_val_len),
2859+ (const char*) var_val);
2860 }
2861 return SNMP_ERR_NOERROR;
2862 }
2863diff --git a/agent/mibgroup/hardware/cpu/cpu.c b/agent/mibgroup/hardware/cpu/cpu.c
2864index 3a0a5d4..2772001 100644
2865--- a/agent/mibgroup/hardware/cpu/cpu.c
2866+++ b/agent/mibgroup/hardware/cpu/cpu.c
2867@@ -142,6 +142,12 @@ netsnmp_cpu_info *netsnmp_cpu_get_byName( char *name, int create ) {
2868 cpu = SNMP_MALLOC_TYPEDEF( netsnmp_cpu_info );
2869 if (!cpu)
2870 return NULL;
2871+ if (strlen(name) >= sizeof(cpu->name)) {
2872+ free(cpu);
2873+ snmp_log(LOG_ERR, "Name of CPU is too large: %s\n", name);
2874+ return NULL;
2875+ }
2876+
2877 strcpy(cpu->name, name);
2878 if ( _cpu_tail ) {
2879 cpu->idx = _cpu_tail->idx+1;
2880diff --git a/agent/mibgroup/hardware/cpu/cpu_kerndata.c b/agent/mibgroup/hardware/cpu/cpu_kerndata.c
2881index 9a9c4a4..8a7f2b2 100644
2882--- a/agent/mibgroup/hardware/cpu/cpu_kerndata.c
2883+++ b/agent/mibgroup/hardware/cpu/cpu_kerndata.c
2884@@ -64,32 +64,32 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
2885 for ( i=0; i < cpu_num; i++ ) {
2886 cpu2 = netsnmp_cpu_get_byIdx( i, 0 );
2887
2888- cpu2->user_ticks = (unsigned long)vminfo[i].v_time[V_CPU_USER];
2889- cpu2->idle_ticks = (unsigned long)vminfo[i].v_time[V_CPU_IDLE];
2890- cpu2->kern_ticks = (unsigned long)vminfo[i].v_time[V_CPU_KERNEL];
2891- cpu2->wait_ticks = (unsigned long)vminfo[i].v_time[V_CPU_STREAM];
2892- cpu2->sys2_ticks = (unsigned long)vminfo[i].v_time[V_CPU_KERNEL]+
2893+ cpu2->user_ticks = (unsigned long long)vminfo[i].v_time[V_CPU_USER];
2894+ cpu2->idle_ticks = (unsigned long long)vminfo[i].v_time[V_CPU_IDLE];
2895+ cpu2->kern_ticks = (unsigned long long)vminfo[i].v_time[V_CPU_KERNEL];
2896+ cpu2->wait_ticks = (unsigned long long)vminfo[i].v_time[V_CPU_STREAM];
2897+ cpu2->sys2_ticks = (unsigned long long)vminfo[i].v_time[V_CPU_KERNEL]+
2898 vminfo[i].v_time[V_CPU_STREAM];
2899 /* nice_ticks, intrpt_ticks, sirq_ticks unused */
2900
2901 /* sum these for the overall stats */
2902- cpu->user_ticks += (unsigned long)vminfo[i].v_time[V_CPU_USER];
2903- cpu->idle_ticks += (unsigned long)vminfo[i].v_time[V_CPU_IDLE];
2904- cpu->kern_ticks += (unsigned long)vminfo[i].v_time[V_CPU_KERNEL];
2905- cpu->wait_ticks += (unsigned long)vminfo[i].v_time[V_CPU_STREAM];
2906- cpu->sys2_ticks += (unsigned long)vminfo[i].v_time[V_CPU_KERNEL]+
2907+ cpu->user_ticks += (unsigned long long)vminfo[i].v_time[V_CPU_USER];
2908+ cpu->idle_ticks += (unsigned long long)vminfo[i].v_time[V_CPU_IDLE];
2909+ cpu->kern_ticks += (unsigned long long)vminfo[i].v_time[V_CPU_KERNEL];
2910+ cpu->wait_ticks += (unsigned long long)vminfo[i].v_time[V_CPU_STREAM];
2911+ cpu->sys2_ticks += (unsigned long long)vminfo[i].v_time[V_CPU_KERNEL]+
2912 vminfo[i].v_time[V_CPU_STREAM];
2913
2914 /*
2915 * Interrupt/Context Switch statistics
2916 * XXX - Do these really belong here ?
2917 */
2918- cpu->swapIn += (unsigned long)vminfo[i].v_swpin;
2919- cpu->swapOut += (unsigned long)vminfo[i].v_swpout;
2920- cpu->pageIn += (unsigned long)vminfo[i].v_phread;
2921- cpu->pageOut += (unsigned long)vminfo[i].v_phwrite;
2922- cpu->nInterrupts += (unsigned long)vminfo[i].v_intr;
2923- cpu->nCtxSwitches += (unsigned long)vminfo[i].v_swtch;
2924+ cpu->swapIn += (unsigned long long)vminfo[i].v_swpin;
2925+ cpu->swapOut += (unsigned long long)vminfo[i].v_swpout;
2926+ cpu->pageIn += (unsigned long long)vminfo[i].v_phread;
2927+ cpu->pageOut += (unsigned long long)vminfo[i].v_phwrite;
2928+ cpu->nInterrupts += (unsigned long long)vminfo[i].v_intr;
2929+ cpu->nCtxSwitches += (unsigned long long)vminfo[i].v_swtch;
2930 }
2931 return 0;
2932 }
2933diff --git a/agent/mibgroup/hardware/cpu/cpu_kstat.c b/agent/mibgroup/hardware/cpu/cpu_kstat.c
2934index 32ccb00..049864c 100644
2935--- a/agent/mibgroup/hardware/cpu/cpu_kstat.c
2936+++ b/agent/mibgroup/hardware/cpu/cpu_kstat.c
2937@@ -48,16 +48,13 @@ void init_cpu_kstat( void ) {
2938 memset(state, 0, sizeof(state));
2939 for (i=0, ks_data = ksp->ks_data; i < ksp->ks_ndata; i++, ks_data++) {
2940 if ( strcmp( ks_data->name, "state" ) == 0 ) {
2941- strncpy( state, ks_data->value.c, sizeof(state));
2942- state[sizeof(state)-1] = '\0';
2943+ strlcpy(state, ks_data->value.c, sizeof(state));
2944 } else if ( strcmp( ks_data->name, "state_begin" ) == 0 ) {
2945 state_begin = ks_data->value.i32;
2946 } else if ( strcmp( ks_data->name, "cpu_type" ) == 0 ) {
2947- strncpy( ctype, ks_data->value.c, sizeof(ctype));
2948- ctype[sizeof(ctype)-1] = '\0';
2949+ strlcpy(ctype, ks_data->value.c, sizeof(ctype));
2950 } else if ( strcmp( ks_data->name, "fpu_type" ) == 0 ) {
2951- strncpy( ftype, ks_data->value.c, sizeof(ftype));
2952- ftype[sizeof(ftype)-1] = '\0';
2953+ strlcpy(ftype, ks_data->value.c, sizeof(ftype));
2954 } else if ( strcmp( ks_data->name, "clock_MHz" ) == 0 ) {
2955 clock = ks_data->value.i32;
2956 }
2957@@ -112,30 +109,30 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
2958 break; /* or continue ? */
2959 }
2960
2961- cpu2->user_ticks = (unsigned long)cs.cpu_sysinfo.cpu[CPU_USER];
2962- cpu2->idle_ticks = (unsigned long)cs.cpu_sysinfo.cpu[CPU_IDLE];
2963- cpu2->kern_ticks = (unsigned long)cs.cpu_sysinfo.cpu[CPU_KERNEL];
2964- cpu2->wait_ticks = (unsigned long)cs.cpu_sysinfo.cpu[CPU_WAIT];
2965+ cpu2->user_ticks = (unsigned long long)cs.cpu_sysinfo.cpu[CPU_USER];
2966+ cpu2->idle_ticks = (unsigned long long)cs.cpu_sysinfo.cpu[CPU_IDLE];
2967+ cpu2->kern_ticks = (unsigned long long)cs.cpu_sysinfo.cpu[CPU_KERNEL];
2968+ cpu2->wait_ticks = (unsigned long long)cs.cpu_sysinfo.cpu[CPU_WAIT];
2969 /* or cs.cpu_sysinfo.wait[W_IO]+cs.cpu_sysinfo.wait[W_PIO] */
2970- cpu2->sys2_ticks = (unsigned long)cpu2->kern_ticks+cpu2->wait_ticks;
2971+ cpu2->sys2_ticks = (unsigned long long)cpu2->kern_ticks+cpu2->wait_ticks;
2972 /* nice_ticks, intrpt_ticks, sirq_ticks unused */
2973
2974 /* sum these for the overall stats */
2975- cpu->user_ticks += (unsigned long)cs.cpu_sysinfo.cpu[CPU_USER];
2976- cpu->idle_ticks += (unsigned long)cs.cpu_sysinfo.cpu[CPU_IDLE];
2977- cpu->kern_ticks += (unsigned long)cs.cpu_sysinfo.cpu[CPU_KERNEL];
2978- cpu->wait_ticks += (unsigned long)cs.cpu_sysinfo.cpu[CPU_WAIT];
2979+ cpu->user_ticks += (unsigned long long)cs.cpu_sysinfo.cpu[CPU_USER];
2980+ cpu->idle_ticks += (unsigned long long)cs.cpu_sysinfo.cpu[CPU_IDLE];
2981+ cpu->kern_ticks += (unsigned long long)cs.cpu_sysinfo.cpu[CPU_KERNEL];
2982+ cpu->wait_ticks += (unsigned long long)cs.cpu_sysinfo.cpu[CPU_WAIT];
2983 /* or cs.cpu_sysinfo.wait[W_IO]+cs.cpu_sysinfo.wait[W_PIO] */
2984- cpu->sys2_ticks += (unsigned long)cpu2->kern_ticks+cpu2->wait_ticks;
2985+ cpu->sys2_ticks += (unsigned long long)cpu2->kern_ticks+cpu2->wait_ticks;
2986
2987 /*
2988 * Interrupt/Context Switch statistics
2989 * XXX - Do these really belong here ?
2990 */
2991- cpu->swapIn += (unsigned long)cs.cpu_vminfo.swapin;
2992- cpu->swapOut += (unsigned long)cs.cpu_vminfo.swapout;
2993- cpu->nInterrupts += (unsigned long)cs.cpu_sysinfo.intr;
2994- cpu->nCtxSwitches += (unsigned long)cs.cpu_sysinfo.pswitch;
2995+ cpu->swapIn += (unsigned long long)cs.cpu_vminfo.swapin;
2996+ cpu->swapOut += (unsigned long long)cs.cpu_vminfo.swapout;
2997+ cpu->nInterrupts += (unsigned long long)cs.cpu_sysinfo.intr;
2998+ cpu->nCtxSwitches += (unsigned long long)cs.cpu_sysinfo.pswitch;
2999 }
3000 }
3001 return 0;
3002diff --git a/agent/mibgroup/hardware/cpu/cpu_linux.c b/agent/mibgroup/hardware/cpu/cpu_linux.c
3003index 2edeccd..640407b 100644
3004--- a/agent/mibgroup/hardware/cpu/cpu_linux.c
3005+++ b/agent/mibgroup/hardware/cpu/cpu_linux.c
3006@@ -121,6 +121,10 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
3007 DEBUGMSGTL(("cpu", "/proc/stat buffer increased to %d\n", bsize));
3008 close(statfd);
3009 statfd = open(STAT_FILE, O_RDONLY, 0);
3010+ if (statfd == -1) {
3011+ snmp_log_perror(STAT_FILE);
3012+ return -1;
3013+ }
3014 }
3015 close(statfd);
3016
3017@@ -159,27 +163,27 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
3018
3019 /* kernel 2.6.33 and above */
3020 if (num_cpuline_elem == 10) {
3021- cpu->guestnice_ticks = (unsigned long)cguest_nicell;
3022+ cpu->guestnice_ticks = (unsigned long long)cguest_nicell;
3023 }
3024 /* kernel 2.6.24 and above */
3025 if (num_cpuline_elem >= 9) {
3026- cpu->guest_ticks = (unsigned long)cguestll;
3027+ cpu->guest_ticks = (unsigned long long)cguestll;
3028 }
3029 /* kernel 2.6.11 and above */
3030 if (num_cpuline_elem >= 8) {
3031- cpu->steal_ticks = (unsigned long)cstealll;
3032+ cpu->steal_ticks = (unsigned long long)cstealll;
3033 }
3034 /* kernel 2.6 */
3035 if (num_cpuline_elem >= 5) {
3036- cpu->wait_ticks = (unsigned long)ciowll;
3037- cpu->intrpt_ticks = (unsigned long)cirqll;
3038- cpu->sirq_ticks = (unsigned long)csoftll;
3039+ cpu->wait_ticks = (unsigned long long)ciowll;
3040+ cpu->intrpt_ticks = (unsigned long long)cirqll;
3041+ cpu->sirq_ticks = (unsigned long long)csoftll;
3042 }
3043 /* rest */
3044- cpu->user_ticks = (unsigned long)cusell;
3045- cpu->nice_ticks = (unsigned long)cicell;
3046- cpu->sys_ticks = (unsigned long)csysll;
3047- cpu->idle_ticks = (unsigned long)cidell;
3048+ cpu->user_ticks = (unsigned long long)cusell;
3049+ cpu->nice_ticks = (unsigned long long)cicell;
3050+ cpu->sys_ticks = (unsigned long long)csysll;
3051+ cpu->idle_ticks = (unsigned long long)cidell;
3052 }
3053 if ( b1 == buff ) {
3054 if (first)
3055@@ -232,6 +236,10 @@ void _cpu_load_swap_etc( char *buff, netsnmp_cpu_info *cpu ) {
3056 vmbuff = (char*)realloc(vmbuff, vmbsize+1);
3057 close(vmstatfd);
3058 vmstatfd = open(VMSTAT_FILE, O_RDONLY, 0);
3059+ if (vmstatfd == -1) {
3060+ snmp_log_perror("cannot open " VMSTAT_FILE);
3061+ return;
3062+ }
3063 }
3064 close(vmstatfd);
3065 if ( bytes_read < 0 ) {
3066@@ -246,7 +254,7 @@ void _cpu_load_swap_etc( char *buff, netsnmp_cpu_info *cpu ) {
3067 b = strstr(vmbuff, "pgpgin ");
3068 if (b) {
3069 sscanf(b, "pgpgin %llu", &pin);
3070- cpu->pageIn = (unsigned long)pin*2; /* ??? */
3071+ cpu->pageIn = (unsigned long long)pin*2; /* ??? */
3072 } else {
3073 if (first)
3074 snmp_log(LOG_ERR, "No pgpgin line in %s\n", VMSTAT_FILE);
3075@@ -255,7 +263,7 @@ void _cpu_load_swap_etc( char *buff, netsnmp_cpu_info *cpu ) {
3076 b = strstr(vmbuff, "pgpgout ");
3077 if (b) {
3078 sscanf(b, "pgpgout %llu", &pout);
3079- cpu->pageOut = (unsigned long)pout*2; /* ??? */
3080+ cpu->pageOut = (unsigned long long)pout*2; /* ??? */
3081 } else {
3082 if (first)
3083 snmp_log(LOG_ERR, "No pgpgout line in %s\n", VMSTAT_FILE);
3084@@ -264,7 +272,7 @@ void _cpu_load_swap_etc( char *buff, netsnmp_cpu_info *cpu ) {
3085 b = strstr(vmbuff, "pswpin ");
3086 if (b) {
3087 sscanf(b, "pswpin %llu", &swpin);
3088- cpu->swapIn = (unsigned long)swpin;
3089+ cpu->swapIn = (unsigned long long)swpin;
3090 } else {
3091 if (first)
3092 snmp_log(LOG_ERR, "No pswpin line in %s\n", VMSTAT_FILE);
3093@@ -273,7 +281,7 @@ void _cpu_load_swap_etc( char *buff, netsnmp_cpu_info *cpu ) {
3094 b = strstr(vmbuff, "pswpout ");
3095 if (b) {
3096 sscanf(b, "pswpout %llu", &swpout);
3097- cpu->swapOut = (unsigned long)swpout;
3098+ cpu->swapOut = (unsigned long long)swpout;
3099 } else {
3100 if (first)
3101 snmp_log(LOG_ERR, "No pswpout line in %s\n", VMSTAT_FILE);
3102@@ -284,8 +292,8 @@ void _cpu_load_swap_etc( char *buff, netsnmp_cpu_info *cpu ) {
3103 b = strstr(buff, "page ");
3104 if (b) {
3105 sscanf(b, "page %llu %llu", &pin, &pout);
3106- cpu->pageIn = (unsigned long)pin;
3107- cpu->pageOut = (unsigned long)pout;
3108+ cpu->pageIn = (unsigned long long)pin;
3109+ cpu->pageOut = (unsigned long long)pout;
3110 } else {
3111 if (first)
3112 snmp_log(LOG_ERR, "No page line in %s\n", STAT_FILE);
3113@@ -294,8 +302,8 @@ void _cpu_load_swap_etc( char *buff, netsnmp_cpu_info *cpu ) {
3114 b = strstr(buff, "swap ");
3115 if (b) {
3116 sscanf(b, "swap %llu %llu", &swpin, &swpout);
3117- cpu->swapIn = (unsigned long)swpin;
3118- cpu->swapOut = (unsigned long)swpout;
3119+ cpu->swapIn = (unsigned long long)swpin;
3120+ cpu->swapOut = (unsigned long long)swpout;
3121 } else {
3122 if (first)
3123 snmp_log(LOG_ERR, "No swap line in %s\n", STAT_FILE);
3124@@ -306,7 +314,7 @@ void _cpu_load_swap_etc( char *buff, netsnmp_cpu_info *cpu ) {
3125 b = strstr(buff, "intr ");
3126 if (b) {
3127 sscanf(b, "intr %llu %llu", &itot, &iticks);
3128- cpu->nInterrupts = (unsigned long)itot;
3129+ cpu->nInterrupts = (unsigned long long)itot;
3130 /* iticks not used? */
3131 } else {
3132 if (first)
3133@@ -315,7 +323,7 @@ void _cpu_load_swap_etc( char *buff, netsnmp_cpu_info *cpu ) {
3134 b = strstr(buff, "ctxt ");
3135 if (b) {
3136 sscanf(b, "ctxt %llu", &ctx);
3137- cpu->nCtxSwitches = (unsigned long)ctx;
3138+ cpu->nCtxSwitches = (unsigned long long)ctx;
3139 } else {
3140 if (first)
3141 snmp_log(LOG_ERR, "No ctxt line in %s\n", STAT_FILE);
3142diff --git a/agent/mibgroup/hardware/cpu/cpu_nlist.c b/agent/mibgroup/hardware/cpu/cpu_nlist.c
3143index b9554d7..974028a 100644
3144--- a/agent/mibgroup/hardware/cpu/cpu_nlist.c
3145+++ b/agent/mibgroup/hardware/cpu/cpu_nlist.c
3146@@ -76,12 +76,12 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
3147 auto_nlist( CPU_SYMBOL, (char *) cpu_stats, sizeof(cpu_stats));
3148 auto_nlist( MEM_SYMBOL, (char *)&mem_stats, sizeof(mem_stats));
3149
3150- cpu->user_ticks = (unsigned long)cpu_stats[CP_USER];
3151- cpu->nice_ticks = (unsigned long)cpu_stats[CP_NICE];
3152- cpu->sys2_ticks = (unsigned long)cpu_stats[CP_SYS]+cpu_stats[CP_INTR];
3153- cpu->idle_ticks = (unsigned long)cpu_stats[CP_IDLE];
3154- cpu->kern_ticks = (unsigned long)cpu_stats[CP_SYS];
3155- cpu->intrpt_ticks = (unsigned long)cpu_stats[CP_INTR];
3156+ cpu->user_ticks = (unsigned long long)cpu_stats[CP_USER];
3157+ cpu->nice_ticks = (unsigned long long)cpu_stats[CP_NICE];
3158+ cpu->sys2_ticks = (unsigned long long)cpu_stats[CP_SYS]+cpu_stats[CP_INTR];
3159+ cpu->idle_ticks = (unsigned long long)cpu_stats[CP_IDLE];
3160+ cpu->kern_ticks = (unsigned long long)cpu_stats[CP_SYS];
3161+ cpu->intrpt_ticks = (unsigned long long)cpu_stats[CP_INTR];
3162 /* wait_ticks, sirq_ticks unused */
3163
3164 /*
3165@@ -89,14 +89,14 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
3166 * XXX - Do these really belong here ?
3167 */
3168 #if defined(openbsd2) || defined(darwin)
3169- cpu->swapIn = (unsigned long)mem_stats.v_swpin;
3170- cpu->swapOut = (unsigned long)mem_stats.v_swpout;
3171+ cpu->swapIn = (unsigned long long)mem_stats.v_swpin;
3172+ cpu->swapOut = (unsigned long long)mem_stats.v_swpout;
3173 #else
3174- cpu->swapIn = (unsigned long)mem_stats.v_swappgsin+mem_stats.v_vnodepgsin;
3175- cpu->swapOut = (unsigned long)mem_stats.v_swappgsout+mem_stats.v_vnodepgsout;
3176+ cpu->swapIn = (unsigned long long)mem_stats.v_swappgsin+mem_stats.v_vnodepgsin;
3177+ cpu->swapOut = (unsigned long long)mem_stats.v_swappgsout+mem_stats.v_vnodepgsout;
3178 #endif
3179- cpu->nInterrupts = (unsigned long)mem_stats.v_intr;
3180- cpu->nCtxSwitches = (unsigned long)mem_stats.v_swtch;
3181+ cpu->nInterrupts = (unsigned long long)mem_stats.v_intr;
3182+ cpu->nCtxSwitches = (unsigned long long)mem_stats.v_swtch;
3183
3184 #ifdef PER_CPU_INFO
3185 for ( i = 0; i < n; i++ ) {
3186diff --git a/agent/mibgroup/hardware/cpu/cpu_pcp.c b/agent/mibgroup/hardware/cpu/cpu_pcp.c
3187index dcc2724..94c7b5c 100644
3188--- a/agent/mibgroup/hardware/cpu/cpu_pcp.c
3189+++ b/agent/mibgroup/hardware/cpu/cpu_pcp.c
3190@@ -153,13 +153,13 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
3191 exit(1);
3192 }
3193
3194- cpu->wait_ticks = (unsigned long)resp->vset[CPUWAIT]->vlist[0].value.lval / 10;
3195- cpu->intrpt_ticks = (unsigned long)resp->vset[CPUINTR]->vlist[0].value.lval / 10;
3196+ cpu->wait_ticks = (unsigned long long)resp->vset[CPUWAIT]->vlist[0].value.lval / 10;
3197+ cpu->intrpt_ticks = (unsigned long long)resp->vset[CPUINTR]->vlist[0].value.lval / 10;
3198 /*cpu->sirq_ticks = (unsigned long)csoftll / 10;*/
3199- cpu->user_ticks = (unsigned long)resp->vset[CPUUSER]->vlist[0].value.lval / 10;
3200+ cpu->user_ticks = (unsigned long long)resp->vset[CPUUSER]->vlist[0].value.lval / 10;
3201 /*cpu->nice_ticks = (unsigned long)cicell / 10;*/
3202- cpu->sys_ticks = (unsigned long)resp->vset[CPUSYS]->vlist[0].value.lval / 10;
3203- cpu->idle_ticks = (unsigned long)resp->vset[CPUIDLE]->vlist[0].value.lval / 10;
3204+ cpu->sys_ticks = (unsigned long long)resp->vset[CPUSYS]->vlist[0].value.lval / 10;
3205+ cpu->idle_ticks = (unsigned long long)resp->vset[CPUIDLE]->vlist[0].value.lval / 10;
3206
3207
3208 /*
3209@@ -168,12 +168,12 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
3210 */
3211 /*cpu = netsnmp_cpu_get_byIdx( -1, 0 );*/
3212 /*_cpu_load_swap_etc( buff, cpu );*/
3213- cpu->pageIn = (unsigned long)resp->vset[PAGESIN]->vlist[0].value.lval;
3214- cpu->pageOut = (unsigned long)resp->vset[PAGESOUT]->vlist[0].value.lval;
3215- cpu->swapIn = (unsigned long)resp->vset[SWAPIN]->vlist[0].value.lval;
3216- cpu->swapOut = (unsigned long)resp->vset[SWAPOUT]->vlist[0].value.lval;
3217- cpu->nInterrupts = (unsigned long)resp->vset[INTR]->vlist[0].value.lval;
3218- cpu->nCtxSwitches = (unsigned long)resp->vset[CTXT]->vlist[0].value.lval;
3219+ cpu->pageIn = (unsigned long long)resp->vset[PAGESIN]->vlist[0].value.lval;
3220+ cpu->pageOut = (unsigned long long)resp->vset[PAGESOUT]->vlist[0].value.lval;
3221+ cpu->swapIn = (unsigned long long)resp->vset[SWAPIN]->vlist[0].value.lval;
3222+ cpu->swapOut = (unsigned long long)resp->vset[SWAPOUT]->vlist[0].value.lval;
3223+ cpu->nInterrupts = (unsigned long long)resp->vset[INTR]->vlist[0].value.lval;
3224+ cpu->nCtxSwitches = (unsigned long long)resp->vset[CTXT]->vlist[0].value.lval;
3225
3226 /*
3227 * XXX - TODO: extract per-CPU statistics
3228diff --git a/agent/mibgroup/hardware/cpu/cpu_perfstat.c b/agent/mibgroup/hardware/cpu/cpu_perfstat.c
3229index 981656d..5f58190 100644
3230--- a/agent/mibgroup/hardware/cpu/cpu_perfstat.c
3231+++ b/agent/mibgroup/hardware/cpu/cpu_perfstat.c
3232@@ -58,27 +58,27 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
3233 sizeof(perfstat_cpu_total_t), 1) > 0) {
3234
3235 /* Returns 'u_longlong_t' statistics */
3236- cpu->user_ticks = (unsigned long)cs.user / cs.ncpus;
3237- cpu->sys_ticks = ((unsigned long)cs.sys + (unsigned long)cs.wait) / cs.ncpus;
3238- cpu->kern_ticks = (unsigned long)cs.sys / cs.ncpus;
3239- cpu->wait_ticks = (unsigned long)cs.wait / cs.ncpus;
3240- cpu->idle_ticks = (unsigned long)cs.idle / cs.ncpus;
3241+ cpu->user_ticks = (unsigned long long)cs.user / cs.ncpus;
3242+ cpu->sys_ticks = ((unsigned long long)cs.sys + (unsigned long long)cs.wait) / cs.ncpus;
3243+ cpu->kern_ticks = (unsigned long long)cs.sys / cs.ncpus;
3244+ cpu->wait_ticks = (unsigned long long)cs.wait / cs.ncpus;
3245+ cpu->idle_ticks = (unsigned long long)cs.idle / cs.ncpus;
3246 /* intrpt_ticks, sirq_ticks, nice_ticks unused */
3247
3248 /*
3249 * Interrupt/Context Switch statistics
3250 * XXX - Do these really belong here ?
3251 */
3252- cpu->pageIn = (unsigned long)cs.sysread;
3253- cpu->pageOut = (unsigned long)cs.syswrite;
3254- cpu->nInterrupts = (unsigned long)cs.devintrs + cs.softintrs;
3255- cpu->nCtxSwitches = (unsigned long)cs.pswitch;
3256+ cpu->pageIn = (unsigned long long)cs.sysread;
3257+ cpu->pageOut = (unsigned long long)cs.syswrite;
3258+ cpu->nInterrupts = (unsigned long long)cs.devintrs + cs.softintrs;
3259+ cpu->nCtxSwitches = (unsigned long long)cs.pswitch;
3260 }
3261
3262 if (perfstat_memory_total((perfstat_id_t *)NULL, &ms,
3263 sizeof(perfstat_memory_total_t), 1) > 0) {
3264- cpu->swapIn = (unsigned long)ms.pgspins;
3265- cpu->swapOut = (unsigned long)ms.pgspouts;
3266+ cpu->swapIn = (unsigned long long)ms.pgspins;
3267+ cpu->swapOut = (unsigned long long)ms.pgspouts;
3268 }
3269
3270
3271@@ -91,14 +91,14 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
3272 if (perfstat_cpu(&name, cs2, sizeof(perfstat_cpu_t), n) > 0) {
3273 for ( i = 0; i < n; i++ ) {
3274 cpu = netsnmp_cpu_get_byIdx( i, 0 );
3275- cpu->user_ticks = (unsigned long)cs2[i].user;
3276- cpu->sys_ticks = (unsigned long)cs2[i].sys + (unsigned long)cs2[i].wait;
3277- cpu->kern_ticks = (unsigned long)cs2[i].sys;
3278- cpu->wait_ticks = (unsigned long)cs2[i].wait;
3279- cpu->idle_ticks = (unsigned long)cs2[i].idle;
3280- cpu->pageIn = (unsigned long)cs2[i].sysread;
3281- cpu->pageOut = (unsigned long)cs2[i].syswrite;
3282- cpu->nCtxSwitches = (unsigned long)cs2[i].pswitch;
3283+ cpu->user_ticks = (unsigned long long)cs2[i].user;
3284+ cpu->sys_ticks = (unsigned long long)cs2[i].sys + (unsigned long long)cs2[i].wait;
3285+ cpu->kern_ticks = (unsigned long long)cs2[i].sys;
3286+ cpu->wait_ticks = (unsigned long long)cs2[i].wait;
3287+ cpu->idle_ticks = (unsigned long long)cs2[i].idle;
3288+ cpu->pageIn = (unsigned long long)cs2[i].sysread;
3289+ cpu->pageOut = (unsigned long long)cs2[i].syswrite;
3290+ cpu->nCtxSwitches = (unsigned long long)cs2[i].pswitch;
3291 /* Interrupt stats only apply overall, not per-CPU */
3292 }
3293 } else {
3294diff --git a/agent/mibgroup/hardware/cpu/cpu_pstat.c b/agent/mibgroup/hardware/cpu/cpu_pstat.c
3295index c68739b..35c1d63 100644
3296--- a/agent/mibgroup/hardware/cpu/cpu_pstat.c
3297+++ b/agent/mibgroup/hardware/cpu/cpu_pstat.c
3298@@ -72,13 +72,13 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
3299
3300 pstat_getdynamic(&psd, sizeof(psd), 1, 0);
3301 /* XXX - Compare cpu_num against psd.psd_proc_cnt */
3302- cpu->user_ticks = (unsigned long)psd.psd_cpu_time[CP_USER];
3303- cpu->nice_ticks = (unsigned long)psd.psd_cpu_time[CP_NICE];
3304- cpu->sys2_ticks = (unsigned long)psd.psd_cpu_time[CP_SYS]+
3305+ cpu->user_ticks = (unsigned long long)psd.psd_cpu_time[CP_USER];
3306+ cpu->nice_ticks = (unsigned long long)psd.psd_cpu_time[CP_NICE];
3307+ cpu->sys2_ticks = (unsigned long long)psd.psd_cpu_time[CP_SYS]+
3308 psd.psd_cpu_time[CP_WAIT];
3309- cpu->idle_ticks = (unsigned long)psd.psd_cpu_time[CP_IDLE];
3310- cpu->wait_ticks = (unsigned long)psd.psd_cpu_time[CP_WAIT];
3311- cpu->kern_ticks = (unsigned long)psd.psd_cpu_time[CP_SYS];
3312+ cpu->idle_ticks = (unsigned long long)psd.psd_cpu_time[CP_IDLE];
3313+ cpu->wait_ticks = (unsigned long long)psd.psd_cpu_time[CP_WAIT];
3314+ cpu->kern_ticks = (unsigned long long)psd.psd_cpu_time[CP_SYS];
3315 /* XXX - record (sum of) "all other ticks" */
3316 /* intrpt_ticks, sirq_ticks unused */
3317
3318@@ -87,21 +87,21 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
3319 * XXX - Do these really belong here ?
3320 */
3321 pstat_getvminfo(&psv, sizeof(psv), 1, 0);
3322- cpu->swapIn = (unsigned long)psv.psv_sswpin;
3323- cpu->swapOut = (unsigned long)psv.psv_sswpout;
3324- cpu->nInterrupts = (unsigned long)psv.psv_sintr;
3325- cpu->nCtxSwitches = (unsigned long)psv.psv_sswtch;
3326+ cpu->swapIn = (unsigned long long)psv.psv_sswpin;
3327+ cpu->swapOut = (unsigned long long)psv.psv_sswpout;
3328+ cpu->nInterrupts = (unsigned long long)psv.psv_sintr;
3329+ cpu->nCtxSwitches = (unsigned long long)psv.psv_sswtch;
3330
3331
3332 for ( i = 0; i < psd.psd_proc_cnt; i++ ) {
3333 cpu = netsnmp_cpu_get_byIdx( i, 0 );
3334- cpu->user_ticks = (unsigned long)psd.psd_mp_cpu_time[i][CP_USER];
3335- cpu->nice_ticks = (unsigned long)psd.psd_mp_cpu_time[i][CP_NICE];
3336- cpu->sys2_ticks = (unsigned long)psd.psd_mp_cpu_time[i][CP_SYS]+
3337+ cpu->user_ticks = (unsigned long long)psd.psd_mp_cpu_time[i][CP_USER];
3338+ cpu->nice_ticks = (unsigned long long)psd.psd_mp_cpu_time[i][CP_NICE];
3339+ cpu->sys2_ticks = (unsigned long long)psd.psd_mp_cpu_time[i][CP_SYS]+
3340 psd.psd_mp_cpu_time[i][CP_WAIT];
3341- cpu->idle_ticks = (unsigned long)psd.psd_mp_cpu_time[i][CP_IDLE];
3342- cpu->wait_ticks = (unsigned long)psd.psd_mp_cpu_time[i][CP_WAIT];
3343- cpu->kern_ticks = (unsigned long)psd.psd_mp_cpu_time[i][CP_SYS];
3344+ cpu->idle_ticks = (unsigned long long)psd.psd_mp_cpu_time[i][CP_IDLE];
3345+ cpu->wait_ticks = (unsigned long long)psd.psd_mp_cpu_time[i][CP_WAIT];
3346+ cpu->kern_ticks = (unsigned long long)psd.psd_mp_cpu_time[i][CP_SYS];
3347 /* XXX - record (sum of) "all other ticks" */
3348 }
3349
3350diff --git a/agent/mibgroup/hardware/cpu/cpu_sysctl.c b/agent/mibgroup/hardware/cpu/cpu_sysctl.c
3351index e549671..5599a58 100644
3352--- a/agent/mibgroup/hardware/cpu/cpu_sysctl.c
3353+++ b/agent/mibgroup/hardware/cpu/cpu_sysctl.c
3354@@ -40,23 +40,25 @@ void _cpu_copy_stats( netsnmp_cpu_info *cpu );
3355 * (including descriptions)
3356 */
3357 void init_cpu_sysctl( void ) {
3358- int n;
3359- size_t i;
3360+ int i, n;
3361+ size_t siz;
3362 int ncpu_mib[] = { CTL_HW, HW_NCPU };
3363+#if !(defined(__NetBSD__) && ( defined(__i386__) || defined(__x86_64__) ) )
3364 int model_mib[] = { CTL_HW, HW_MODEL };
3365+#endif
3366 char descr[ SNMP_MAXBUF ];
3367 netsnmp_cpu_info *cpu = netsnmp_cpu_get_byIdx( -1, 1 );
3368 strcpy(cpu->name, "Overall CPU statistics");
3369
3370- i = sizeof(n);
3371- sysctl(ncpu_mib, 2, &n, &i, NULL, 0);
3372+ siz = sizeof(n);
3373+ sysctl(ncpu_mib, 2, &n, &siz, NULL, 0);
3374 if ( n <= 0 )
3375 n = 1; /* Single CPU system */
3376- i = sizeof(descr);
3377+ siz = sizeof(descr);
3378 #if defined(__NetBSD__) && ( defined(__i386__) || defined(__x86_64__) )
3379- sysctlbyname("machdep.cpu_brand", descr, (void *)&i, NULL, 0);
3380+ sysctlbyname("machdep.cpu_brand", descr, &siz, NULL, 0);
3381 #else
3382- sysctl(model_mib, 2, descr, &i, NULL, 0);
3383+ sysctl(model_mib, 2, descr, &siz, NULL, 0);
3384 #endif
3385 for ( i = 0; i < n; i++ ) {
3386 cpu = netsnmp_cpu_get_byIdx( i, 1 );
3387@@ -176,12 +178,12 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
3388 #else
3389 sysctl(cpu_mib, 2, cpu_stats, &cpu_size, NULL, 0);
3390 #endif
3391- cpu->user_ticks = (unsigned long)cpu_stats[CP_USER];
3392- cpu->nice_ticks = (unsigned long)cpu_stats[CP_NICE];
3393- cpu->sys2_ticks = (unsigned long)cpu_stats[CP_SYS]+cpu_stats[CP_INTR];
3394- cpu->kern_ticks = (unsigned long)cpu_stats[CP_SYS];
3395- cpu->idle_ticks = (unsigned long)cpu_stats[CP_IDLE];
3396- cpu->intrpt_ticks = (unsigned long)cpu_stats[CP_INTR];
3397+ cpu->user_ticks = (unsigned long long)cpu_stats[CP_USER];
3398+ cpu->nice_ticks = (unsigned long long)cpu_stats[CP_NICE];
3399+ cpu->sys2_ticks = (unsigned long long)cpu_stats[CP_SYS]+cpu_stats[CP_INTR];
3400+ cpu->kern_ticks = (unsigned long long)cpu_stats[CP_SYS];
3401+ cpu->idle_ticks = (unsigned long long)cpu_stats[CP_IDLE];
3402+ cpu->intrpt_ticks = (unsigned long long)cpu_stats[CP_INTR];
3403 /* wait_ticks, sirq_ticks unused */
3404
3405 /*
3406@@ -189,15 +191,15 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) {
3407 * XXX - Do these really belong here ?
3408 */
3409 sysctl(mem_mib, 2, &mem_stats, &mem_size, NULL, 0);
3410- cpu->nInterrupts = (unsigned long)mem_stats.NS_VM_INTR;
3411- cpu->nCtxSwitches = (unsigned long)mem_stats.NS_VM_SWTCH;
3412- cpu->swapIn = (unsigned long)mem_stats.NS_VM_SWAPIN;
3413- cpu->swapOut = (unsigned long)mem_stats.NS_VM_SWAPOUT;
3414+ cpu->nInterrupts = (unsigned long long)mem_stats.NS_VM_INTR;
3415+ cpu->nCtxSwitches = (unsigned long long)mem_stats.NS_VM_SWTCH;
3416+ cpu->swapIn = (unsigned long long)mem_stats.NS_VM_SWAPIN;
3417+ cpu->swapOut = (unsigned long long)mem_stats.NS_VM_SWAPOUT;
3418 #ifdef NS_VM_PAGEIN
3419- cpu->pageIn = (unsigned long)mem_stats.NS_VM_PAGEIN;
3420+ cpu->pageIn = (unsigned long long)mem_stats.NS_VM_PAGEIN;
3421 #endif
3422 #ifdef NS_VM_PAGEOUT
3423- cpu->pageOut = (unsigned long)mem_stats.NS_VM_PAGEOUT;
3424+ cpu->pageOut = (unsigned long long)mem_stats.NS_VM_PAGEOUT;
3425 #endif
3426
3427 #ifdef NETSNMP_KERN_MCPU
3428diff --git a/agent/mibgroup/hardware/cpu/cpu_sysinfo.c b/agent/mibgroup/hardware/cpu/cpu_sysinfo.c
3429index d510308..ed1f357 100644
3430--- a/agent/mibgroup/hardware/cpu/cpu_sysinfo.c
3431+++ b/agent/mibgroup/hardware/cpu/cpu_sysinfo.c
3432@@ -91,20 +91,20 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic )
3433 }
3434
3435 DEBUGMSGTL(("cpu_sysinfo", "total cpu kernel: %lu\n", sinfo_gen->cpu[CPU_KERNEL]));
3436- cpu->sys2_ticks = (unsigned long) sinfo_gen->cpu[CPU_KERNEL] + (unsigned long) sinfo_gen->cpu[CPU_SXBRK] + (unsigned long) sinfo_gen->cpu[CPU_INTR];
3437- cpu->kern_ticks = (unsigned long) sinfo_gen->cpu[CPU_KERNEL];
3438- cpu->intrpt_ticks = (unsigned long) sinfo_gen->cpu[CPU_INTR];
3439- cpu->user_ticks = (unsigned long) sinfo_gen->cpu[CPU_USER];
3440- cpu->wait_ticks = (unsigned long) sinfo_gen->cpu[CPU_WAIT];
3441- cpu->idle_ticks = (unsigned long) sinfo_gen->cpu[CPU_IDLE];
3442+ cpu->sys2_ticks = (unsigned long long) sinfo_gen->cpu[CPU_KERNEL] + (unsigned long long) sinfo_gen->cpu[CPU_SXBRK] + (unsigned long long) sinfo_gen->cpu[CPU_INTR];
3443+ cpu->kern_ticks = (unsigned long long) sinfo_gen->cpu[CPU_KERNEL];
3444+ cpu->intrpt_ticks = (unsigned long long) sinfo_gen->cpu[CPU_INTR];
3445+ cpu->user_ticks = (unsigned long long) sinfo_gen->cpu[CPU_USER];
3446+ cpu->wait_ticks = (unsigned long long) sinfo_gen->cpu[CPU_WAIT];
3447+ cpu->idle_ticks = (unsigned long long) sinfo_gen->cpu[CPU_IDLE];
3448
3449 /* XXX - Do these really belong here ? */
3450- cpu->pageIn = (unsigned long)0;
3451- cpu->pageOut = (unsigned long)0;
3452- cpu->swapIn = (unsigned long)sinfo_gen->swapin;
3453- cpu->swapOut = (unsigned long)sinfo_gen->swapout;
3454- cpu->nInterrupts = (unsigned long)sinfo_gen->intr_svcd;
3455- cpu->nCtxSwitches = (unsigned long)sinfo_gen->pswitch;
3456+ cpu->pageIn = (unsigned long long)0;
3457+ cpu->pageOut = (unsigned long long)0;
3458+ cpu->swapIn = (unsigned long long)sinfo_gen->swapin;
3459+ cpu->swapOut = (unsigned long long)sinfo_gen->swapout;
3460+ cpu->nInterrupts = (unsigned long long)sinfo_gen->intr_svcd;
3461+ cpu->nCtxSwitches = (unsigned long long)sinfo_gen->pswitch;
3462
3463 /* fetch individual cpu stats */
3464
3465@@ -120,11 +120,11 @@ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic )
3466 cpu = netsnmp_cpu_get_byIdx(i, 0);
3467
3468 DEBUGMSGTL(("cpu_sysinfo", "cpu %u kernel: %lu\n", i, sinfo_cpus[i].cpu[CPU_KERNEL]));
3469- cpu->sys2_ticks = (unsigned long)sinfo_cpus[i].cpu[CPU_KERNEL] + (unsigned long) sinfo_cpus[i].cpu[CPU_SXBRK] + (unsigned long)sinfo_cpus[i].cpu[CPU_INTR];
3470- cpu->intrpt_ticks = (unsigned long)sinfo_cpus[i].cpu[CPU_INTR];
3471- cpu->user_ticks = (unsigned long)sinfo_cpus[i].cpu[CPU_USER];
3472- cpu->wait_ticks = (unsigned long)sinfo_cpus[i].cpu[CPU_WAIT];
3473- cpu->idle_ticks = (unsigned long)sinfo_cpus[i].cpu[CPU_IDLE];
3474+ cpu->sys2_ticks = (unsigned long long)sinfo_cpus[i].cpu[CPU_KERNEL] + (unsigned long long) sinfo_cpus[i].cpu[CPU_SXBRK] + (unsigned long long)sinfo_cpus[i].cpu[CPU_INTR];
3475+ cpu->intrpt_ticks = (unsigned long long)sinfo_cpus[i].cpu[CPU_INTR];
3476+ cpu->user_ticks = (unsigned long long)sinfo_cpus[i].cpu[CPU_USER];
3477+ cpu->wait_ticks = (unsigned long long)sinfo_cpus[i].cpu[CPU_WAIT];
3478+ cpu->idle_ticks = (unsigned long long)sinfo_cpus[i].cpu[CPU_IDLE];
3479 }
3480
3481 return 0;
3482diff --git a/agent/mibgroup/hardware/fsys/fsys_getfsstats.c b/agent/mibgroup/hardware/fsys/fsys_getfsstats.c
3483index 55327b7..93f38ce 100644
3484--- a/agent/mibgroup/hardware/fsys/fsys_getfsstats.c
3485+++ b/agent/mibgroup/hardware/fsys/fsys_getfsstats.c
3486@@ -164,7 +164,7 @@ netsnmp_fsys_arch_load( void )
3487 entry->type = _fs_type( stats[i].f_fstypename );
3488 entry->flags |= NETSNMP_FS_FLAG_ACTIVE;
3489
3490- if (! stats[i].NSFS_FLAGS & MNT_LOCAL ) {
3491+ if (! (stats[i].NSFS_FLAGS & MNT_LOCAL )) {
3492 entry->flags |= NETSNMP_FS_FLAG_REMOTE;
3493 }
3494 if ( stats[i].NSFS_FLAGS & MNT_RDONLY ) {
3495@@ -175,4 +175,6 @@ netsnmp_fsys_arch_load( void )
3496 }
3497 netsnmp_fsys_calculate32(entry);
3498 }
3499+
3500+ free(stats);
3501 }
3502diff --git a/agent/mibgroup/hardware/fsys/fsys_mntctl.c b/agent/mibgroup/hardware/fsys/fsys_mntctl.c
3503index e65d6d5..3ad68d4 100644
3504--- a/agent/mibgroup/hardware/fsys/fsys_mntctl.c
3505+++ b/agent/mibgroup/hardware/fsys/fsys_mntctl.c
3506@@ -128,9 +128,9 @@ netsnmp_fsys_arch_load( void )
3507 continue;
3508 }
3509
3510- strncpy( entry->path, path, sizeof( entry->path ));
3511- strncpy( entry->device, vmt2dataptr( aixcurr, VMT_STUB),
3512- sizeof( entry->device ));
3513+ strlcpy(entry->path, path, sizeof(entry->path));
3514+ strlcpy(entry->device, vmt2dataptr(aixcurr, VMT_STUB),
3515+ sizeof(entry->device));
3516 entry->type = _fsys_type( aixcurr->vmt_gfstype );
3517
3518 if (!(entry->type & _NETSNMP_FS_TYPE_SKIP_BIT))
3519diff --git a/agent/mibgroup/hardware/fsys/fsys_mntent.c b/agent/mibgroup/hardware/fsys/fsys_mntent.c
3520index 1a156f4..c380365 100644
3521--- a/agent/mibgroup/hardware/fsys/fsys_mntent.c
3522+++ b/agent/mibgroup/hardware/fsys/fsys_mntent.c
3523@@ -135,6 +135,9 @@ _fsys_type( char *typename )
3524 !strcmp(typename, MNTTYPE_GFS2) ||
3525 !strcmp(typename, MNTTYPE_XFS) ||
3526 !strcmp(typename, MNTTYPE_JFS) ||
3527+ !strcmp(typename, MNTTYPE_VXFS) ||
3528+ !strcmp(typename, MNTTYPE_REISERFS) ||
3529+ !strcmp(typename, MNTTYPE_OCFS2) ||
3530 !strcmp(typename, MNTTYPE_LOFS))
3531 return NETSNMP_FS_TYPE_OTHER;
3532
3533@@ -190,11 +193,9 @@ netsnmp_fsys_arch_load( void )
3534 continue;
3535 }
3536
3537- strncpy( entry->path, m->NSFS_PATH, sizeof( entry->path ));
3538- entry->path[sizeof(entry->path)-1] = '\0';
3539- strncpy( entry->device, m->NSFS_DEV, sizeof( entry->device ));
3540- entry->device[sizeof(entry->device)-1] = '\0';
3541- entry->type = _fsys_type( m->NSFS_TYPE );
3542+ strlcpy(entry->path, m->NSFS_PATH, sizeof(entry->path));
3543+ strlcpy(entry->device, m->NSFS_DEV, sizeof(entry->device));
3544+ entry->type = _fsys_type(m->NSFS_TYPE);
3545 if (!(entry->type & _NETSNMP_FS_TYPE_SKIP_BIT))
3546 entry->flags |= NETSNMP_FS_FLAG_ACTIVE;
3547
3548diff --git a/agent/mibgroup/hardware/fsys/hw_fsys.c b/agent/mibgroup/hardware/fsys/hw_fsys.c
3549index c96284e..a6cd94d 100644
3550--- a/agent/mibgroup/hardware/fsys/hw_fsys.c
3551+++ b/agent/mibgroup/hardware/fsys/hw_fsys.c
3552@@ -3,6 +3,9 @@
3553 #include <net-snmp/net-snmp-includes.h>
3554 #include <net-snmp/agent/net-snmp-agent-includes.h>
3555 #include <net-snmp/agent/hardware/fsys.h>
3556+#ifdef HAVE_INTTYPES_H
3557+#include <inttypes.h>
3558+#endif
3559
3560 netsnmp_feature_child_of(hw_fsys_get_container, netsnmp_unused)
3561
3562@@ -174,9 +177,8 @@ netsnmp_fsys_by_path( char *path, int create_type )
3563 * ... so let's create a new one
3564 */
3565 sp = _fsys_create_entry();
3566- if ( sp ) {
3567- strncpy( sp->path, path, sizeof(sp->path) );
3568- }
3569+ if (sp)
3570+ strlcpy(sp->path, path, sizeof(sp->path));
3571 return sp;
3572 }
3573
3574@@ -217,9 +219,8 @@ netsnmp_fsys_by_device( char *device, int create_type )
3575 * ... so let's create a new one
3576 */
3577 sp = _fsys_create_entry();
3578- if ( sp ) {
3579- strncpy( sp->device, device, sizeof(sp->device) );
3580- }
3581+ if (sp)
3582+ strlcpy(sp->device, device, sizeof(sp->device));
3583 return sp;
3584 }
3585
3586@@ -242,7 +243,7 @@ _fsys_create_entry( void )
3587 sp->idx.oids[0] = ++_fsys_idx;
3588 }
3589
3590- DEBUGMSGTL(("fsys:new", "Create filesystem entry (index = %d\n", _fsys_idx));
3591+ DEBUGMSGTL(("fsys:new", "Create filesystem entry (index = %d)\n", _fsys_idx));
3592 CONTAINER_INSERT( _fsys_container, sp );
3593 return sp;
3594 }
3595@@ -319,21 +320,30 @@ netsnmp_fsys_avail( netsnmp_fsys_info *f) {
3596 #define INT32_MAX 0x7fffffff
3597 #endif
3598
3599+#ifndef PRIu64
3600+#define PRIu64 "llu"
3601+#endif
3602+
3603 /* recalculate f->size_32, used_32, avail_32 and units_32 from f->size & comp.*/
3604 void
3605-netsnmp_fsys_calculate32( netsnmp_fsys_info *f)
3606+netsnmp_fsys_calculate32(netsnmp_fsys_info *f)
3607 {
3608 unsigned long long s = f->size;
3609- unsigned long long u = f->units;
3610- int factor = 0;
3611+ unsigned shift = 0;
3612+
3613 while (s > INT32_MAX) {
3614 s = s >> 1;
3615- u = u << 1;
3616- factor++;
3617+ shift++;
3618 }
3619
3620 f->size_32 = s;
3621- f->units_32 = u;
3622- f->avail_32 = f->avail << factor;
3623- f->used_32 = f->used << factor;
3624+ f->units_32 = f->units << shift;
3625+ f->avail_32 = f->avail >> shift;
3626+ f->used_32 = f->used >> shift;
3627+
3628+ DEBUGMSGTL(("fsys", "Results of 32-bit conversion: size %" PRIu64 " -> %lu;"
3629+ " units %" PRIu64 " -> %lu; avail %" PRIu64 " -> %lu;"
3630+ " used %" PRIu64 " -> %lu\n",
3631+ (uint64_t)f->size, f->size_32, (uint64_t)f->units, f->units_32,
3632+ (uint64_t)f->avail, f->avail_32, (uint64_t)f->used, f->used_32));
3633 }
3634diff --git a/agent/mibgroup/hardware/fsys/mnttypes.h b/agent/mibgroup/hardware/fsys/mnttypes.h
3635index f6d96fe..9183451 100644
3636--- a/agent/mibgroup/hardware/fsys/mnttypes.h
3637+++ b/agent/mibgroup/hardware/fsys/mnttypes.h
3638@@ -90,9 +90,6 @@
3639 #ifndef MNTTYPE_PC
3640 #define MNTTYPE_PC "pc"
3641 #endif
3642-#ifndef MNTTYPE_REISERFS
3643-#define MNTTYPE_REISERFS "reiserfs"
3644-#endif
3645 #ifndef MNTTYPE_SMBFS
3646 #define MNTTYPE_SMBFS "smbfs"
3647 #endif
3648@@ -108,30 +105,48 @@
3649 #ifndef MNTTYPE_VFAT
3650 #define MNTTYPE_VFAT "vfat"
3651 #endif
3652+
3653+/*
3654+ * File systems to monitor, but not covered by HR-TYPES enumerations
3655+ */
3656+#ifndef MNTTYPE_MVFS
3657+#define MNTTYPE_MVFS "mvfs"
3658+#endif
3659+#ifndef MNTTYPE_TMPFS
3660+#define MNTTYPE_TMPFS "tmpfs"
3661+#endif
3662 #ifndef MNTTYPE_GFS
3663 #define MNTTYPE_GFS "gfs"
3664 #endif
3665 #ifndef MNTTYPE_GFS2
3666 #define MNTTYPE_GFS2 "gfs2"
3667 #endif
3668-
3669-/*
3670- * File systems to monitor, but not covered by HR-TYPES enumerations
3671- */
3672+#ifndef MNTTYPE_XFS
3673+#define MNTTYPE_XFS "xfs"
3674+#endif
3675+#ifndef MNTTYPE_JFS
3676+#define MNTTYPE_JFS "jfs"
3677+#endif
3678+#ifndef MNTTYPE_VXFS
3679+#define MNTTYPE_VXFS "vxfs"
3680+#endif
3681+#ifndef MNTTYPE_REISERFS
3682+#define MNTTYPE_REISERFS "reiserfs"
3683+#endif
3684 #ifndef MNTTYPE_LOFS
3685 #define MNTTYPE_LOFS "lofs"
3686 #endif
3687-#ifndef MNTTYPE_APP
3688-#define MNTTYPE_APP "app"
3689-#endif
3690-#ifndef MNTTYPE_MVFS
3691-#define MNTTYPE_MVFS "mvfs"
3692+#ifndef MNTTYPE_OCFS2
3693+#define MNTTYPE_OCFS2 "ocfs2"
3694 #endif
3695
3696 /*
3697 * File systems to skip
3698 * (Probably not strictly needed)
3699 */
3700+#ifndef MNTTYPE_APP
3701+#define MNTTYPE_APP "app"
3702+#endif
3703 #ifndef MNTTYPE_DEVPTS
3704 #define MNTTYPE_DEVPTS "devpts"
3705 #endif
3706@@ -144,9 +159,6 @@
3707 #ifndef MNTTYPE_SYSFS
3708 #define MNTTYPE_SYSFS "sysfs"
3709 #endif
3710-#ifndef MNTTYPE_TMPFS
3711-#define MNTTYPE_TMPFS "tmpfs"
3712-#endif
3713 #ifndef MNTTYPE_USBFS
3714 #define MNTTYPE_USBFS "usbfs"
3715 #endif
3716@@ -156,12 +168,5 @@
3717 #ifndef MNTTYPE_RPCPIPE
3718 #define MNTTYPE_RPCPIPE "rpc_pipefs"
3719 #endif
3720-#ifndef MNTTYPE_XFS
3721-#define MNTTYPE_XFS "xfs"
3722-#endif
3723-#ifndef MNTTYPE_JFS
3724-#define MNTTYPE_JFS "jfs"
3725-#endif
3726-
3727
3728 #endif /* _NETSNMP_FSYS_MNTTYPES_H */
3729diff --git a/agent/mibgroup/hardware/memory/memory_linux.c b/agent/mibgroup/hardware/memory/memory_linux.c
3730index 89abf57..8c189c5 100644
3731--- a/agent/mibgroup/hardware/memory/memory_linux.c
3732+++ b/agent/mibgroup/hardware/memory/memory_linux.c
3733@@ -46,6 +46,7 @@ int netsnmp_mem_arch_load( netsnmp_cache *cache, void *magic ) {
3734 buff = (char*)malloc(bsize+1);
3735 if (NULL == buff) {
3736 snmp_log(LOG_ERR, "malloc failed\n");
3737+ close(statfd);
3738 return -1;
3739 }
3740 }
3741@@ -53,6 +54,7 @@ int netsnmp_mem_arch_load( netsnmp_cache *cache, void *magic ) {
3742 b = (char*)realloc(buff, bsize + MEMINFO_STEP_SIZE + 1);
3743 if (NULL == b) {
3744 snmp_log(LOG_ERR, "malloc failed\n");
3745+ close(statfd);
3746 return -1;
3747 }
3748 buff = b;
3749@@ -89,13 +91,19 @@ int netsnmp_mem_arch_load( netsnmp_cache *cache, void *magic ) {
3750 if (first)
3751 snmp_log(LOG_ERR, "No MemFree line in /proc/meminfo\n");
3752 }
3753- b = strstr(buff, "MemShared: ");
3754- if (b)
3755- sscanf(b, "MemShared: %lu", &memshared);
3756+ if (0 == netsnmp_os_prematch("Linux","2.4")) {
3757+ b = strstr(buff, "MemShared: ");
3758+ if (b)
3759+ sscanf(b, "MemShared: %lu", &memshared);
3760+ else if (first)
3761+ snmp_log(LOG_ERR, "No MemShared line in /proc/meminfo\n");
3762+ }
3763 else {
3764- if (first)
3765- if (0 == netsnmp_os_prematch("Linux","2.4"))
3766- snmp_log(LOG_ERR, "No MemShared line in /proc/meminfo\n");
3767+ b = strstr(buff, "Shmem: ");
3768+ if (b)
3769+ sscanf(b, "Shmem: %lu", &memshared);
3770+ else if (first)
3771+ snmp_log(LOG_ERR, "No Shmem line in /proc/meminfo\n");
3772 }
3773 b = strstr(buff, "Buffers: ");
3774 if (b)
3775@@ -155,8 +163,6 @@ int netsnmp_mem_arch_load( netsnmp_cache *cache, void *magic ) {
3776 mem->other = -1;
3777 }
3778
3779- /* Shared memory is not reported by Linux 2.6 kernel */
3780- if (0 != netsnmp_os_prematch("Linux","2.6")) {
3781 mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SHARED, 1 );
3782 if (!mem) {
3783 snmp_log_perror("No Shared Memory info entry");
3784@@ -165,10 +171,9 @@ int netsnmp_mem_arch_load( netsnmp_cache *cache, void *magic ) {
3785 mem->descr = strdup("Shared memory");
3786 mem->units = 1024;
3787 mem->size = memshared;
3788- mem->free = -1;
3789+ mem->free = 0; /* All in use */
3790 mem->other = -1;
3791 }
3792- }
3793
3794 mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_CACHED, 1 );
3795 if (!mem) {
3796diff --git a/agent/mibgroup/hardware/sensors/hw_sensors.c b/agent/mibgroup/hardware/sensors/hw_sensors.c
3797index 508ad47..1a01645 100644
3798--- a/agent/mibgroup/hardware/sensors/hw_sensors.c
3799+++ b/agent/mibgroup/hardware/sensors/hw_sensors.c
3800@@ -163,6 +163,11 @@ sensor_by_name( const char *name, int create_type )
3801 */
3802 sp = SNMP_MALLOC_TYPEDEF( netsnmp_sensor_info );
3803 if ( sp ) {
3804+ if (strlen(name) >= sizeof(sp->name)) {
3805+ snmp_log(LOG_ERR, "Sensor name is too large: %s\n", name);
3806+ free(sp);
3807+ return NULL;
3808+ }
3809 strcpy( sp->name, name );
3810 sp->type = create_type;
3811 /*
3812diff --git a/agent/mibgroup/hardware/sensors/lmsensors_v3.c b/agent/mibgroup/hardware/sensors/lmsensors_v3.c
3813index d33a1c4..e34da19 100644
3814--- a/agent/mibgroup/hardware/sensors/lmsensors_v3.c
3815+++ b/agent/mibgroup/hardware/sensors/lmsensors_v3.c
3816@@ -32,7 +32,7 @@ netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
3817
3818 while ((data2 = sensors_get_all_subfeatures( chip, data, &b))) {
3819 char *label = NULL;
3820- double val;
3821+ double val = 0;
3822 int type = NETSNMP_SENSOR_TYPE_OTHER;
3823
3824 DEBUGMSGTL(("sensors:arch:detail", " get_subfeatures (%s, %d)\n", data2->name, data2->number));
3825diff --git a/agent/mibgroup/host/data_access/swinst_apt.c b/agent/mibgroup/host/data_access/swinst_apt.c
3826index d204857..26cdba5 100644
3827--- a/agent/mibgroup/host/data_access/swinst_apt.c
3828+++ b/agent/mibgroup/host/data_access/swinst_apt.c
3829@@ -37,11 +37,10 @@ static char apt_fmt[SNMP_MAXBUF];
3830 void
3831 netsnmp_swinst_arch_init(void)
3832 {
3833- strncpy( pkg_directory, "/var/lib/dpkg/info", SNMP_MAXBUF );
3834+ strlcpy(pkg_directory, "/var/lib/dpkg/info", sizeof(pkg_directory));
3835 snprintf(apt_fmt, SNMP_MAXBUF, "%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%ds",
3836 SNMP_MAXBUF, SNMP_MAXBUF, SNMP_MAXBUF,
3837 SNMP_MAXBUF, SNMP_MAXBUF, SNMP_MAXBUF);
3838- return;
3839 }
3840
3841 void
3842@@ -95,7 +94,7 @@ netsnmp_swinst_arch_load( netsnmp_container *container, u_int flags)
3843 entry->swDate_len = 8;
3844 memcpy(entry->swDate, "\0\0\1\1\0\0\0\0", 8);
3845 }
3846- fclose(p);
3847+ pclose(p);
3848 DEBUGMSGTL(("swinst:load:arch"," loaded %d entries\n",
3849 CONTAINER_SIZE(container)));
3850
3851diff --git a/agent/mibgroup/host/data_access/swinst_pkginfo.c b/agent/mibgroup/host/data_access/swinst_pkginfo.c
3852index 1ca40a2..327ca70 100644
3853--- a/agent/mibgroup/host/data_access/swinst_pkginfo.c
3854+++ b/agent/mibgroup/host/data_access/swinst_pkginfo.c
3855@@ -103,7 +103,9 @@ netsnmp_swinst_arch_load( netsnmp_container *container, u_int flags)
3856 if there isn't a list of them! */
3857 }
3858 d = opendir( pkg_directory );
3859- while (d != NULL && (dp = readdir(d)) != NULL) {
3860+ if (!d)
3861+ return 1;
3862+ while ((dp = readdir(d)) != NULL) {
3863 if ( '.' == dp->d_name[0] )
3864 continue;
3865 entry = netsnmp_swinst_entry_create( i++ );
3866diff --git a/agent/mibgroup/host/data_access/swinst_rpm.c b/agent/mibgroup/host/data_access/swinst_rpm.c
3867index a2862e0..71595be 100644
3868--- a/agent/mibgroup/host/data_access/swinst_rpm.c
3869+++ b/agent/mibgroup/host/data_access/swinst_rpm.c
3870@@ -100,7 +100,7 @@ netsnmp_swinst_arch_load( netsnmp_container *container, u_int flags)
3871 int32_t *t;
3872 time_t install_time;
3873 size_t date_len;
3874- int rc, i = 1;
3875+ int i = 1;
3876 netsnmp_swinst_entry *entry;
3877
3878 ts = rpmtsCreate();
3879@@ -112,11 +112,11 @@ netsnmp_swinst_arch_load( netsnmp_container *container, u_int flags)
3880
3881 while (NULL != (h = rpmdbNextIterator( mi )))
3882 {
3883-
3884+ const u_char *dt;
3885 entry = netsnmp_swinst_entry_create( i++ );
3886 if (NULL == entry)
3887 continue; /* error already logged by function */
3888- rc = CONTAINER_INSERT(container, entry);
3889+ CONTAINER_INSERT(container, entry);
3890
3891 h = headerLink( h );
3892 headerGetEntry( h, RPMTAG_NAME, NULL, (void**)&n, NULL);
3893@@ -134,8 +134,15 @@ netsnmp_swinst_arch_load( netsnmp_container *container, u_int flags)
3894 : 4; /* application */
3895
3896 install_time = *t;
3897- entry->swDate_len = snprintf( entry->swDate, sizeof(entry->swDate),
3898- "%s", date_n_time( &install_time, &date_len ));
3899+ dt = date_n_time( &install_time, &date_len );
3900+ if (date_len != 8 && date_len != 11) {
3901+ snmp_log(LOG_ERR, "Bogus length from date_n_time for %s", entry->swName);
3902+ entry->swDate_len = 0;
3903+ }
3904+ else {
3905+ entry->swDate_len = date_len;
3906+ memcpy(entry->swDate, dt, entry->swDate_len);
3907+ }
3908
3909 headerFree( h );
3910 }
3911diff --git a/agent/mibgroup/host/data_access/swrun_darwin.c b/agent/mibgroup/host/data_access/swrun_darwin.c
3912index 7d07cd5..6c6b82a 100644
3913--- a/agent/mibgroup/host/data_access/swrun_darwin.c
3914+++ b/agent/mibgroup/host/data_access/swrun_darwin.c
3915@@ -289,8 +289,7 @@ _set_command_name_jaguar(netsnmp_swrun_entry *entry)
3916 exec_path = (char *)ip;
3917 DEBUGMSGTL(("swrun:load:arch:_cn"," exec_path %s\n", exec_path));
3918 len = strlen(exec_path);
3919- strncpy(entry->hrSWRunPath, exec_path, sizeof(entry->hrSWRunPath)-1);
3920- entry->hrSWRunPath[sizeof(entry->hrSWRunPath)-1] = 0;
3921+ strlcpy(entry->hrSWRunPath, exec_path, sizeof(entry->hrSWRunPath));
3922 if (len > sizeof(entry->hrSWRunPath)-1) {
3923 DEBUGMSGTL(("swrun:load:arch:_cn"," truncating long run path\n"));
3924 entry->hrSWRunPath[sizeof(entry->hrSWRunPath)-2] = '$';
3925@@ -326,8 +325,7 @@ _set_command_name_jaguar(netsnmp_swrun_entry *entry)
3926 DEBUGMSGTL(("swrun:load:arch:_cn",
3927 SWRUNINDENT "kernel name %s\n", command));
3928 if (strncmp(command, entry->hrSWRunName, sizeof(entry->hrSWRunName)-1)) {
3929- strncpy(entry->hrSWRunName, command, sizeof(entry->hrSWRunName)-1);
3930- entry->hrSWRunName[sizeof(entry->hrSWRunName)-1] = 0;
3931+ strlcpy(entry->hrSWRunName, command, sizeof(entry->hrSWRunName));
3932 entry->hrSWRunName_len = strlen(entry->hrSWRunName);
3933 DEBUGMSGTL(("swrun:load:arch:_cn", "**"
3934 SWRUNINDENT "updated name to %s\n", entry->hrSWRunName));
3935@@ -369,8 +367,7 @@ _set_command_name(netsnmp_swrun_entry *entry)
3936
3937 exec_path = arg_buf + sizeof(nargs);
3938 len = strlen(exec_path);
3939- strncpy(entry->hrSWRunPath, exec_path, sizeof(entry->hrSWRunPath)-1);
3940- entry->hrSWRunPath[sizeof(entry->hrSWRunPath)-1] = 0;
3941+ strlcpy(entry->hrSWRunPath, exec_path, sizeof(entry->hrSWRunPath));
3942 if (len > sizeof(entry->hrSWRunPath)-1) {
3943 DEBUGMSGTL(("swrun:load:arch:_cn"," truncating long run path\n"));
3944 entry->hrSWRunPath[sizeof(entry->hrSWRunPath)-2] = '$';
3945@@ -459,8 +456,8 @@ _set_command_name(netsnmp_swrun_entry *entry)
3946 * save arg
3947 */
3948 if(entry->hrSWRunParameters_len < sizeof(entry->hrSWRunParameters)-1) {
3949- strncat(&entry->hrSWRunParameters[entry->hrSWRunParameters_len], argN,
3950- sizeof(entry->hrSWRunParameters) - entry->hrSWRunParameters_len - 2);
3951+ strlcat(&entry->hrSWRunParameters[entry->hrSWRunParameters_len],
3952+ argN, sizeof(entry->hrSWRunParameters));
3953 entry->hrSWRunParameters_len = strlen(entry->hrSWRunParameters);
3954 if ((entry->hrSWRunParameters_len+2 < sizeof(entry->hrSWRunParameters)-1) && (0 != nargs)) {
3955 /* add space between params */
3956@@ -486,8 +483,7 @@ _set_command_name(netsnmp_swrun_entry *entry)
3957
3958 /* Allocate space for the command and copy. */
3959 if (strncmp(command, entry->hrSWRunName, sizeof(entry->hrSWRunName)-1)) {
3960- strncpy(entry->hrSWRunName, command, sizeof(entry->hrSWRunName)-1);
3961- entry->hrSWRunName[sizeof(entry->hrSWRunName)-1] = 0;
3962+ strlcpy(entry->hrSWRunName, command, sizeof(entry->hrSWRunName));
3963 entry->hrSWRunName_len = strlen(entry->hrSWRunName);
3964 DEBUGMSGTL(("swrun:load:arch:_cn",
3965 " **updated name to %s\n", entry->hrSWRunName));
3966diff --git a/agent/mibgroup/host/data_access/swrun_kinfo.c b/agent/mibgroup/host/data_access/swrun_kinfo.c
3967index aae5f62..64583bf 100644
3968--- a/agent/mibgroup/host/data_access/swrun_kinfo.c
3969+++ b/agent/mibgroup/host/data_access/swrun_kinfo.c
3970@@ -236,7 +236,7 @@ netsnmp_arch_swrun_container_load( netsnmp_container *container, u_int flags)
3971 : 4 /* application */
3972 ;
3973
3974-#ifdef netbsdelf5
3975+#ifdef netbsd5
3976 switch (proc_table[i].SWRUN_K_STAT) {
3977 case LSONPROC:
3978 case LSRUN: entry->hrSWRunStatus = HRSWRUNSTATUS_RUNNING;
3979diff --git a/agent/mibgroup/host/data_access/swrun_procfs_status.c b/agent/mibgroup/host/data_access/swrun_procfs_status.c
3980index 367f422..a9aa2d8 100644
3981--- a/agent/mibgroup/host/data_access/swrun_procfs_status.c
3982+++ b/agent/mibgroup/host/data_access/swrun_procfs_status.c
3983@@ -123,32 +123,26 @@ netsnmp_arch_swrun_container_load( netsnmp_container *container, u_int flags)
3984 }
3985 fclose(fp);
3986
3987- if ( cp ) {
3988- /*
3989- * argv[0] is hrSWRunPath
3990- */
3991- entry->hrSWRunPath_len = snprintf(entry->hrSWRunPath,
3992- sizeof(entry->hrSWRunPath)-1, "%s", buf);
3993- /*
3994- * Stitch together argv[1..] to construct hrSWRunParameters
3995- */
3996- cp = buf + entry->hrSWRunPath_len+1;
3997- while ( 1 ) {
3998- while (*cp)
3999- cp++;
4000- if ( '\0' == *(cp+1))
4001- break; /* '\0''\0' => End of command line */
4002- *cp = ' ';
4003- }
4004- entry->hrSWRunParameters_len
4005- = sprintf(entry->hrSWRunParameters, "%.*s",
4006- (int)sizeof(entry->hrSWRunParameters) - 1,
4007- buf + entry->hrSWRunPath_len + 1);
4008- } else {
4009- memcpy(entry->hrSWRunPath, entry->hrSWRunName, entry->hrSWRunName_len);
4010- entry->hrSWRunPath_len = entry->hrSWRunName_len;
4011- entry->hrSWRunParameters_len = 0;
4012+ /*
4013+ * argv[0] is hrSWRunPath
4014+ */
4015+ entry->hrSWRunPath_len = snprintf(entry->hrSWRunPath,
4016+ sizeof(entry->hrSWRunPath)-1, "%s", buf);
4017+ /*
4018+ * Stitch together argv[1..] to construct hrSWRunParameters
4019+ */
4020+ cp = buf + entry->hrSWRunPath_len+1;
4021+ while ( 1 ) {
4022+ while (*cp)
4023+ cp++;
4024+ if ( '\0' == *(cp+1))
4025+ break; /* '\0''\0' => End of command line */
4026+ *cp = ' ';
4027 }
4028+ entry->hrSWRunParameters_len
4029+ = sprintf(entry->hrSWRunParameters, "%.*s",
4030+ (int)sizeof(entry->hrSWRunParameters) - 1,
4031+ buf + entry->hrSWRunPath_len + 1);
4032
4033 /*
4034 * XXX - No information regarding system processes vs applications
4035diff --git a/agent/mibgroup/host/hrSWInstalledTable.c b/agent/mibgroup/host/hrSWInstalledTable.c
4036index 71d2a38..ad8aee3 100644
4037--- a/agent/mibgroup/host/hrSWInstalledTable.c
4038+++ b/agent/mibgroup/host/hrSWInstalledTable.c
4039@@ -143,6 +143,7 @@ initialize_table_hrSWInstalledTable(void)
4040 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
4041 snmp_log(LOG_ERR,"error registering table handler for "
4042 MYTABLE "\n");
4043+ reg = NULL; /* it was freed inside netsnmp_register_table */
4044 goto bail;
4045 }
4046
4047diff --git a/agent/mibgroup/host/hrSWRunPerfTable.c b/agent/mibgroup/host/hrSWRunPerfTable.c
4048index 7a9adfa..43b44d1 100644
4049--- a/agent/mibgroup/host/hrSWRunPerfTable.c
4050+++ b/agent/mibgroup/host/hrSWRunPerfTable.c
4051@@ -115,6 +115,7 @@ initialize_table_hrSWRunPerfTable(void)
4052 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
4053 snmp_log(LOG_ERR,"error registering table handler for "
4054 MYTABLE "\n");
4055+ reg = NULL; /* it was freed inside netsnmp_register_table */
4056 goto bail;
4057 }
4058
4059diff --git a/agent/mibgroup/host/hrSWRunTable.c b/agent/mibgroup/host/hrSWRunTable.c
4060index 946813e..03ad256 100644
4061--- a/agent/mibgroup/host/hrSWRunTable.c
4062+++ b/agent/mibgroup/host/hrSWRunTable.c
4063@@ -128,6 +128,7 @@ initialize_table_hrSWRunTable(void)
4064 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
4065 snmp_log(LOG_ERR,"error registering table handler for "
4066 MYTABLE "\n");
4067+ reg = NULL; /* it was freed inside netsnmp_register_table */
4068 goto bail;
4069 }
4070
4071diff --git a/agent/mibgroup/host/hr_device.c b/agent/mibgroup/host/hr_device.c
4072index c2e112c..24031bf 100644
4073--- a/agent/mibgroup/host/hr_device.c
4074+++ b/agent/mibgroup/host/hr_device.c
4075@@ -250,8 +250,7 @@ really_try_next:
4076 case HRDEV_DESCR:
4077 if ((device_descr[type] != NULL) &&
4078 (NULL!=(tmp_str=((*device_descr[type])(dev_idx))))) {
4079- strncpy(string, tmp_str, sizeof(string)-1);
4080- string[ sizeof(string)-1] = 0;
4081+ strlcpy(string, tmp_str, sizeof(string));
4082 } else
4083 #if NETSNMP_NO_DUMMY_VALUES
4084 goto try_next;
4085diff --git a/agent/mibgroup/host/hr_disk.c b/agent/mibgroup/host/hr_disk.c
4086index d8f874f..679264b 100644
4087--- a/agent/mibgroup/host/hr_disk.c
4088+++ b/agent/mibgroup/host/hr_disk.c
4089@@ -355,7 +355,7 @@ parse_disk_config(const char *token, char *cptr)
4090 di_curr->item_details = (void *) 0;
4091 name++;
4092 } else if (*name == '[') {
4093- d_set = (details_set *) malloc(sizeof(details_set));
4094+ d_set = (details_set *) calloc(sizeof(details_set), 1);
4095 if (!d_set) {
4096 config_perror("Out of memory");
4097 SNMP_FREE(d_new);
4098@@ -364,8 +364,6 @@ parse_disk_config(const char *token, char *cptr)
4099 SNMP_FREE(d_str);
4100 return;
4101 }
4102- for (i = 0; i < sizeof(details_set); i++)
4103- (*d_set)[i] = (unsigned char) 0;
4104 name++;
4105 if (*name == '^' || *name == '!') {
4106 neg = 1;
4107@@ -904,16 +902,14 @@ Get_HR_Disk_Label(char *string, size_t str_len, const char *devfull)
4108
4109 sess_ref = DASessionCreate( NULL );
4110 if (NULL == sess_ref) {
4111- strncpy(string, devfull, str_len);
4112- string[str_len-1] = 0;
4113+ strlcpy(string, devfull, str_len);
4114 return -1;
4115 }
4116
4117 disk = DADiskCreateFromBSDName( NULL, sess_ref, devfull );
4118 if (NULL == disk) {
4119 CFRelease(sess_ref);
4120- strncpy(string, devfull, str_len);
4121- string[str_len-1] = 0;
4122+ strlcpy(string, devfull, str_len);
4123 return -1;
4124 }
4125
4126@@ -924,7 +920,7 @@ Get_HR_Disk_Label(char *string, size_t str_len, const char *devfull)
4127 devfull);
4128 CFRelease(disk);
4129 CFRelease(sess_ref);
4130- strncpy(string, devfull, str_len);
4131+ strlcpy(string, devfull, str_len);
4132 return -1;
4133 }
4134
4135@@ -932,14 +928,12 @@ Get_HR_Disk_Label(char *string, size_t str_len, const char *devfull)
4136 str_ref = (CFStringRef)
4137 CFDictionaryGetValue(desc, kDADiskDescriptionMediaNameKey);
4138 if (str_ref) {
4139- strncpy(string, CFStringGetCStringPtr(str_ref, sys_encoding),
4140+ strlcpy(string, CFStringGetCStringPtr(str_ref, sys_encoding),
4141 str_len);
4142- string[str_len-1] = 0;
4143 DEBUGMSGTL(("verbose:diskmgr:darwin", " name %s\n", string));
4144 }
4145 else {
4146- strncpy(string, devfull, str_len);
4147- string[str_len-1] = 0;
4148+ strlcpy(string, devfull, str_len);
4149 }
4150
4151 CFRelease(disk);
4152@@ -984,27 +978,21 @@ static void
4153 Save_HR_Disk_General(void)
4154 {
4155 #ifdef DIOC_DESCRIBE
4156- strncpy(HRD_savedModel, HRD_info.model_num, sizeof(HRD_savedModel)-1);
4157- HRD_savedModel[ sizeof(HRD_savedModel)-1 ] = 0;
4158+ strlcpy(HRD_savedModel, HRD_info.model_num, sizeof(HRD_savedModel));
4159 #endif
4160 #ifdef DKIOCINFO
4161- strncpy(HRD_savedModel, HRD_info.dki_dname, sizeof(HRD_savedModel)-1);
4162- HRD_savedModel[ sizeof(HRD_savedModel)-1 ] = 0;
4163+ strlcpy(HRD_savedModel, HRD_info.dki_dname, sizeof(HRD_savedModel));
4164 #endif
4165 #ifdef HAVE_LINUX_HDREG_H
4166- strncpy(HRD_savedModel, (const char *) HRD_info.model,
4167- sizeof(HRD_savedModel)-1);
4168- HRD_savedModel[ sizeof(HRD_savedModel)-1 ] = 0;
4169+ strlcpy(HRD_savedModel, (const char *) HRD_info.model,
4170+ sizeof(HRD_savedModel));
4171 #endif
4172 #ifdef DIOCGDINFO
4173- strncpy(HRD_savedModel, dktypenames[HRD_info.d_type],
4174- sizeof(HRD_savedModel)-1);
4175- HRD_savedModel[ sizeof(HRD_savedModel)-1 ] = 0;
4176+ strlcpy(HRD_savedModel, dktypenames[HRD_info.d_type],
4177+ sizeof(HRD_savedModel));
4178 #endif
4179 #ifdef darwin
4180- strncpy(HRD_savedModel, HRD_model,
4181- sizeof(HRD_savedModel)-1);
4182- HRD_savedModel[ sizeof(HRD_savedModel)-1 ] = 0;
4183+ strlcpy(HRD_savedModel, HRD_model, sizeof(HRD_savedModel));
4184 #endif
4185 }
4186
4187@@ -1149,9 +1137,8 @@ Query_Disk(int fd, const char *devfull)
4188 str_ref = (CFStringRef)
4189 CFDictionaryGetValue(desc, kDADiskDescriptionDeviceModelKey);
4190 if (str_ref) {
4191- strncpy(HRD_model, CFStringGetCStringPtr(str_ref, sys_encoding),
4192+ strlcpy(HRD_model, CFStringGetCStringPtr(str_ref, sys_encoding),
4193 sizeof(HRD_model));
4194- HRD_savedModel[ sizeof(HRD_savedModel)-1 ] = 0;
4195 DEBUGMSGTL(("verbose:diskmgr:darwin", " model %s\n", HRD_model));
4196 }
4197 else
4198diff --git a/agent/mibgroup/host/hr_filesys.c b/agent/mibgroup/host/hr_filesys.c
4199index 660e706..b23d322 100644
4200--- a/agent/mibgroup/host/hr_filesys.c
4201+++ b/agent/mibgroup/host/hr_filesys.c
4202@@ -361,15 +361,13 @@ var_hrfilesys(struct variable *vp,
4203 long_return = fsys_idx;
4204 return (u_char *) & long_return;
4205 case HRFSYS_MOUNT:
4206- snprintf(string, sizeof(string), "%s", HRFS_entry->HRFS_mount);
4207- string[ sizeof(string)-1 ] = 0;
4208+ strlcpy(string, HRFS_entry->HRFS_mount, sizeof(string));
4209 *var_len = strlen(string);
4210 return (u_char *) string;
4211 case HRFSYS_RMOUNT:
4212- if (Check_HR_FileSys_NFS()) {
4213- snprintf(string, sizeof(string), "%s", HRFS_entry->HRFS_name);
4214- string[ sizeof(string)-1 ] = 0;
4215- } else
4216+ if (Check_HR_FileSys_NFS())
4217+ strlcpy(string, HRFS_entry->HRFS_name, sizeof(string));
4218+ else
4219 string[0] = '\0';
4220 *var_len = strlen(string);
4221 return (u_char *) string;
4222@@ -945,17 +943,14 @@ cook_device(char *dev)
4223 static char cooked_dev[SNMP_MAXPATH+1];
4224
4225 if (!strncmp(dev, RAW_DEVICE_PREFIX, strlen(RAW_DEVICE_PREFIX))) {
4226- strncpy(cooked_dev, COOKED_DEVICE_PREFIX, sizeof(cooked_dev)-1);
4227- cooked_dev[ sizeof(cooked_dev)-1 ] = 0;
4228- strncat(cooked_dev, dev + strlen(RAW_DEVICE_PREFIX),
4229- sizeof(cooked_dev)-strlen(cooked_dev)-1);
4230- cooked_dev[ sizeof(cooked_dev)-1 ] = 0;
4231+ strlcpy(cooked_dev, COOKED_DEVICE_PREFIX, sizeof(cooked_dev));
4232+ strlcat(cooked_dev, dev + strlen(RAW_DEVICE_PREFIX),
4233+ sizeof(cooked_dev));
4234 } else {
4235- strncpy(cooked_dev, dev, sizeof(cooked_dev)-1);
4236- cooked_dev[ sizeof(cooked_dev)-1 ] = 0;
4237+ strlcpy(cooked_dev, dev, sizeof(cooked_dev));
4238 }
4239
4240- return (cooked_dev);
4241+ return cooked_dev;
4242 }
4243
4244
4245diff --git a/agent/mibgroup/host/hr_proc.c b/agent/mibgroup/host/hr_proc.c
4246index 9d44c7b..6f93079 100644
4247--- a/agent/mibgroup/host/hr_proc.c
4248+++ b/agent/mibgroup/host/hr_proc.c
4249@@ -164,6 +164,7 @@ var_hrproc(struct variable * vp,
4250 int exact, size_t * var_len, WriteMethod ** write_method)
4251 {
4252 int proc_idx;
4253+ unsigned long long value;
4254 netsnmp_cpu_info *cpu;
4255
4256 proc_idx =
4257@@ -181,9 +182,9 @@ var_hrproc(struct variable * vp,
4258 ( cpu->history[0].total_hist == cpu->total_ticks ))
4259 return NULL;
4260
4261- long_return = (cpu->idle_ticks - cpu->history[0].idle_hist)*100;
4262- long_return /= (cpu->total_ticks - cpu->history[0].total_hist);
4263- long_return = 100 - long_return;
4264+ value = (cpu->idle_ticks - cpu->history[0].idle_hist)*100;
4265+ value /= (cpu->total_ticks - cpu->history[0].total_hist);
4266+ long_return = 100 - value;
4267 if (long_return < 0)
4268 long_return = 0;
4269 return (u_char *) & long_return;
4270diff --git a/agent/mibgroup/host/hr_storage.c b/agent/mibgroup/host/hr_storage.c
4271index 4b8ba8a..264fecc 100644
4272--- a/agent/mibgroup/host/hr_storage.c
4273+++ b/agent/mibgroup/host/hr_storage.c
4274@@ -595,8 +595,7 @@ really_try_next:
4275 return (u_char *) storage_type_id;
4276 case HRSTORE_DESCR:
4277 if (store_idx > NETSNMP_MEM_TYPE_MAX) {
4278- strncpy(string, HRFS_entry->HRFS_mount, sizeof(string)-1);
4279- string[ sizeof(string)-1 ] = 0;
4280+ strlcpy(string, HRFS_entry->HRFS_mount, sizeof(string));
4281 *var_len = strlen(string);
4282 return (u_char *) string;
4283 } else {
4284diff --git a/agent/mibgroup/host/hr_swinst.c b/agent/mibgroup/host/hr_swinst.c
4285index 91c660c..4aa4593 100644
4286--- a/agent/mibgroup/host/hr_swinst.c
4287+++ b/agent/mibgroup/host/hr_swinst.c
4288@@ -405,10 +405,8 @@ var_hrswinst(struct variable * vp,
4289 case HRSWINST_UPDATE:
4290 string[0] = '\0';
4291
4292- if (swi->swi_directory != NULL) {
4293- strncpy(string, swi->swi_directory, sizeof(string));
4294- string[ sizeof(string)-1 ] = 0;
4295- }
4296+ if (swi->swi_directory != NULL)
4297+ strlcpy(string, swi->swi_directory, sizeof(string));
4298
4299 if (*string && (stat(string, &stat_buf) != -1)) {
4300 if (stat_buf.st_mtime > starttime.tv_sec)
4301@@ -436,7 +434,7 @@ var_hrswinst(struct variable * vp,
4302 #ifdef HAVE_PKGINFO
4303 char *pver;
4304 # endif
4305- strncpy(string, swi->swi_name, sizeof(string) - 1);
4306+ strlcpy(string, swi->swi_name, sizeof(string));
4307
4308 /* If we are on a solaris machine, the package names do not include versioning info,
4309 * so we must add it manually
4310diff --git a/agent/mibgroup/host/hr_swrun.c b/agent/mibgroup/host/hr_swrun.c
4311index 9e11f2e..644e7bd 100644
4312--- a/agent/mibgroup/host/hr_swrun.c
4313+++ b/agent/mibgroup/host/hr_swrun.c
4314@@ -657,14 +657,12 @@ var_hrswrun(struct variable * vp,
4315 return (u_char *) & long_return;
4316 case HRSWRUN_NAME:
4317 #ifdef HAVE_SYS_PSTAT_H
4318- snprintf(string, sizeof(string), "%s", proc_buf.pst_cmd);
4319- string[ sizeof(string)-1 ] = 0;
4320+ strlcpy(string, proc_buf.pst_cmd, sizeof(string));
4321 cp = strchr(string, ' ');
4322 if (cp != NULL)
4323 *cp = '\0';
4324 #elif defined(dynix)
4325- snprintf(string, sizeof(string), "%s", lowpsinfo.pr_fname);
4326- string[ sizeof(string)-1 ] = 0;
4327+ strlcpy(string, lowpsinfo.pr_fname, sizeof(string));
4328 cp = strchr(string, ' ');
4329 if (cp != NULL)
4330 *cp = '\0';
4331@@ -673,19 +671,16 @@ var_hrswrun(struct variable * vp,
4332 if (proc_buf) {
4333 char *pos=strchr(proc_buf->pr_psargs,' ');
4334 if (pos != NULL) *pos = '\0';
4335- strlcpy(string, basename(proc_buf->pr_psargs),sizeof(string));
4336+ strlcpy(string, basename(proc_buf->pr_psargs), sizeof(string));
4337 if (pos != NULL) *pos=' ';
4338 } else {
4339- strcpy(string, "<exited>");
4340+ strlcpy(string, "<exited>", sizeof(string));
4341 }
4342- string[ sizeof(string)-1 ] = 0;
4343 #else
4344- strncpy(string, proc_buf->p_user.u_comm, sizeof(string));
4345- string[ sizeof(string)-1 ] = 0;
4346+ strlcpy(string, proc_buf->p_user.u_comm, sizeof(string));
4347 #endif
4348 #elif defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7)
4349- strncpy(string, proc_table[LowProcIndex].pi_comm, sizeof(string));
4350- string[ sizeof(string)-1 ] = 0;
4351+ strlcpy(string, proc_table[LowProcIndex].pi_comm, sizeof(string));
4352 cp = strchr(string, ' ');
4353 if (cp != NULL)
4354 *cp = '\0';
4355@@ -806,8 +801,7 @@ var_hrswrun(struct variable * vp,
4356 *cp1 = 0;
4357 #endif
4358 #elif defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7)
4359- strncpy(string, proc_table[LowProcIndex].pi_comm, sizeof(string));
4360- string[ sizeof(string)-1 ] = 0;
4361+ strlcpy(string, proc_table[LowProcIndex].pi_comm, sizeof(string));
4362 cp = strchr(string, ' ');
4363 if (cp != NULL)
4364 *cp = '\0';
4365diff --git a/agent/mibgroup/host/hr_system.c b/agent/mibgroup/host/hr_system.c
4366index da38c74..9fea4f4 100644
4367--- a/agent/mibgroup/host/hr_system.c
4368+++ b/agent/mibgroup/host/hr_system.c
4369@@ -469,9 +469,7 @@ static int set_solaris_eeprom_parameter(const char *key, const char *value,
4370 }
4371
4372
4373- sprintf(pbuffer,"eeprom %s=\"",key);
4374- strncat(pbuffer,value,var_val_len);
4375- strcat(pbuffer,"\"\n");
4376+ sprintf(pbuffer, "eeprom %s=\"%.*s\"\n", key, var_val_len, value);
4377
4378 status=system(pbuffer);
4379
4380diff --git a/agent/mibgroup/host/hrh_filesys.c b/agent/mibgroup/host/hrh_filesys.c
4381index fd84bde..4aab6a0 100644
4382--- a/agent/mibgroup/host/hrh_filesys.c
4383+++ b/agent/mibgroup/host/hrh_filesys.c
4384@@ -350,13 +350,13 @@ when_dumped(char *filesys, int level, size_t * length)
4385 continue;
4386
4387 ++cp2;
4388- while (isspace(*cp2))
4389+ while (isspace(0xFF & *cp2))
4390 ++cp2; /* Now find the dump level */
4391
4392 if (level == FULL_DUMP) {
4393 if (*(cp2++) != '0')
4394 continue; /* Not interested in partial dumps */
4395- while (isspace(*cp2))
4396+ while (isspace(0xFF & *cp2))
4397 ++cp2;
4398
4399 dumpdate = ctime_to_timet(cp2);
4400@@ -365,7 +365,7 @@ when_dumped(char *filesys, int level, size_t * length)
4401 } else { /* Partial Dump */
4402 if (*(cp2++) == '0')
4403 continue; /* Not interested in full dumps */
4404- while (isspace(*cp2))
4405+ while (isspace(0xFF & *cp2))
4406 ++cp2;
4407
4408 tmp = ctime_to_timet(cp2);
4409@@ -390,17 +390,14 @@ cook_device(char *dev)
4410 static char cooked_dev[SNMP_MAXPATH+1];
4411
4412 if (!strncmp(dev, RAW_DEVICE_PREFIX, strlen(RAW_DEVICE_PREFIX))) {
4413- strncpy(cooked_dev, COOKED_DEVICE_PREFIX, sizeof(cooked_dev)-1);
4414- cooked_dev[ sizeof(cooked_dev)-1 ] = 0;
4415- strncat(cooked_dev, dev + strlen(RAW_DEVICE_PREFIX),
4416- sizeof(cooked_dev)-strlen(cooked_dev)-1);
4417- cooked_dev[ sizeof(cooked_dev)-1 ] = 0;
4418+ strlcpy(cooked_dev, COOKED_DEVICE_PREFIX, sizeof(cooked_dev));
4419+ strlcat(cooked_dev, dev + strlen(RAW_DEVICE_PREFIX),
4420+ sizeof(cooked_dev));
4421 } else {
4422- strncpy(cooked_dev, dev, sizeof(cooked_dev)-1);
4423- cooked_dev[ sizeof(cooked_dev)-1 ] = 0;
4424+ strlcpy(cooked_dev, dev, sizeof(cooked_dev));
4425 }
4426
4427- return (cooked_dev);
4428+ return cooked_dev;
4429 }
4430
4431
4432diff --git a/agent/mibgroup/host/hrh_storage.c b/agent/mibgroup/host/hrh_storage.c
4433index 27841a4..ca2f854 100644
4434--- a/agent/mibgroup/host/hrh_storage.c
4435+++ b/agent/mibgroup/host/hrh_storage.c
4436@@ -408,8 +408,7 @@ really_try_next:
4437 return (u_char *) storage_type_id;
4438 case HRSTORE_DESCR:
4439 if (store_idx > NETSNMP_MEM_TYPE_MAX) {
4440- strncpy(string, HRFS_entry->path, sizeof(string)-1);
4441- string[ sizeof(string)-1 ] = 0;
4442+ strlcpy(string, HRFS_entry->path, sizeof(string));
4443 *var_len = strlen(string);
4444 return (u_char *) string;
4445 } else {
4446diff --git a/agent/mibgroup/if-mib/data_access/interface_ioctl.c b/agent/mibgroup/if-mib/data_access/interface_ioctl.c
4447index 66aec99..db2c245 100644
4448--- a/agent/mibgroup/if-mib/data_access/interface_ioctl.c
4449+++ b/agent/mibgroup/if-mib/data_access/interface_ioctl.c
4450@@ -70,8 +70,7 @@ _ioctl_get(int fd, int which, struct ifreq *ifrq, const char* name)
4451 }
4452 }
4453
4454- strncpy(ifrq->ifr_name, name, sizeof(ifrq->ifr_name));
4455- ifrq->ifr_name[ sizeof(ifrq->ifr_name)-1 ] = 0;
4456+ strlcpy(ifrq->ifr_name, name, sizeof(ifrq->ifr_name));
4457 rc = ioctl(fd, which, ifrq);
4458 if (rc < 0) {
4459 snmp_log(LOG_ERR,"ioctl %d returned %d\n", which, rc);
4460@@ -157,6 +156,11 @@ netsnmp_access_interface_ioctl_physaddr_get(int fd,
4461 ifentry->type = IANAIFTYPE_TUNNEL;
4462 break; /* tunnel */
4463 #endif
4464+#ifdef ARPHRD_INFINIBAND
4465+ case ARPHRD_INFINIBAND:
4466+ ifentry->type = IANAIFTYPE_INFINIBAND;
4467+ break;
4468+#endif
4469 #ifdef ARPHRD_SLIP
4470 case ARPHRD_SLIP:
4471 case ARPHRD_CSLIP:
4472@@ -323,8 +327,7 @@ netsnmp_access_interface_ioctl_flags_set(int fd,
4473 }
4474 }
4475
4476- strncpy(ifrq.ifr_name, ifentry->name, sizeof(ifrq.ifr_name));
4477- ifrq.ifr_name[ sizeof(ifrq.ifr_name)-1 ] = 0;
4478+ strlcpy(ifrq.ifr_name, ifentry->name, sizeof(ifrq.ifr_name));
4479 rc = ioctl(fd, SIOCGIFFLAGS, &ifrq);
4480 if(rc < 0) {
4481 snmp_log(LOG_ERR,"error getting flags\n");
4482diff --git a/agent/mibgroup/if-mib/data_access/interface_linux.c b/agent/mibgroup/if-mib/data_access/interface_linux.c
4483index 9810b15..e291b9f 100644
4484--- a/agent/mibgroup/if-mib/data_access/interface_linux.c
4485+++ b/agent/mibgroup/if-mib/data_access/interface_linux.c
4486@@ -589,6 +589,7 @@ netsnmp_arch_interface_container_load(netsnmp_container* container,
4487 fd = socket(AF_INET, SOCK_DGRAM, 0);
4488 if(fd < 0) {
4489 snmp_log(LOG_ERR, "could not create socket\n");
4490+ fclose(devin);
4491 return -2;
4492 }
4493
4494@@ -727,6 +728,7 @@ netsnmp_arch_interface_container_load(netsnmp_container* container,
4495 {IANAIFTYPE_ISO88025TOKENRING, "tr"},
4496 {IANAIFTYPE_FASTETHER, "feth"},
4497 {IANAIFTYPE_GIGABITETHERNET,"gig"},
4498+ {IANAIFTYPE_INFINIBAND,"ib"},
4499 {IANAIFTYPE_PPP, "ppp"},
4500 {IANAIFTYPE_SLIP, "sl"},
4501 {IANAIFTYPE_TUNNEL, "sit"},
4502@@ -891,40 +893,38 @@ unsigned long long
4503 netsnmp_linux_interface_get_if_speed(int fd, const char *name,
4504 unsigned long long defaultspeed)
4505 {
4506+ int ret;
4507 struct ifreq ifr;
4508 struct ethtool_cmd edata;
4509+ uint16_t speed_hi;
4510+ uint32_t speed;
4511
4512 memset(&ifr, 0, sizeof(ifr));
4513+ memset(&edata, 0, sizeof(edata));
4514 edata.cmd = ETHTOOL_GSET;
4515- edata.speed = 0;
4516
4517- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)-1);
4518+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
4519 ifr.ifr_data = (char *) &edata;
4520
4521- if (ioctl(fd, SIOCETHTOOL, &ifr) == -1) {
4522- DEBUGMSGTL(("mibII/interfaces", "ETHTOOL_GSET on %s failed\n",
4523- ifr.ifr_name));
4524- return netsnmp_linux_interface_get_if_speed_mii(fd,name,defaultspeed);
4525- }
4526-
4527- if (edata.speed != SPEED_10 && edata.speed != SPEED_100
4528-#ifdef SPEED_10000
4529- && edata.speed != SPEED_10000
4530-#endif
4531-#ifdef SPEED_2500
4532- && edata.speed != SPEED_2500
4533-#endif
4534- && edata.speed != SPEED_1000 ) {
4535- DEBUGMSGTL(("mibII/interfaces", "fallback to mii for %s\n",
4536- ifr.ifr_name));
4537- /* try MII */
4538+ ret = ioctl(fd, SIOCETHTOOL, &ifr);
4539+ if (ret == -1 || edata.speed == 0) {
4540+ DEBUGMSGTL(("mibII/interfaces", "ETHTOOL_GSET on %s failed (%d / %d)\n",
4541+ ifr.ifr_name, ret, edata.speed));
4542 return netsnmp_linux_interface_get_if_speed_mii(fd,name,defaultspeed);
4543 }
4544
4545+#ifdef HAVE_STRUCT_ETHTOOL_CMD_SPEED_HI
4546+ speed_hi = edata.speed_hi;
4547+#else
4548+ speed_hi = 0;
4549+#endif
4550+ speed = speed_hi << 16 | edata.speed;
4551+ if (speed == 0xffff || speed == 0xffffffffUL /*SPEED_UNKNOWN*/)
4552+ speed = defaultspeed;
4553 /* return in bps */
4554- DEBUGMSGTL(("mibII/interfaces", "ETHTOOL_GSET on %s speed = %d\n",
4555- ifr.ifr_name, edata.speed));
4556- return edata.speed*1000LL*1000LL;
4557+ DEBUGMSGTL(("mibII/interfaces", "ETHTOOL_GSET on %s speed = %#x -> %d\n",
4558+ ifr.ifr_name, speed_hi << 16 | edata.speed, speed));
4559+ return speed * 1000LL * 1000LL;
4560 }
4561 #endif
4562
4563@@ -954,8 +954,7 @@ netsnmp_linux_interface_get_if_speed(int fd, const char *name,
4564 const unsigned long long media_speeds[] = {10000000, 10000000, 100000000, 100000000, 10000000, 0};
4565 /* It corresponds to "10baseT", "10baseT-FD", "100baseTx", "100baseTx-FD", "100baseT4", "Flow-control", 0, */
4566
4567- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
4568- ifr.ifr_name[ sizeof(ifr.ifr_name)-1 ] = 0;
4569+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
4570 data[0] = 0;
4571
4572 /*
4573@@ -1042,6 +1041,10 @@ int netsnmp_prefix_listen()
4574 unsigned groups = 0;
4575
4576 int fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
4577+ if (fd < 0) {
4578+ snmp_log(LOG_ERR, "netsnmp_prefix_listen: Cannot create socket.\n");
4579+ return -1;
4580+ }
4581
4582 memset(&localaddrinfo, 0, sizeof(struct sockaddr_nl));
4583
4584@@ -1052,6 +1055,7 @@ int netsnmp_prefix_listen()
4585
4586 if (bind(fd, (struct sockaddr*)&localaddrinfo, sizeof(localaddrinfo)) < 0) {
4587 snmp_log(LOG_ERR,"netsnmp_prefix_listen: Bind failed.\n");
4588+ close(fd);
4589 return -1;
4590 }
4591
4592@@ -1066,11 +1070,13 @@ int netsnmp_prefix_listen()
4593 status = send(fd, &req, req.n.nlmsg_len, 0);
4594 if (status < 0) {
4595 snmp_log(LOG_ERR,"netsnmp_prefix_listen: send failed\n");
4596+ close(fd);
4597 return -1;
4598 }
4599
4600 if (register_readfd(fd, netsnmp_prefix_process, NULL) != 0) {
4601 snmp_log(LOG_ERR,"netsnmp_prefix_listen: error registering netlink socket\n");
4602+ close(fd);
4603 return -1;
4604 }
4605 return 0;
4606diff --git a/agent/mibgroup/if-mib/data_access/interface_openbsd.c b/agent/mibgroup/if-mib/data_access/interface_openbsd.c
4607index 552043a..8340dc6 100644
4608--- a/agent/mibgroup/if-mib/data_access/interface_openbsd.c
4609+++ b/agent/mibgroup/if-mib/data_access/interface_openbsd.c
4610@@ -343,12 +343,10 @@ netsnmp_openbsd_interface_get_if_speed(char *name, u_int *speed, u_int *speed_hi
4611 return 0;
4612 }
4613
4614- (void) memset(&ifmr, 0, sizeof(ifmr));
4615- (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
4616-
4617- if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0 ||
4618- ifmr.ifm_count == 0) {
4619+ memset(&ifmr, 0, sizeof(ifmr));
4620+ strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
4621
4622+ if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0 || ifmr.ifm_count == 0) {
4623 close(s);
4624 return 0;
4625 }
4626diff --git a/agent/mibgroup/if-mib/data_access/interface_sysctl.c b/agent/mibgroup/if-mib/data_access/interface_sysctl.c
4627index 0669ffc..81efbef 100644
4628--- a/agent/mibgroup/if-mib/data_access/interface_sysctl.c
4629+++ b/agent/mibgroup/if-mib/data_access/interface_sysctl.c
4630@@ -252,8 +252,8 @@ netsnmp_sysctl_get_if_speed(char *name, u_int *speed,
4631 return 0;
4632 }
4633
4634- (void) memset(&ifmr, 0, sizeof(ifmr));
4635- (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
4636+ memset(&ifmr, 0, sizeof(ifmr));
4637+ strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
4638
4639 DEBUGMSGTL(("access:interface:container:sysctl"," speed in\n"));
4640 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0 ||
4641@@ -326,6 +326,11 @@ netsnmp_arch_interface_container_load(netsnmp_container* container,
4642 int amask;
4643 char *if_name;
4644 int flags;
4645+#ifdef HAVE_STRUCT_IFNET_IF_LASTCHANGE_TV_NSEC
4646+ struct timespec startspec;
4647+
4648+ TIMEVAL_TO_TIMESPEC(&starttime, &startspec);
4649+#endif
4650
4651 DEBUGMSGTL(("access:interface:container:sysctl",
4652 "load (flags %u)\n", load_flags));
4653@@ -477,7 +482,11 @@ netsnmp_arch_interface_container_load(netsnmp_container* container,
4654 NETSNMP_INTERFACE_FLAGS_HAS_DROPS |
4655 NETSNMP_INTERFACE_FLAGS_HAS_MCAST_PKTS;
4656
4657+#ifdef HAVE_STRUCT_IFNET_IF_LASTCHANGE_TV_NSEC
4658+ if (timespeccmp(&ifp->ifm_data.ifi_lastchange, &startspec, >)) {
4659+#else
4660 if (timercmp(&ifp->ifm_data.ifi_lastchange, &starttime, >)) {
4661+#endif
4662 entry->lastchange = (ifp->ifm_data.ifi_lastchange.tv_sec -
4663 starttime.tv_sec) * 100;
4664 entry->ns_flags |= NETSNMP_INTERFACE_FLAGS_HAS_LASTCHANGE;
4665@@ -502,7 +511,7 @@ netsnmp_arch_interface_container_load(netsnmp_container* container,
4666
4667 CONTAINER_INSERT(container, entry);
4668 DEBUGMSGTL(("access:interface:container:sysctl",
4669- "created entry %d for %s\n", entry->index, entry->name));
4670+ "created entry %d for %s\n", (int)entry->index, entry->name));
4671 } /* for (each interface entry) */
4672
4673 /* pass 2: walk addresses */
4674diff --git a/agent/mibgroup/if-mib/ifXTable/ifXTable_interface.c b/agent/mibgroup/if-mib/ifXTable/ifXTable_interface.c
4675index e82c2fd..6434b46 100644
4676--- a/agent/mibgroup/if-mib/ifXTable/ifXTable_interface.c
4677+++ b/agent/mibgroup/if-mib/ifXTable/ifXTable_interface.c
4678@@ -2021,7 +2021,7 @@ _ifXTable_container_row_restore(const char *token, char *buf)
4679 }
4680 rowreq_ctx = (ifXTable_rowreq_ctx*)CONTAINER_FIND(container, &index);
4681 if (NULL == rowreq_ctx) {
4682- snmp_log(LOG_ERR, "error finding row index in "
4683+ snmp_log(LOG_DEBUG, "error finding row index in "
4684 "_ifXTable_container_row_restore\n");
4685 return;
4686 }
4687diff --git a/agent/mibgroup/ip-forward-mib/data_access/route_linux.c b/agent/mibgroup/ip-forward-mib/data_access/route_linux.c
4688index d620834..926ccb7 100644
4689--- a/agent/mibgroup/ip-forward-mib/data_access/route_linux.c
4690+++ b/agent/mibgroup/ip-forward-mib/data_access/route_linux.c
4691@@ -103,8 +103,7 @@ _load_ipv4(netsnmp_container* container, u_long *index )
4692 /*
4693 * temporary null terminated name
4694 */
4695- strncpy(name, rtent_name, sizeof(name));
4696- name[ sizeof(name)-1 ] = 0;
4697+ strlcpy(name, rtent_name, sizeof(name));
4698
4699 /*
4700 * don't bother to try and get the ifindex for routes with
4701diff --git a/agent/mibgroup/ip-mib/data_access/arp_netlink.c b/agent/mibgroup/ip-mib/data_access/arp_netlink.c
4702index 01a535a..2059c23 100644
4703--- a/agent/mibgroup/ip-mib/data_access/arp_netlink.c
4704+++ b/agent/mibgroup/ip-mib/data_access/arp_netlink.c
4705@@ -43,7 +43,7 @@ netsnmp_access_arp_create(u_int init_flags,
4706 if (cache_timeout != NULL)
4707 *cache_timeout = 5;
4708 if (cache_flags != NULL)
4709- *cache_flags |= NETSNMP_CACHE_RESET_TIMER_ON_USE;
4710+ *cache_flags |= NETSNMP_CACHE_RESET_TIMER_ON_USE | NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD;
4711 access->cache_expired = cache_expired;
4712
4713 DEBUGMSGTL(("access:netlink:arp", "create arp cache\n"));
4714@@ -131,6 +131,7 @@ int netsnmp_access_arp_unload(netsnmp_arp_access *access)
4715 unregister_readfd(fd);
4716 close(fd);
4717 access->arch_magic = NULL;
4718+ access->synchronized = 0;
4719 }
4720 return 0;
4721 }
4722diff --git a/agent/mibgroup/ip-mib/data_access/ipaddress_ioctl.c b/agent/mibgroup/ip-mib/data_access/ipaddress_ioctl.c
4723index b4f7e3a..ba145cb 100644
4724--- a/agent/mibgroup/ip-mib/data_access/ipaddress_ioctl.c
4725+++ b/agent/mibgroup/ip-mib/data_access/ipaddress_ioctl.c
4726@@ -230,7 +230,7 @@ _netsnmp_ioctl_ipaddress_container_load_v4(netsnmp_container *container,
4727 /* restore the interface name if we modifed it due to unaliasing
4728 * above
4729 */
4730- if (entry->flags | NETSNMP_ACCESS_IPADDRESS_ISALIAS) {
4731+ if (entry->flags & NETSNMP_ACCESS_IPADDRESS_ISALIAS) {
4732 memcpy(ifrp->ifr_name, extras->name, sizeof(extras->name));
4733 }
4734
4735@@ -242,7 +242,7 @@ _netsnmp_ioctl_ipaddress_container_load_v4(netsnmp_container *container,
4736 addr_info = netsnmp_access_other_info_get(entry->if_index, AF_INET);
4737 if(addr_info.bcastflg) {
4738 bcastentry = netsnmp_access_ipaddress_entry_create();
4739- if(NULL == entry) {
4740+ if(NULL == bcastentry) {
4741 rc = -3;
4742 break;
4743 }
4744@@ -491,11 +491,10 @@ _netsnmp_ioctl_ipaddress_set_v4(netsnmp_ipaddress_entry * entry)
4745 alias_idx = _next_alias(name);
4746 snprintf(ifrq.ifr_name,sizeof(ifrq.ifr_name), "%s:%d",
4747 name, alias_idx);
4748+ ifrq.ifr_name[sizeof(ifrq.ifr_name) - 1] = 0;
4749 }
4750 else
4751- strncpy(ifrq.ifr_name, (char *) extras->name, sizeof(ifrq.ifr_name));
4752-
4753- ifrq.ifr_name[ sizeof(ifrq.ifr_name)-1 ] = 0;
4754+ strlcpy(ifrq.ifr_name, (char *) extras->name, sizeof(ifrq.ifr_name));
4755
4756 sin = (struct sockaddr_in*)&ifrq.ifr_addr;
4757 sin->sin_family = AF_INET;
4758@@ -543,8 +542,7 @@ _netsnmp_ioctl_ipaddress_delete_v4(netsnmp_ipaddress_entry * entry)
4759
4760 memset(&ifrq, 0, sizeof(ifrq));
4761
4762- strncpy(ifrq.ifr_name, (char *) extras->name, sizeof(ifrq.ifr_name));
4763- ifrq.ifr_name[ sizeof(ifrq.ifr_name)-1 ] = 0;
4764+ strlcpy(ifrq.ifr_name, (char *) extras->name, sizeof(ifrq.ifr_name));
4765
4766 ifrq.ifr_flags = 0;
4767
4768diff --git a/agent/mibgroup/ip-mib/data_access/ipaddress_solaris2.c b/agent/mibgroup/ip-mib/data_access/ipaddress_solaris2.c
4769index 1a7d169..e2485e3 100644
4770--- a/agent/mibgroup/ip-mib/data_access/ipaddress_solaris2.c
4771+++ b/agent/mibgroup/ip-mib/data_access/ipaddress_solaris2.c
4772@@ -191,7 +191,7 @@ _load_v4(netsnmp_container *container, int idx_offset)
4773
4774 entry->ns_ia_index = ++idx_offset;
4775
4776- DEBUGMSGTL(("access:ipaddress:container", "insert if %d, addrlen %d\n",
4777+ DEBUGMSGTL(("access:ipaddress:container", "insert if %" NETSNMP_PRIo "u, addrlen %d\n",
4778 entry->if_index, entry->ia_address_len));
4779
4780 if (CONTAINER_INSERT(container, entry) < 0) {
4781@@ -276,7 +276,7 @@ _load_v6(netsnmp_container *container, int idx_offset)
4782
4783 entry->ns_ia_index = ++idx_offset;
4784
4785- DEBUGMSGTL(("access:ipaddress:container", "insert if %d, addrlen %d\n",
4786+ DEBUGMSGTL(("access:ipaddress:container", "insert if %" NETSNMP_PRIo "u, addrlen %d\n",
4787 entry->if_index, entry->ia_address_len));
4788
4789 if (CONTAINER_INSERT(container, entry) < 0) {
4790diff --git a/agent/mibgroup/ip-mib/data_access/systemstats_linux.c b/agent/mibgroup/ip-mib/data_access/systemstats_linux.c
4791index 61a4855..717fc17 100644
4792--- a/agent/mibgroup/ip-mib/data_access/systemstats_linux.c
4793+++ b/agent/mibgroup/ip-mib/data_access/systemstats_linux.c
4794@@ -356,7 +356,6 @@ _systemstats_v6_load_file(netsnmp_systemstats_entry *entry, FILE *devin)
4795 char line[1024];
4796 char *stats, *start = line;
4797 int len, rc;
4798- int scan_count;
4799 uintmax_t scan_val;
4800
4801 /*
4802@@ -516,8 +515,6 @@ _systemstats_v6_load_file(netsnmp_systemstats_entry *entry, FILE *devin)
4803
4804 if (rc)
4805 DEBUGMSGTL(("access:systemstats", "unknown stat %s\n", line));
4806- else
4807- ++scan_count;
4808 }
4809 /*
4810 * Let DiscontinuityTime and RefreshRate active
4811diff --git a/agent/mibgroup/ip-mib/ipAddressPrefixTable/ipAddressPrefixTable_data_access.c b/agent/mibgroup/ip-mib/ipAddressPrefixTable/ipAddressPrefixTable_data_access.c
4812index dd39b07..4437829 100644
4813--- a/agent/mibgroup/ip-mib/ipAddressPrefixTable/ipAddressPrefixTable_data_access.c
4814+++ b/agent/mibgroup/ip-mib/ipAddressPrefixTable/ipAddressPrefixTable_data_access.c
4815@@ -287,6 +287,7 @@ ipAddressPrefixTable_container_load(netsnmp_container *container)
4816 "error setting index while loading "
4817 "ipAddressPrefixTable data.\n");
4818 ipAddressPrefixTable_release_rowreq_ctx(rowreq_ctx);
4819+ rowreq_ctx = NULL;
4820 continue;
4821 }
4822
4823diff --git a/agent/mibgroup/ip-mib/ipv4InterfaceTable/ipv4InterfaceTable_data_access.c b/agent/mibgroup/ip-mib/ipv4InterfaceTable/ipv4InterfaceTable_data_access.c
4824index 84a98ff..c9e14ff 100644
4825--- a/agent/mibgroup/ip-mib/ipv4InterfaceTable/ipv4InterfaceTable_data_access.c
4826+++ b/agent/mibgroup/ip-mib/ipv4InterfaceTable/ipv4InterfaceTable_data_access.c
4827@@ -138,7 +138,7 @@ ipv4InterfaceTable_check_entry_for_updates(const ifTable_rowreq_ctx *
4828 * yes.
4829 */
4830 DEBUGMSGTL(("ipv4InterfaceTable:check_entry_for_updates",
4831- "inserted row for %d\n", entry->index));
4832+ "inserted row for %" NETSNMP_PRIo "d\n", entry->index));
4833 CONTAINER_INSERT(c, ift_rrc);
4834 changed = 1;
4835 }
4836@@ -152,7 +152,7 @@ ipv4InterfaceTable_check_entry_for_updates(const ifTable_rowreq_ctx *
4837 * no
4838 */
4839 DEBUGMSGTL(("ipv4InterfaceTable:check_entry_for_updates",
4840- "removed row for %d\n",
4841+ "removed row for %" NETSNMP_PRIo "d\n",
4842 ift_rrc->data.ifentry->index));
4843 CONTAINER_REMOVE(c, ift_rrc);
4844 changed = 1;
4845@@ -164,7 +164,7 @@ ipv4InterfaceTable_check_entry_for_updates(const ifTable_rowreq_ctx *
4846 ift_rrc->data.ifentry->retransmit_v4) ||
4847 (entry->reasm_max_v4 != ift_rrc->data.ifentry->reasm_max_v4)) {
4848 DEBUGMSGTL(("ipv4InterfaceTable:check_entry_for_updates",
4849- "row changed for %d\n",
4850+ "row changed for %" NETSNMP_PRIo "d\n",
4851 ift_rrc->data.ifentry->index));
4852 changed = 1;
4853 }
4854diff --git a/agent/mibgroup/ip-mib/ipv6InterfaceTable/ipv6InterfaceTable_data_access.c b/agent/mibgroup/ip-mib/ipv6InterfaceTable/ipv6InterfaceTable_data_access.c
4855index ef7d533..33c65a9 100644
4856--- a/agent/mibgroup/ip-mib/ipv6InterfaceTable/ipv6InterfaceTable_data_access.c
4857+++ b/agent/mibgroup/ip-mib/ipv6InterfaceTable/ipv6InterfaceTable_data_access.c
4858@@ -138,7 +138,7 @@ ipv6InterfaceTable_check_entry_for_updates(const ifTable_rowreq_ctx *
4859 * yes.
4860 */
4861 DEBUGMSGTL(("ipv6InterfaceTable:check_entry_for_updates",
4862- "inserted row for index %d\n", entry->index));
4863+ "inserted row for index %" NETSNMP_PRIo "d\n", entry->index));
4864 CONTAINER_INSERT(c, ift_rrc);
4865 changed = 1;
4866 }
4867@@ -152,7 +152,7 @@ ipv6InterfaceTable_check_entry_for_updates(const ifTable_rowreq_ctx *
4868 * no
4869 */
4870 DEBUGMSGTL(("ipv6InterfaceTable:check_entry_for_updates",
4871- "removed row for index %d\n",
4872+ "removed row for index %" NETSNMP_PRIo "d\n",
4873 ift_rrc->data.ifentry->index));
4874 CONTAINER_REMOVE(c, ift_rrc);
4875 changed = 1;
4876@@ -190,7 +190,7 @@ ipv6InterfaceTable_check_entry_for_updates(const ifTable_rowreq_ctx *
4877 && (entry->forwarding_v6 !=
4878 ift_rrc->data.ifentry->forwarding_v6))) {
4879 DEBUGMSGTL(("ipv6InterfaceTable:check_entry_for_updates",
4880- "row changed for index %d\n",
4881+ "row changed for index %" NETSNMP_PRIo "d\n",
4882 ift_rrc->data.ifentry->index));
4883 changed = 1;
4884 }
4885diff --git a/agent/mibgroup/kernel_sunos5.c b/agent/mibgroup/kernel_sunos5.c
4886index 984fc77..9ee0284 100644
4887--- a/agent/mibgroup/kernel_sunos5.c
4888+++ b/agent/mibgroup/kernel_sunos5.c
4889@@ -469,8 +469,7 @@ getKstat(const char *statname, const char *varname, void *value)
4890 case KSTAT_DATA_CHAR:
4891 DEBUGMSGTL(("kernel_sunos5", "value: %s\n", d->value.c));
4892 *(char **)v = buf;
4893- buf[sizeof(buf)-1] = 0;
4894- strncpy(buf, d->value.c, sizeof(buf)-1);
4895+ strlcpy(buf, d->value.c, sizeof(buf));
4896 break;
4897 #ifdef KSTAT_DATA_INT32 /* Solaris 2.6 and up */
4898 case KSTAT_DATA_INT32:
4899@@ -623,8 +622,7 @@ getKstatString(const char *statname, const char *varname,
4900 if (strcmp(d->name, varname) == 0) {
4901 switch (d->data_type) {
4902 case KSTAT_DATA_CHAR:
4903- value[value_len-1] = '\0';
4904- strncpy(value, d->value.c, value_len-1);
4905+ strlcpy(value, d->value.c, value_len);
4906 DEBUGMSGTL(("kernel_sunos5", "value: %s\n", d->value.c));
4907 break;
4908 default:
4909diff --git a/agent/mibgroup/mibII/icmp.c b/agent/mibgroup/mibII/icmp.c
4910index 977effa..429fa0b 100644
4911--- a/agent/mibgroup/mibII/icmp.c
4912+++ b/agent/mibgroup/mibII/icmp.c
4913@@ -456,9 +456,11 @@ icmp_msg_stats_first_entry(void **loop_context,
4914 void
4915 init_icmp(void)
4916 {
4917- netsnmp_handler_registration *reginfo;
4918+ netsnmp_handler_registration *scalar_reginfo = NULL;
4919+ int rc;
4920 #ifdef linux
4921- netsnmp_handler_registration *msg_stats_reginfo;
4922+ netsnmp_handler_registration *msg_stats_reginfo = NULL;
4923+ netsnmp_handler_registration *table_reginfo = NULL;
4924 netsnmp_iterator_info *iinfo;
4925 netsnmp_iterator_info *msg_stats_iinfo;
4926 netsnmp_table_registration_info *table_info;
4927@@ -469,15 +471,17 @@ init_icmp(void)
4928 * register ourselves with the agent as a group of scalars...
4929 */
4930 DEBUGMSGTL(("mibII/icmp", "Initialising ICMP group\n"));
4931- reginfo = netsnmp_create_handler_registration("icmp", icmp_handler,
4932+ scalar_reginfo = netsnmp_create_handler_registration("icmp", icmp_handler,
4933 icmp_oid, OID_LENGTH(icmp_oid), HANDLER_CAN_RONLY);
4934- netsnmp_register_scalar_group(reginfo, ICMPINMSGS, ICMPOUTADDRMASKREPS);
4935+ rc = netsnmp_register_scalar_group(scalar_reginfo, ICMPINMSGS, ICMPOUTADDRMASKREPS);
4936+ if (rc != SNMPERR_SUCCESS)
4937+ return;
4938 /*
4939 * .... with a local cache
4940 * (except for HP-UX 11, which extracts objects individually)
4941 */
4942 #ifndef hpux11
4943- netsnmp_inject_handler( reginfo,
4944+ netsnmp_inject_handler( scalar_reginfo,
4945 netsnmp_get_cache_handler(ICMP_STATS_CACHE_TIMEOUT,
4946 icmp_load, icmp_free,
4947 icmp_oid, OID_LENGTH(icmp_oid)));
4948@@ -485,63 +489,64 @@ init_icmp(void)
4949 #ifdef linux
4950
4951 /* register icmpStatsTable */
4952- reginfo = netsnmp_create_handler_registration("icmpStatsTable",
4953- icmp_stats_table_handler, icmp_stats_tbl_oid,
4954- OID_LENGTH(icmp_stats_tbl_oid), HANDLER_CAN_RONLY);
4955-
4956 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
4957- if (!table_info) {
4958- return;
4959- }
4960-
4961+ if (!table_info)
4962+ goto bail;
4963 netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, 0);
4964 table_info->min_column = ICMP_STAT_INMSG;
4965 table_info->max_column = ICMP_STAT_OUTERR;
4966
4967
4968 iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
4969- if (!iinfo) {
4970- return;
4971- }
4972+ if (!iinfo)
4973+ goto bail;
4974 iinfo->get_first_data_point = icmp_stats_first_entry;
4975 iinfo->get_next_data_point = icmp_stats_next_entry;
4976 iinfo->table_reginfo = table_info;
4977
4978- netsnmp_register_table_iterator2(reginfo, iinfo);
4979-
4980- /* register icmpMsgStatsTable */
4981- msg_stats_reginfo = netsnmp_create_handler_registration("icmpMsgStatsTable",
4982- icmp_msg_stats_table_handler, icmp_msg_stats_tbl_oid,
4983- OID_LENGTH(icmp_msg_stats_tbl_oid), HANDLER_CAN_RONLY);
4984+ table_reginfo = netsnmp_create_handler_registration("icmpStatsTable",
4985+ icmp_stats_table_handler, icmp_stats_tbl_oid,
4986+ OID_LENGTH(icmp_stats_tbl_oid), HANDLER_CAN_RONLY);
4987
4988- msg_stats_table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
4989- if (!msg_stats_table_info) {
4990- return;
4991+ rc = netsnmp_register_table_iterator2(table_reginfo, iinfo);
4992+ if (rc != SNMPERR_SUCCESS) {
4993+ table_reginfo = NULL;
4994+ goto bail;
4995 }
4996+ netsnmp_inject_handler( table_reginfo,
4997+ netsnmp_get_cache_handler(ICMP_STATS_CACHE_TIMEOUT,
4998+ icmp_load, icmp_free,
4999+ icmp_stats_tbl_oid, OID_LENGTH(icmp_stats_tbl_oid)));
5000
5001+ /* register icmpMsgStatsTable */
5002+ msg_stats_table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
5003+ if (!msg_stats_table_info)
5004+ goto bail;
5005 netsnmp_table_helper_add_indexes(msg_stats_table_info, ASN_INTEGER, ASN_INTEGER, 0);
5006 msg_stats_table_info->min_column = ICMP_MSG_STAT_IN_PKTS;
5007 msg_stats_table_info->max_column = ICMP_MSG_STAT_OUT_PKTS;
5008
5009 msg_stats_iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
5010- if (!msg_stats_iinfo) {
5011- return;
5012- }
5013+ if (!msg_stats_iinfo)
5014+ goto bail;
5015 msg_stats_iinfo->get_first_data_point = icmp_msg_stats_first_entry;
5016 msg_stats_iinfo->get_next_data_point = icmp_msg_stats_next_entry;
5017 msg_stats_iinfo->table_reginfo = msg_stats_table_info;
5018
5019- netsnmp_register_table_iterator2(msg_stats_reginfo, msg_stats_iinfo);
5020+ msg_stats_reginfo = netsnmp_create_handler_registration("icmpMsgStatsTable",
5021+ icmp_msg_stats_table_handler, icmp_msg_stats_tbl_oid,
5022+ OID_LENGTH(icmp_msg_stats_tbl_oid), HANDLER_CAN_RONLY);
5023+
5024+ rc = netsnmp_register_table_iterator2(msg_stats_reginfo, msg_stats_iinfo);
5025+ if (rc != SNMPERR_SUCCESS) {
5026+ msg_stats_reginfo = NULL;
5027+ goto bail;
5028+ }
5029+
5030 netsnmp_inject_handler( msg_stats_reginfo,
5031 netsnmp_get_cache_handler(ICMP_STATS_CACHE_TIMEOUT,
5032 icmp_load, icmp_free,
5033 icmp_msg_stats_tbl_oid, OID_LENGTH(icmp_msg_stats_tbl_oid)));
5034-#ifndef hpux11
5035- netsnmp_inject_handler( reginfo,
5036- netsnmp_get_cache_handler(ICMP_STATS_CACHE_TIMEOUT,
5037- icmp_load, icmp_free,
5038- icmp_stats_tbl_oid, OID_LENGTH(icmp_stats_tbl_oid)));
5039-#endif /* ! hpux11 */
5040 #endif /* linux */
5041
5042 #ifdef USING_MIBII_IP_MODULE
5043@@ -558,6 +563,17 @@ init_icmp(void)
5044 init_kernel_sunos5();
5045 #endif
5046 #endif
5047+ return;
5048+
5049+#ifdef linux
5050+bail:
5051+ if (scalar_reginfo)
5052+ netsnmp_unregister_handler(scalar_reginfo);
5053+ if (table_reginfo)
5054+ netsnmp_unregister_handler(table_reginfo);
5055+ if (msg_stats_reginfo)
5056+ netsnmp_unregister_handler(msg_stats_reginfo);
5057+#endif
5058 }
5059
5060
5061diff --git a/agent/mibgroup/mibII/interfaces.c b/agent/mibgroup/mibII/interfaces.c
5062index 08c2a85..41d7287 100644
5063--- a/agent/mibgroup/mibII/interfaces.c
5064+++ b/agent/mibgroup/mibII/interfaces.c
5065@@ -463,10 +463,8 @@ Interface_Scan_By_Index(int iindex,
5066 a = get_address(ifp + 1, ifp->ifm_addrs, RTA_IFP);
5067 if (a == NULL)
5068 return 0;
5069- strncpy(if_name,
5070- ((const struct sockaddr_in *) a)->sin_zero,
5071- ((const u_char *) a)[5]);
5072- if_name[((const u_char *) a)[5]] = 0;
5073+ sprintf(if_name, "%.*s", ((const u_char *) a)[5],
5074+ ((const struct sockaddr_in *) a)->sin_zero);
5075 *if_msg = *ifp;
5076 ++have_ifinfo;
5077 }
5078@@ -1603,8 +1601,7 @@ Interface_Scan_Init(void)
5079 }
5080
5081 *stats = 0;
5082- strncpy(ifname_buf, ifstart, sizeof(ifname_buf));
5083- ifname_buf[ sizeof(ifname_buf)-1 ] = 0;
5084+ strlcpy(ifname_buf, ifstart, sizeof(ifname_buf));
5085 *stats++ = ':';
5086 while (*stats == ' ')
5087 stats++;
5088@@ -1671,31 +1668,27 @@ Interface_Scan_Init(void)
5089 nnew->if_unit = strdup(*ptr ? ptr : "");
5090 *ptr = 0;
5091
5092- strncpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5093- ifrq.ifr_name[ sizeof(ifrq.ifr_name)-1 ] = 0;
5094+ strlcpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5095 if (ioctl(fd, SIOCGIFADDR, &ifrq) < 0)
5096 memset((char *) &nnew->if_addr, 0, sizeof(nnew->if_addr));
5097 else
5098 nnew->if_addr = ifrq.ifr_addr;
5099
5100- strncpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5101- ifrq.ifr_name[ sizeof(ifrq.ifr_name)-1 ] = 0;
5102+ strlcpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5103 if (ioctl(fd, SIOCGIFBRDADDR, &ifrq) < 0)
5104 memset((char *) &nnew->ifu_broadaddr, 0,
5105 sizeof(nnew->ifu_broadaddr));
5106 else
5107 nnew->ifu_broadaddr = ifrq.ifr_broadaddr;
5108
5109- strncpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5110- ifrq.ifr_name[ sizeof(ifrq.ifr_name)-1 ] = 0;
5111+ strlcpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5112 if (ioctl(fd, SIOCGIFNETMASK, &ifrq) < 0)
5113 memset((char *) &nnew->ia_subnetmask, 0,
5114 sizeof(nnew->ia_subnetmask));
5115 else
5116 nnew->ia_subnetmask = ifrq.ifr_netmask;
5117
5118- strncpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5119- ifrq.ifr_name[ sizeof(ifrq.ifr_name)-1 ] = 0;
5120+ strlcpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5121 nnew->if_flags = ioctl(fd, SIOCGIFFLAGS, &ifrq) < 0
5122 ? 0 : ifrq.ifr_flags;
5123
5124@@ -1707,8 +1700,7 @@ Interface_Scan_Init(void)
5125 * 4 bytes of sa_data.
5126 */
5127 memset(ifrq.ifr_hwaddr.sa_data, (0), IFHWADDRLEN);
5128- strncpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5129- ifrq.ifr_name[ sizeof(ifrq.ifr_name)-1 ] = 0;
5130+ strlcpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5131 if (ioctl(fd, SIOCGIFHWADDR, &ifrq) < 0)
5132 memset(nnew->if_hwaddr, (0), IFHWADDRLEN);
5133 else {
5134@@ -1765,14 +1757,12 @@ Interface_Scan_Init(void)
5135 #endif
5136 }
5137
5138- strncpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5139- ifrq.ifr_name[ sizeof(ifrq.ifr_name)-1 ] = 0;
5140+ strlcpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5141 nnew->if_metric = ioctl(fd, SIOCGIFMETRIC, &ifrq) < 0
5142 ? 0 : ifrq.ifr_metric;
5143
5144 #ifdef SIOCGIFMTU
5145- strncpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5146- ifrq.ifr_name[ sizeof(ifrq.ifr_name)-1 ] = 0;
5147+ strlcpy(ifrq.ifr_name, ifname, sizeof(ifrq.ifr_name));
5148 nnew->if_mtu = (ioctl(fd, SIOCGIFMTU, &ifrq) < 0)
5149 ? 0 : ifrq.ifr_mtu;
5150 #else
5151@@ -1882,14 +1872,13 @@ Interface_Scan_Next(short *Index,
5152 }
5153 #else
5154 ifnet = *ifnetaddr;
5155- strncpy(saveName, ifnet.if_name, sizeof(saveName));
5156+ strlcpy(saveName, ifnet.if_name, sizeof(saveName));
5157 #endif
5158
5159 saveName[sizeof(saveName) - 1] = '\0';
5160 cp = (char *) strchr(saveName, '\0');
5161 #ifdef linux
5162- strncat(cp, ifnet.if_unit, sizeof(saveName)-strlen(saveName)-1);
5163- saveName[sizeof(saveName) - 1] = '\0';
5164+ strlcat(saveName, ifnet.if_unit, sizeof(saveName));
5165 #else
5166 #ifdef NETSNMP_FEATURE_CHECKIN
5167 /* this exists here just so we don't copy ifdef logic elsewhere */
5168@@ -2000,7 +1989,7 @@ Interface_Scan_Next(short *Index,
5169 }
5170 #if HAVE_STRUCT_IFNET_IF_XNAME
5171 #if defined(netbsd1) || defined(openbsd2)
5172- strncpy(saveName, ifnet.if_xname, sizeof saveName);
5173+ strlcpy(saveName, ifnet.if_xname, sizeof(saveName));
5174 #else
5175 if (!NETSNMP_KLOOKUP(ifnet.if_xname, (char *) saveName, sizeof saveName)) {
5176 DEBUGMSGTL(("mibII/interfaces:Interface_Scan_Next", "klookup failed\n"));
5177diff --git a/agent/mibgroup/mibII/ip.c b/agent/mibgroup/mibII/ip.c
5178index 56de408..40b5d2f 100644
5179--- a/agent/mibgroup/mibII/ip.c
5180+++ b/agent/mibgroup/mibII/ip.c
5181@@ -151,6 +151,7 @@ void
5182 init_ip(void)
5183 {
5184 netsnmp_handler_registration *reginfo;
5185+ int rc;
5186
5187 /*
5188 * register ourselves with the agent as a group of scalars...
5189@@ -158,7 +159,9 @@ init_ip(void)
5190 DEBUGMSGTL(("mibII/ip", "Initialising IP group\n"));
5191 reginfo = netsnmp_create_handler_registration("ip", ip_handler,
5192 ip_oid, OID_LENGTH(ip_oid), HANDLER_CAN_RONLY);
5193- netsnmp_register_scalar_group(reginfo, IPFORWARDING, IPROUTEDISCARDS);
5194+ rc = netsnmp_register_scalar_group(reginfo, IPFORWARDING, IPROUTEDISCARDS);
5195+ if (rc != SNMPERR_SUCCESS)
5196+ return;
5197
5198 /*
5199 * .... with a local cache
5200diff --git a/agent/mibgroup/mibII/ipv6.c b/agent/mibgroup/mibII/ipv6.c
5201index a372ca4..5714647 100644
5202--- a/agent/mibgroup/mibII/ipv6.c
5203+++ b/agent/mibgroup/mibII/ipv6.c
5204@@ -817,8 +817,7 @@ var_ifv6Entry(register struct variable * vp,
5205
5206 memset(&ifr, 0, sizeof(ifr));
5207 ifr.ifr_addr.sa_family = AF_INET6;
5208- strncpy(ifr.ifr_name, if_getname(interface),
5209- sizeof(ifr.ifr_name) - 1);
5210+ strlcpy(ifr.ifr_name, if_getname(interface), sizeof(ifr.ifr_name));
5211 if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
5212 break;
5213 if (ioctl(s, SIOCGIFMTU, (caddr_t) & ifr) < 0) {
5214@@ -1019,8 +1018,7 @@ var_ifv6Entry(register struct variable * vp,
5215 int s;
5216
5217 memset(&ifr, 0, sizeof(ifr));
5218- strncpy(ifr.ifr_name, if_getname(interface),
5219- sizeof(ifr.ifr_name) - 1);
5220+ strlcpy(ifr.ifr_name, if_getname(interface), sizeof(ifr.ifr_name));
5221 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
5222 break;
5223 if (ioctl(s, SIOCGIFSTAT_IN6, (caddr_t) & ifr) < 0) {
5224@@ -1176,8 +1174,7 @@ var_icmpv6Entry(register struct variable * vp,
5225 int s;
5226
5227 memset(&ifr, 0, sizeof(ifr));
5228- strncpy(ifr.ifr_name, if_getname(interface),
5229- sizeof(ifr.ifr_name) - 1);
5230+ strlcpy(ifr.ifr_name, if_getname(interface), sizeof(ifr.ifr_name));
5231 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
5232 break;
5233 if (ioctl(s, SIOCGIFSTAT_ICMP6, (caddr_t) & ifr) < 0) {
5234@@ -2101,7 +2098,7 @@ var_ifv6Entry(register struct variable * vp,
5235 break;
5236 memset(&ifr, 0, sizeof(ifr));
5237 ifr.ifr_addr.sa_family = AF_INET6;
5238- strncpy(ifr.ifr_name, p, sizeof(ifr.ifr_name) - 1);
5239+ strlcpy(ifr.ifr_name, p, sizeof(ifr.ifr_name));
5240 if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
5241 break;
5242 if (ioctl(s, SIOCGIFMTU, (caddr_t) & ifr) < 0) {
5243@@ -2121,7 +2118,7 @@ var_ifv6Entry(register struct variable * vp,
5244 break;
5245 memset(&ifr, 0, sizeof(ifr));
5246 ifr.ifr_addr.sa_family = AF_INET6;
5247- strncpy(ifr.ifr_name, p, sizeof(ifr.ifr_name) - 1);
5248+ strlcpy(ifr.ifr_name, p, sizeof(ifr.ifr_name));
5249 if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
5250 break;
5251 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
5252@@ -2150,7 +2147,7 @@ var_ifv6Entry(register struct variable * vp,
5253 break;
5254 memset(&ifr, 0, sizeof(ifr));
5255 ifr.ifr_addr.sa_family = AF_INET6;
5256- strncpy(ifr.ifr_name, p, sizeof(ifr.ifr_name) - 1);
5257+ strlcpy(ifr.ifr_name, p, sizeof(ifr.ifr_name));
5258 if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
5259 break;
5260 if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) {
5261diff --git a/agent/mibgroup/mibII/kernel_linux.c b/agent/mibgroup/mibII/kernel_linux.c
5262index dfa0b2b..b21a166 100644
5263--- a/agent/mibgroup/mibII/kernel_linux.c
5264+++ b/agent/mibgroup/mibII/kernel_linux.c
5265@@ -66,8 +66,8 @@ decode_icmp_msg(char *line, char *data, struct icmp4_msg_mib *msg)
5266 * getting modified. So we take a local copy for this purpose even though
5267 * its expensive.
5268 */
5269- strncpy(line_cpy, line, sizeof(line_cpy));
5270- strncpy(data_cpy, data, sizeof(data_cpy));
5271+ strlcpy(line_cpy, line, sizeof(line_cpy));
5272+ strlcpy(data_cpy, data, sizeof(data_cpy));
5273
5274 lineptr = line_cpy;
5275 dataptr = data_cpy;
5276diff --git a/agent/mibgroup/mibII/kernel_netbsd.c b/agent/mibgroup/mibII/kernel_netbsd.c
5277index 7f0a690..93f38b7 100644
5278--- a/agent/mibgroup/mibII/kernel_netbsd.c
5279+++ b/agent/mibgroup/mibII/kernel_netbsd.c
5280@@ -32,8 +32,8 @@
5281 int
5282 netbsd_read_icmp_stat(struct icmp_mib *mib)
5283 {
5284- size_t size;
5285 uint64_t icmpstat[ICMP_NSTATS];
5286+ size_t size = sizeof(icmpstat);
5287 int i;
5288
5289 (void)memset(mib, 0, sizeof(*mib));
5290@@ -89,8 +89,8 @@ netbsd_read_icmp_stat(struct icmp_mib *mib)
5291 int
5292 netbsd_read_ip_stat(struct ip_mib *mib)
5293 {
5294- size_t size;
5295 uint64_t ipstat[IP_NSTATS];
5296+ size_t size = sizeof(ipstat);
5297 int i;
5298 static int sname[4] = { 4, 2, 0, 0 }; /* CTL_NET, PF_INET, IPPROTO_IP, 0 */
5299 size_t len;
5300@@ -141,8 +141,8 @@ netbsd_read_ip_stat(struct ip_mib *mib)
5301 int
5302 netbsd_read_tcp_stat(struct tcp_mib *mib)
5303 {
5304- size_t size;
5305 uint64_t tcpstat[TCP_NSTATS];
5306+ size_t size = sizeof(tcpstat);
5307
5308 (void)memset(mib, 0, sizeof(*mib));
5309
5310@@ -177,8 +177,8 @@ netbsd_read_tcp_stat(struct tcp_mib *mib)
5311 int
5312 netbsd_read_udp_stat(struct udp_mib *mib)
5313 {
5314- size_t size;
5315 uint64_t udpstat[UDP_NSTATS];
5316+ size_t size = sizeof(udpstat);
5317
5318 (void)memset(mib, 0, sizeof(*mib));
5319
5320diff --git a/agent/mibgroup/mibII/mta_sendmail.c b/agent/mibgroup/mibII/mta_sendmail.c
5321index 79a5182..00397d3 100644
5322--- a/agent/mibgroup/mibII/mta_sendmail.c
5323+++ b/agent/mibgroup/mibII/mta_sendmail.c
5324@@ -853,8 +853,7 @@ read_sendmailcf(BOOL config)
5325 }
5326
5327 if (strncasecmp(line + 2, "StatusFile", 10) == 0) {
5328- strncpy(sendmailst_fn, filename, sizeof(sendmailst_fn));
5329- sendmailst_fn[ sizeof(sendmailst_fn)-1 ] = 0;
5330+ strlcpy(sendmailst_fn, filename, sizeof(sendmailst_fn));
5331 found_sendmailst = TRUE;
5332 DEBUGMSGTL(("mibII/mta_sendmail.c:read_sendmailcf",
5333 "found statatistics file \"%s\"\n",
5334@@ -975,11 +974,7 @@ read_sendmailcf(BOOL config)
5335 linenr++;
5336 }
5337
5338- for (i = 0; i < 10 && fclose(sendmailcf_fp) != 0; i++) {
5339- /*
5340- * nothing to do
5341- */
5342- }
5343+ fclose(sendmailcf_fp);
5344
5345 for (i = mailers; i < MAXMAILERS; i++) {
5346 mailernames[i][0] = '\0';
5347diff --git a/agent/mibgroup/mibII/route_write.c b/agent/mibgroup/mibII/route_write.c
5348index b2e941b..5820ee1 100644
5349--- a/agent/mibgroup/mibII/route_write.c
5350+++ b/agent/mibgroup/mibII/route_write.c
5351@@ -434,11 +434,6 @@ write_rte(int action,
5352
5353 memcpy(buf, var_val, (var_val_len > 8) ? 8 : var_val_len);
5354
5355- if (var_val_type != ASN_IPADDRESS) {
5356- snmp_log(LOG_ERR, "not IP address 2");
5357- return SNMP_ERR_WRONGTYPE;
5358- }
5359-
5360 rp->xx_dst = *((u_long *) buf);
5361
5362
5363@@ -509,16 +504,12 @@ write_rte(int action,
5364
5365 memcpy(buf, var_val, (var_val_len > 8) ? 8 : var_val_len);
5366
5367- if (var_val_type != ASN_IPADDRESS) {
5368- snmp_log(LOG_ERR, "not right5");
5369- return SNMP_ERR_WRONGTYPE;
5370- }
5371-
5372 rp->xx_nextIR = *((u_long *) buf);
5373
5374 } else if (action == COMMIT) {
5375 rp->rt_nextIR = rp->xx_nextIR;
5376 }
5377+ break;
5378
5379
5380 case IPROUTETYPE:
5381diff --git a/agent/mibgroup/mibII/system_mib.c b/agent/mibgroup/mibII/system_mib.c
5382index 7ca1227..65b0b7c 100644
5383--- a/agent/mibgroup/mibII/system_mib.c
5384+++ b/agent/mibgroup/mibII/system_mib.c
5385@@ -262,9 +262,9 @@ init_system_mib(void)
5386 extmp.type = EXECPROC;
5387 extmp.next = NULL;
5388 exec_command(&extmp);
5389- strncpy(version_descr, extmp.output, sizeof(version_descr));
5390- version_descr[sizeof(version_descr) - 1] = 0;
5391- version_descr[strlen(version_descr) - 1] = 0; /* chomp new line */
5392+ strlcpy(version_descr, extmp.output, sizeof(version_descr));
5393+ if (strlen(version_descr) >= 1)
5394+ version_descr[strlen(version_descr) - 1] = 0; /* chomp new line */
5395 #else
5396 #if (defined (WIN32) && defined (HAVE_WIN32_PLATFORM_SDK)) || defined (mingw32)
5397 windowsOSVersionString(version_descr, sizeof(version_descr));
5398@@ -278,7 +278,7 @@ init_system_mib(void)
5399 gethostname(sysName, sizeof(sysName));
5400 #else
5401 #ifdef HAVE_UNAME
5402- strncpy(sysName, utsName.nodename, sizeof(sysName));
5403+ strlcpy(sysName, utsName.nodename, sizeof(sysName));
5404 #else
5405 #if defined (HAVE_EXECV) && !defined (mingw32)
5406 sprintf(extmp.command, "%s -n", UNAMEPROG);
5407@@ -288,8 +288,9 @@ init_system_mib(void)
5408 extmp.type = EXECPROC;
5409 extmp.next = NULL;
5410 exec_command(&extmp);
5411- strncpy(sysName, extmp.output, sizeof(sysName));
5412- sysName[strlen(sysName) - 1] = 0; /* chomp new line */
5413+ strlcpy(sysName, extmp.output, sizeof(sysName));
5414+ if (strlen(sysName) >= 1)
5415+ sysName[strlen(sysName) - 1] = 0; /* chomp new line */
5416 #else
5417 strcpy(sysName, "unknown");
5418 #endif /* HAVE_EXECV */
5419diff --git a/agent/mibgroup/mibII/tcp.c b/agent/mibgroup/mibII/tcp.c
5420index d68e699..3c79fad 100644
5421--- a/agent/mibgroup/mibII/tcp.c
5422+++ b/agent/mibgroup/mibII/tcp.c
5423@@ -113,6 +113,7 @@ void
5424 init_tcp(void)
5425 {
5426 netsnmp_handler_registration *reginfo;
5427+ int rc;
5428
5429 /*
5430 * register ourselves with the agent as a group of scalars...
5431@@ -120,7 +121,9 @@ init_tcp(void)
5432 DEBUGMSGTL(("mibII/tcpScalar", "Initialising TCP scalar group\n"));
5433 reginfo = netsnmp_create_handler_registration("tcp", tcp_handler,
5434 tcp_oid, OID_LENGTH(tcp_oid), HANDLER_CAN_RONLY);
5435- netsnmp_register_scalar_group(reginfo, TCPRTOALGORITHM, TCPOUTRSTS);
5436+ rc = netsnmp_register_scalar_group(reginfo, TCPRTOALGORITHM, TCPOUTRSTS);
5437+ if (rc != SNMPERR_SUCCESS)
5438+ return;
5439
5440 /*
5441 * .... with a local cache
5442diff --git a/agent/mibgroup/mibII/tcpTable.c b/agent/mibgroup/mibII/tcpTable.c
5443index 01d00e5..088dd06 100644
5444--- a/agent/mibgroup/mibII/tcpTable.c
5445+++ b/agent/mibgroup/mibII/tcpTable.c
5446@@ -147,6 +147,7 @@ init_tcpTable(void)
5447 netsnmp_table_registration_info *table_info;
5448 netsnmp_iterator_info *iinfo;
5449 netsnmp_handler_registration *reginfo;
5450+ int rc;
5451
5452 DEBUGMSGTL(("mibII/tcpTable", "Initialising TCP Table\n"));
5453 /*
5454@@ -186,7 +187,9 @@ init_tcpTable(void)
5455 tcpTable_handler,
5456 tcpTable_oid, OID_LENGTH(tcpTable_oid),
5457 HANDLER_CAN_RONLY),
5458- netsnmp_register_table_iterator2(reginfo, iinfo);
5459+ rc = netsnmp_register_table_iterator2(reginfo, iinfo);
5460+ if (rc != SNMPERR_SUCCESS)
5461+ return;
5462
5463 /*
5464 * .... with a local cache
5465diff --git a/agent/mibgroup/mibII/udp.c b/agent/mibgroup/mibII/udp.c
5466index 8d2654d..1ddcbc5 100644
5467--- a/agent/mibgroup/mibII/udp.c
5468+++ b/agent/mibgroup/mibII/udp.c
5469@@ -74,6 +74,7 @@ void
5470 init_udp(void)
5471 {
5472 netsnmp_handler_registration *reginfo;
5473+ int rc;
5474
5475 /*
5476 * register ourselves with the agent as a group of scalars...
5477@@ -81,7 +82,9 @@ init_udp(void)
5478 DEBUGMSGTL(("mibII/udpScalar", "Initialising UDP scalar group\n"));
5479 reginfo = netsnmp_create_handler_registration("udp", udp_handler,
5480 udp_oid, OID_LENGTH(udp_oid), HANDLER_CAN_RONLY);
5481- netsnmp_register_scalar_group(reginfo, UDPINDATAGRAMS, UDPOUTDATAGRAMS);
5482+ rc = netsnmp_register_scalar_group(reginfo, UDPINDATAGRAMS, UDPOUTDATAGRAMS);
5483+ if (rc != SNMPERR_SUCCESS)
5484+ return;
5485
5486 /*
5487 * .... with a local cache
5488diff --git a/agent/mibgroup/mibII/udpTable.c b/agent/mibgroup/mibII/udpTable.c
5489index 162de1b..64f6dfb 100644
5490--- a/agent/mibgroup/mibII/udpTable.c
5491+++ b/agent/mibgroup/mibII/udpTable.c
5492@@ -129,6 +129,7 @@ init_udpTable(void)
5493 netsnmp_table_registration_info *table_info;
5494 netsnmp_iterator_info *iinfo;
5495 netsnmp_handler_registration *reginfo;
5496+ int rc;
5497
5498 DEBUGMSGTL(("mibII/udpTable", "Initialising UDP Table\n"));
5499 /*
5500@@ -166,7 +167,9 @@ init_udpTable(void)
5501 udpTable_handler,
5502 udpTable_oid, OID_LENGTH(udpTable_oid),
5503 HANDLER_CAN_RONLY),
5504- netsnmp_register_table_iterator2(reginfo, iinfo);
5505+ rc = netsnmp_register_table_iterator2(reginfo, iinfo);
5506+ if (rc != SNMPERR_SUCCESS)
5507+ return;
5508
5509 /*
5510 * .... with a local cache
5511@@ -496,6 +499,7 @@ udpTable_load(netsnmp_cache *cache, void *vmagic)
5512 if (state != 7) /* fix me: UDP_LISTEN ??? */
5513 continue;
5514
5515+ memset(&pcb, 0, sizeof(pcb));
5516 /* store in network byte order */
5517 pcb.inp_laddr.s_addr = htonl(pcb.inp_laddr.s_addr);
5518 pcb.inp_lport = htons((unsigned short) (lport));
5519diff --git a/agent/mibgroup/mibII/vacm_conf.c b/agent/mibgroup/mibII/vacm_conf.c
5520index f62c6cc..f2faf86 100644
5521--- a/agent/mibgroup/mibII/vacm_conf.c
5522+++ b/agent/mibgroup/mibII/vacm_conf.c
5523@@ -201,8 +201,7 @@ vacm_parse_group(const char *token, char *param)
5524 config_perror("failed to create group entry");
5525 return;
5526 }
5527- strncpy(gp->groupName, group, sizeof(gp->groupName));
5528- gp->groupName[ sizeof(gp->groupName)-1 ] = 0;
5529+ strlcpy(gp->groupName, group, sizeof(gp->groupName));
5530 gp->storageType = SNMP_STORAGE_PERMANENT;
5531 gp->status = SNMP_ROW_ACTIVE;
5532 free(gp->reserved);
5533@@ -542,10 +541,6 @@ vacm_parse_setaccess(const char *token, char *param)
5534 config_perror("failed to create access entry");
5535 return;
5536 }
5537- if (!ap) {
5538- config_perror("failed to create access entry");
5539- return;
5540- }
5541
5542 strcpy(ap->views[viewnum], viewval);
5543 ap->contextMatch = iprefix;
5544@@ -990,11 +985,9 @@ vacm_create_simple(const char *token, char *confline,
5545 sprintf(viewname,"viewUSM%d",commcount);
5546 }
5547 if ( strcmp( token, "authgroup" ) == 0 ) {
5548- strncpy(grpname, community, sizeof(grpname));
5549- grpname[ sizeof(grpname)-1 ] = 0;
5550+ strlcpy(grpname, community, sizeof(grpname));
5551 } else {
5552- strncpy(secname, community, sizeof(secname));
5553- secname[ sizeof(secname)-1 ] = 0;
5554+ strlcpy(secname, community, sizeof(secname));
5555
5556 /*
5557 * sec->group mapping
5558@@ -1419,7 +1412,7 @@ vacm_check_view_contents(netsnmp_pdu *pdu, oid * name, size_t namelen,
5559 * NULL termination of the pdu field is ugly here. Do in PDU parsing?
5560 */
5561 if (pdu->contextName)
5562- strncpy(contextNameIndex, pdu->contextName, pdu->contextNameLen);
5563+ memcpy(contextNameIndex, pdu->contextName, pdu->contextNameLen);
5564 else
5565 contextNameIndex[0] = '\0';
5566
5567diff --git a/agent/mibgroup/mibII/vacm_vars.c b/agent/mibgroup/mibII/vacm_vars.c
5568index 7860573..85cef94 100644
5569--- a/agent/mibgroup/mibII/vacm_vars.c
5570+++ b/agent/mibgroup/mibII/vacm_vars.c
5571@@ -1084,7 +1084,7 @@ write_vacmAccessStatus(int action,
5572 {
5573 static long long_ret;
5574 int model, level;
5575- char *newGroupName, *newContextPrefix;
5576+ char *newGroupName = NULL, *newContextPrefix = NULL;
5577 size_t groupNameLen, contextPrefixLen;
5578 struct vacm_accessEntry *aptr = NULL;
5579
5580diff --git a/agent/mibgroup/mibII/var_route.c b/agent/mibgroup/mibII/var_route.c
5581index b5daed0..8488019 100644
5582--- a/agent/mibgroup/mibII/var_route.c
5583+++ b/agent/mibgroup/mibII/var_route.c
5584@@ -919,7 +919,7 @@ load_rtentries(struct radix_node *pt)
5585 }
5586 #if HAVE_STRUCT_IFNET_IF_XNAME
5587 #if defined(netbsd1) || defined(openbsd2)
5588- strncpy(name, ifnet.if_xname, sizeof name);
5589+ strlcpy(name, ifnet.if_xname, sizeof(name));
5590 #else
5591 if (!NETSNMP_KLOOKUP(ifnet.if_xname, name, sizeof name)) {
5592 DEBUGMSGTL(("mibII/var_route", "klookup failed\n"));
5593@@ -1366,8 +1366,7 @@ Route_Scan_Reload(void)
5594 &(((struct sockaddr_in *) &(rtent.rt_genmask))->sin_addr.s_addr)))
5595 continue;
5596
5597- strncpy(name, rt->rt_dev, sizeof(name));
5598- name[ sizeof(name)-1 ] = 0;
5599+ strlcpy(name, rt->rt_dev, sizeof(name));
5600
5601 rt->rt_flags = flags, rt->rt_refcnt = refcnt;
5602 rt->rt_use = use, rt->rt_metric = metric;
5603diff --git a/agent/mibgroup/notification-log-mib/notification_log.c b/agent/mibgroup/notification-log-mib/notification_log.c
5604index 86efb34..a12a338 100644
5605--- a/agent/mibgroup/notification-log-mib/notification_log.c
5606+++ b/agent/mibgroup/notification-log-mib/notification_log.c
5607@@ -136,11 +136,9 @@ check_log_size(unsigned int clientreg, void *clientarg)
5608 netsnmp_table_row *row;
5609 netsnmp_table_data_set_storage *data;
5610 u_long count = 0;
5611- struct timeval now;
5612 u_long uptime;
5613
5614- gettimeofday(&now, NULL);
5615- uptime = netsnmp_timeval_uptime(&now);
5616+ uptime = netsnmp_get_agent_uptime();
5617
5618 if (!nlmLogTable || !nlmLogTable->table ) {
5619 DEBUGMSGTL(("notification_log", "missing log table\n"));
5620@@ -580,7 +578,6 @@ void
5621 log_notification(netsnmp_pdu *pdu, netsnmp_transport *transport)
5622 {
5623 long tmpl;
5624- struct timeval now;
5625 netsnmp_table_row *row;
5626
5627 static u_long default_num = 0;
5628@@ -620,8 +617,7 @@ log_notification(netsnmp_pdu *pdu, netsnmp_transport *transport)
5629 /*
5630 * add the data
5631 */
5632- gettimeofday(&now, NULL);
5633- tmpl = netsnmp_timeval_uptime(&now);
5634+ tmpl = netsnmp_get_agent_uptime();
5635 netsnmp_set_row_column(row, COLUMN_NLMLOGTIME, ASN_TIMETICKS,
5636 &tmpl, sizeof(tmpl));
5637 time(&timetnow);
5638diff --git a/agent/mibgroup/notification/snmpNotifyFilterProfileTable.c b/agent/mibgroup/notification/snmpNotifyFilterProfileTable.c
5639index ac7f2ab..b12cdc8 100644
5640--- a/agent/mibgroup/notification/snmpNotifyFilterProfileTable.c
5641+++ b/agent/mibgroup/notification/snmpNotifyFilterProfileTable.c
5642@@ -194,6 +194,7 @@ parse_snmpNotifyFilterProfileTable(const char *token, char *line)
5643 &StorageTmp->snmpNotifyFilterProfileNameLen);
5644 if (StorageTmp->snmpNotifyFilterProfileName == NULL) {
5645 config_perror("invalid specification for snmpNotifyFilterProfileName");
5646+ SNMP_FREE(StorageTmp);
5647 return;
5648 }
5649
5650diff --git a/agent/mibgroup/notification/snmpNotifyTable.c b/agent/mibgroup/notification/snmpNotifyTable.c
5651index 649b19e..8d09c59 100644
5652--- a/agent/mibgroup/notification/snmpNotifyTable.c
5653+++ b/agent/mibgroup/notification/snmpNotifyTable.c
5654@@ -317,9 +317,15 @@ notifyTable_register_notifications(int major, int minor,
5655 /*
5656 * address
5657 */
5658+ t = snmp_sess_transport(snmp_sess_pointer(ss));
5659+ if (!t) {
5660+ snmp_log(LOG_ERR,
5661+ "Cannot add new trap destination, transport is closed.");
5662+ snmp_sess_close(ss);
5663+ return 0;
5664+ }
5665 ptr = snmpTargetAddrTable_create();
5666 ptr->name = strdup(buf);
5667- t = snmp_sess_transport(snmp_sess_pointer(ss));
5668 memcpy(ptr->tDomain, t->domain, t->domain_length * sizeof(oid));
5669 ptr->tDomainLen = t->domain_length;
5670 ptr->tAddressLen = t->remote_length;
5671@@ -346,8 +352,10 @@ notifyTable_register_notifications(int major, int minor,
5672 pptr->secModel = ss->securityModel;
5673 pptr->secLevel = ss->securityLevel;
5674 pptr->secName = (char *) malloc(ss->securityNameLen + 1);
5675- if (pptr->secName == NULL)
5676+ if (pptr->secName == NULL) {
5677+ snmpTargetParamTable_dispose(pptr);
5678 return 0;
5679+ }
5680 memcpy((void *) pptr->secName, (void *) ss->securityName,
5681 ss->securityNameLen);
5682 pptr->secName[ss->securityNameLen] = 0;
5683@@ -363,8 +371,10 @@ notifyTable_register_notifications(int major, int minor,
5684 pptr->secName = NULL;
5685 if (ss->community && (ss->community_len > 0)) {
5686 pptr->secName = (char *) malloc(ss->community_len + 1);
5687- if (pptr->secName == NULL)
5688+ if (pptr->secName == NULL) {
5689+ snmpTargetParamTable_dispose(pptr);
5690 return 0;
5691+ }
5692 memcpy((void *) pptr->secName, (void *) ss->community,
5693 ss->community_len);
5694 pptr->secName[ss->community_len] = 0;
5695@@ -573,6 +583,7 @@ parse_snmpNotifyTable(const char *token, char *line)
5696 &StorageTmp->snmpNotifyNameLen);
5697 if (StorageTmp->snmpNotifyName == NULL) {
5698 config_perror("invalid specification for snmpNotifyName");
5699+ SNMP_FREE(StorageTmp);
5700 return;
5701 }
5702
5703@@ -582,6 +593,7 @@ parse_snmpNotifyTable(const char *token, char *line)
5704 &StorageTmp->snmpNotifyTagLen);
5705 if (StorageTmp->snmpNotifyTag == NULL) {
5706 config_perror("invalid specification for snmpNotifyTag");
5707+ SNMP_FREE(StorageTmp);
5708 return;
5709 }
5710
5711diff --git a/agent/mibgroup/rmon-mib/data_access/etherstats_linux.c b/agent/mibgroup/rmon-mib/data_access/etherstats_linux.c
5712index cd35d09..d4b6e69 100644
5713--- a/agent/mibgroup/rmon-mib/data_access/etherstats_linux.c
5714+++ b/agent/mibgroup/rmon-mib/data_access/etherstats_linux.c
5715@@ -46,8 +46,8 @@ etherstats_interface_name_list_get (struct ifname *list_head, int *retval)
5716 *retval = -2;
5717 return NULL;
5718 }
5719- memset (list_head, 0, sizeof (struct ifname));
5720- strncpy (list_head->name, p->ifa_name, IF_NAMESIZE);
5721+ memset(list_head, 0, sizeof(struct ifname));
5722+ strlcpy(list_head->name, p->ifa_name, IF_NAMESIZE);
5723 continue;
5724 }
5725 for (nameptr1 = list_head; nameptr1; nameptr2 = nameptr1, nameptr1 = nameptr1->ifn_next)
5726@@ -67,10 +67,9 @@ etherstats_interface_name_list_get (struct ifname *list_head, int *retval)
5727 return NULL;
5728 }
5729 nameptr2 = nameptr2->ifn_next;
5730- memset (nameptr2, 0, sizeof (struct ifname));
5731- strncpy (nameptr2->name, p->ifa_name, IF_NAMESIZE);
5732+ memset(nameptr2, 0, sizeof(struct ifname));
5733+ strlcpy(nameptr2->name, p->ifa_name, IF_NAMESIZE);
5734 continue;
5735-
5736 }
5737
5738 freeifaddrs(addrs);
5739@@ -162,7 +161,7 @@ interface_ioctl_etherstats_get (etherStatsTable_rowreq_ctx *rowreq_ctx , int fd,
5740 "called\n"));
5741
5742 memset(&ifr, 0, sizeof(ifr));
5743- strcpy(ifr.ifr_name, name);
5744+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
5745
5746 memset(&driver_info, 0, sizeof(driver_info));
5747 driver_info.cmd = ETHTOOL_GDRVINFO;
5748@@ -238,8 +237,8 @@ interface_ioctl_etherstats_get (etherStatsTable_rowreq_ctx *rowreq_ctx , int fd,
5749 for (i = 0; i < nstats; i++) {
5750 char s[ETH_GSTRING_LEN];
5751
5752- strncpy(s, (const char *) &eth_strings->data[i * ETH_GSTRING_LEN],
5753- ETH_GSTRING_LEN);
5754+ strlcpy(s, (const char *) &eth_strings->data[i * ETH_GSTRING_LEN],
5755+ sizeof(s));
5756
5757 if (ETHERSTATSJABBERS(s)) {
5758 data->etherStatsJabbers = (u_long)eth_stats->data[i];
5759@@ -300,8 +299,7 @@ _etherStats_ioctl_get(int fd, int which, struct ifreq *ifrq, const char* name)
5760 }
5761 }
5762
5763- strncpy(ifrq->ifr_name, name, sizeof(ifrq->ifr_name));
5764- ifrq->ifr_name[ sizeof(ifrq->ifr_name)-1 ] = 0;
5765+ strlcpy(ifrq->ifr_name, name, sizeof(ifrq->ifr_name));
5766 rc = ioctl(fd, which, ifrq);
5767 if (rc < 0) {
5768 DEBUGMSGTL(("access:etherStatsTable:ioctl",
5769diff --git a/agent/mibgroup/sctp-mib/sctpAssocLocalAddrTable.c b/agent/mibgroup/sctp-mib/sctpAssocLocalAddrTable.c
5770index bc22430..d6023e5 100644
5771--- a/agent/mibgroup/sctp-mib/sctpAssocLocalAddrTable.c
5772+++ b/agent/mibgroup/sctp-mib/sctpAssocLocalAddrTable.c
5773@@ -102,6 +102,7 @@ initialize_table_sctpAssocLocalAddrTable(void)
5774 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
5775 snmp_log(LOG_ERR,
5776 "error registering table handler for sctpAssocLocalAddrTable\n");
5777+ reg = NULL; /* it was freed inside netsnmp_register_table */
5778 goto bail;
5779 }
5780
5781diff --git a/agent/mibgroup/sctp-mib/sctpAssocRemAddrTable.c b/agent/mibgroup/sctp-mib/sctpAssocRemAddrTable.c
5782index bea3978..38ca8a3 100644
5783--- a/agent/mibgroup/sctp-mib/sctpAssocRemAddrTable.c
5784+++ b/agent/mibgroup/sctp-mib/sctpAssocRemAddrTable.c
5785@@ -101,6 +101,7 @@ initialize_table_sctpAssocRemAddrTable(void)
5786 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
5787 snmp_log(LOG_ERR,
5788 "error registering table handler for sctpAssocRemAddrTable\n");
5789+ reg = NULL; /* it was freed inside netsnmp_register_table */
5790 goto bail;
5791 }
5792
5793diff --git a/agent/mibgroup/sctp-mib/sctpAssocTable.c b/agent/mibgroup/sctp-mib/sctpAssocTable.c
5794index 951f778..9919075 100644
5795--- a/agent/mibgroup/sctp-mib/sctpAssocTable.c
5796+++ b/agent/mibgroup/sctp-mib/sctpAssocTable.c
5797@@ -135,6 +135,7 @@ initialize_table_sctpAssocTable(void)
5798 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
5799 snmp_log(LOG_ERR,
5800 "error registering table handler for sctpAssocTable\n");
5801+ reg = NULL; /* it was freed inside netsnmp_register_table */
5802 goto bail;
5803 }
5804
5805diff --git a/agent/mibgroup/sctp-mib/sctpLookupLocalPortTable.c b/agent/mibgroup/sctp-mib/sctpLookupLocalPortTable.c
5806index f40db3a..1a6fd35 100644
5807--- a/agent/mibgroup/sctp-mib/sctpLookupLocalPortTable.c
5808+++ b/agent/mibgroup/sctp-mib/sctpLookupLocalPortTable.c
5809@@ -97,6 +97,7 @@ initialize_table_sctpLookupLocalPortTable(void)
5810 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
5811 snmp_log(LOG_ERR,
5812 "error registering table handler for sctpLookupLocalPortTable\n");
5813+ reg = NULL; /* it was freed inside netsnmp_register_table */
5814 goto bail;
5815 }
5816
5817diff --git a/agent/mibgroup/sctp-mib/sctpLookupRemHostNameTable.c b/agent/mibgroup/sctp-mib/sctpLookupRemHostNameTable.c
5818index cfbceab..ae2ec91 100644
5819--- a/agent/mibgroup/sctp-mib/sctpLookupRemHostNameTable.c
5820+++ b/agent/mibgroup/sctp-mib/sctpLookupRemHostNameTable.c
5821@@ -99,6 +99,7 @@ initialize_table_sctpLookupRemHostNameTable(void)
5822 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
5823 snmp_log(LOG_ERR,
5824 "error registering table handler for sctpLookupRemHostNameTable\n");
5825+ reg = NULL; /* it was freed inside netsnmp_register_table */
5826 goto bail;
5827 }
5828
5829diff --git a/agent/mibgroup/sctp-mib/sctpLookupRemIPAddrTable.c b/agent/mibgroup/sctp-mib/sctpLookupRemIPAddrTable.c
5830index c95bdf1..368dd51 100644
5831--- a/agent/mibgroup/sctp-mib/sctpLookupRemIPAddrTable.c
5832+++ b/agent/mibgroup/sctp-mib/sctpLookupRemIPAddrTable.c
5833@@ -98,6 +98,7 @@ initialize_table_sctpLookupRemIPAddrTable(void)
5834 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
5835 snmp_log(LOG_ERR,
5836 "error registering table handler for sctpLookupRemIPAddrTable\n");
5837+ reg = NULL; /* it was freed inside netsnmp_register_table */
5838 goto bail;
5839 }
5840
5841diff --git a/agent/mibgroup/sctp-mib/sctpLookupRemPortTable.c b/agent/mibgroup/sctp-mib/sctpLookupRemPortTable.c
5842index eb1828b..c8a8874 100644
5843--- a/agent/mibgroup/sctp-mib/sctpLookupRemPortTable.c
5844+++ b/agent/mibgroup/sctp-mib/sctpLookupRemPortTable.c
5845@@ -97,6 +97,7 @@ initialize_table_sctpLookupRemPortTable(void)
5846 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
5847 snmp_log(LOG_ERR,
5848 "error registering table handler for sctpLookupRemPortTable\n");
5849+ reg = NULL; /* it was freed inside netsnmp_register_table */
5850 goto bail;
5851 }
5852
5853diff --git a/agent/mibgroup/sctp-mib/sctpLookupRemPrimIPAddrTable.c b/agent/mibgroup/sctp-mib/sctpLookupRemPrimIPAddrTable.c
5854index 44d384f..d9966fc 100644
5855--- a/agent/mibgroup/sctp-mib/sctpLookupRemPrimIPAddrTable.c
5856+++ b/agent/mibgroup/sctp-mib/sctpLookupRemPrimIPAddrTable.c
5857@@ -99,6 +99,7 @@ initialize_table_sctpLookupRemPrimIPAddrTable(void)
5858 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
5859 snmp_log(LOG_ERR,
5860 "error registering table handler for sctpLookupRemPrimIPAddrTable\n");
5861+ reg = NULL; /* it was freed inside netsnmp_register_table */
5862 goto bail;
5863 }
5864
5865diff --git a/agent/mibgroup/sctp-mib/sctpScalars.c b/agent/mibgroup/sctp-mib/sctpScalars.c
5866index 6bcefd2..821079a 100644
5867--- a/agent/mibgroup/sctp-mib/sctpScalars.c
5868+++ b/agent/mibgroup/sctp-mib/sctpScalars.c
5869@@ -18,6 +18,7 @@ init_sctpScalars(void)
5870 {
5871 netsnmp_handler_registration *reginfo_stats;
5872 netsnmp_handler_registration *reginfo_params;
5873+ int rc;
5874
5875 DEBUGMSGTL(("sctp:scalars:init", "Initializing\n"));
5876
5877@@ -27,8 +28,14 @@ init_sctpScalars(void)
5878 sctp_stats_oid,
5879 OID_LENGTH(sctp_stats_oid),
5880 HANDLER_CAN_RONLY);
5881- netsnmp_register_scalar_group(reginfo_stats, SCTP_CURRESTAB,
5882+ if (!reginfo_stats)
5883+ return;
5884+
5885+ rc = netsnmp_register_scalar_group(reginfo_stats, SCTP_CURRESTAB,
5886 SCTP_DISCONTINUITYTIME);
5887+ if (rc != SNMPERR_SUCCESS)
5888+ return;
5889+
5890 netsnmp_inject_handler(reginfo_stats,
5891 netsnmp_get_cache_handler
5892 (SCTP_STATS_CACHE_TIMEOUT,
5893@@ -43,8 +50,13 @@ init_sctpScalars(void)
5894 sctp_params_oid,
5895 OID_LENGTH(sctp_params_oid),
5896 HANDLER_CAN_RONLY);
5897- netsnmp_register_scalar_group(reginfo_params, SCTP_RTOALGORITHM,
5898+ if (!reginfo_params)
5899+ return;
5900+
5901+ rc = netsnmp_register_scalar_group(reginfo_params, SCTP_RTOALGORITHM,
5902 SCTP_MAXINITRETR);
5903+ if (!rc)
5904+ return;
5905 netsnmp_inject_handler(reginfo_params,
5906 netsnmp_get_cache_handler
5907 (SCTP_PARAMS_CACHE_TIMEOUT,
5908diff --git a/agent/mibgroup/sctp-mib/sctpScalars_freebsd.c b/agent/mibgroup/sctp-mib/sctpScalars_freebsd.c
5909index a62b788..b8c723f 100644
5910--- a/agent/mibgroup/sctp-mib/sctpScalars_freebsd.c
5911+++ b/agent/mibgroup/sctp-mib/sctpScalars_freebsd.c
5912@@ -60,9 +60,7 @@ netsnmp_access_sctp_params_arch_init()
5913 int
5914 netsnmp_access_sctp_params_arch_load(netsnmp_sctp_params * sctp_params)
5915 {
5916- int ret;
5917 size_t len = sizeof(uint32_t);
5918- unsigned int cnt = 0;
5919
5920 sctp_params->rto_algorithm = NETSNMP_SCTP_ALGORITHM_VANJ;
5921 sctp_params->max_assocs = SCTP_MAX_NUM_OF_ASOC;
5922diff --git a/agent/mibgroup/sctp-mib/sctpScalars_linux.c b/agent/mibgroup/sctp-mib/sctpScalars_linux.c
5923index 8cbe90f..2e5b5af 100644
5924--- a/agent/mibgroup/sctp-mib/sctpScalars_linux.c
5925+++ b/agent/mibgroup/sctp-mib/sctpScalars_linux.c
5926@@ -35,6 +35,7 @@ load_uint_file(const char *filename, u_int * value)
5927 if (ret != 1) {
5928 DEBUGMSGTL(("sctp:scalars:arch:load", "Malformed file %s\n",
5929 filename));
5930+ fclose(f);
5931 return -2;
5932 }
5933
5934@@ -71,6 +72,7 @@ netsnmp_access_sctp_stats_arch_load(netsnmp_sctp_stats * sctp_stats)
5935 if (delimiter == NULL) {
5936 DEBUGMSGTL(("sctp:scalars:stats:arch_load",
5937 "Malformed line, cannot find '\\t'!\n"));
5938+ fclose(f);
5939 return -1;
5940 }
5941 errno = 0;
5942@@ -78,6 +80,7 @@ netsnmp_access_sctp_stats_arch_load(netsnmp_sctp_stats * sctp_stats)
5943 if (errno != 0) {
5944 DEBUGMSGTL(("sctp:scalars:stats:arch_load",
5945 "Malformed value!'\n"));
5946+ fclose(f);
5947 return -1;
5948 }
5949
5950@@ -136,11 +139,13 @@ netsnmp_access_sctp_stats_arch_load(netsnmp_sctp_stats * sctp_stats)
5951 if (ret < 0) {
5952 DEBUGMSGTL(("sctp:scalars:stats:arch_load",
5953 "Unknown entry!'\n"));
5954+ fclose(f);
5955 return ret;
5956 }
5957 }
5958
5959 sctp_stats->discontinuity_time = 0;
5960+ fclose(f);
5961 return 0;
5962 }
5963
5964diff --git a/agent/mibgroup/sctp-mib/sctpTables_common.c b/agent/mibgroup/sctp-mib/sctpTables_common.c
5965index 899d8d5..b28ea03 100644
5966--- a/agent/mibgroup/sctp-mib/sctpTables_common.c
5967+++ b/agent/mibgroup/sctp-mib/sctpTables_common.c
5968@@ -435,7 +435,7 @@ sctpTables_load(void)
5969
5970 ret = sctpTables_arch_load(&containers, &flags);
5971
5972- if (flags | SCTP_TABLES_LOAD_FLAG_DELETE_INVALID) {
5973+ if (flags & SCTP_TABLES_LOAD_FLAG_DELETE_INVALID) {
5974 sctpAssocTable_delete_invalid(containers.sctpAssocTable);
5975 sctpAssocRemAddrTable_delete_invalid(containers.
5976 sctpAssocRemAddrTable);
5977@@ -443,7 +443,7 @@ sctpTables_load(void)
5978 sctpAssocLocalAddrTable);
5979 }
5980
5981- if (flags | SCTP_TABLES_LOAD_FLAG_AUTO_LOOKUP) {
5982+ if (flags & SCTP_TABLES_LOAD_FLAG_AUTO_LOOKUP) {
5983 ret = sctpTables_fill_lookup(&containers);
5984 }
5985
5986diff --git a/agent/mibgroup/sctp-mib/sctpTables_freebsd.c b/agent/mibgroup/sctp-mib/sctpTables_freebsd.c
5987index db73e00..516e9f5 100644
5988--- a/agent/mibgroup/sctp-mib/sctpTables_freebsd.c
5989+++ b/agent/mibgroup/sctp-mib/sctpTables_freebsd.c
5990@@ -58,8 +58,6 @@ parse_assoc_local_addresses(sctpTables_containers * containers,
5991 static int
5992 parse_assoc_xstcb(sctpTables_containers * containers, struct xsctp_tcb *xstcb)
5993 {
5994- long inode;
5995- char *token;
5996 int ret;
5997 sctpAssocTable_entry *entry;
5998
5999@@ -124,7 +122,6 @@ static int
6000 parse_remaddr_xraddr(sctpTables_containers * containers,
6001 struct xsctp_raddr *xraddr)
6002 {
6003- char *token;
6004 int ret;
6005 sctpAssocRemAddrTable_entry *entry;
6006
6007@@ -184,8 +181,6 @@ sctpTables_arch_load(sctpTables_containers * containers, u_long * flags)
6008 struct xsctp_tcb *xstcb;
6009 struct xsctp_laddr *xladdr;
6010 struct xsctp_raddr *xraddr;
6011- sa_family_t family;
6012- void *addr;
6013
6014
6015 *flags |= SCTP_TABLES_LOAD_FLAG_DELETE_INVALID;
6016diff --git a/agent/mibgroup/smux/smux.c b/agent/mibgroup/smux/smux.c
6017index fdb5e11..2055974 100644
6018--- a/agent/mibgroup/smux/smux.c
6019+++ b/agent/mibgroup/smux/smux.c
6020@@ -91,7 +91,7 @@ static u_char *smux_parse(u_char *, oid *, size_t *, size_t *, u_char *);
6021 static u_char *smux_parse_var(u_char *, size_t *, oid *, size_t *,
6022 size_t *, u_char *);
6023 static void smux_send_close(int, int);
6024-static void smux_list_detach(smux_reg **, smux_reg **);
6025+static void smux_list_detach(smux_reg **, smux_reg *);
6026 static void smux_replace_active(smux_reg *, smux_reg *);
6027 static void smux_peer_cleanup(int);
6028 static int smux_auth_peer(oid *, size_t, char *, int);
6029@@ -145,6 +145,7 @@ smux_parse_peer_auth(const char *token, char *cptr)
6030 }
6031 if (nauths == SMUX_MAX_PEERS) {
6032 config_perror("Too many smuxpeers");
6033+ free(aptr);
6034 return;
6035 }
6036
6037@@ -169,10 +170,8 @@ smux_parse_peer_auth(const char *token, char *cptr)
6038 /*
6039 * password
6040 */
6041- if (*password_cptr) {
6042- strncpy(aptr->sa_passwd, password_cptr, SMUXMAXSTRLEN-1);
6043- aptr->sa_passwd[SMUXMAXSTRLEN-1] = '\0';
6044- }
6045+ if (*password_cptr)
6046+ strlcpy(aptr->sa_passwd, password_cptr, sizeof(aptr->sa_passwd));
6047 } else {
6048 /*
6049 * null passwords OK
6050@@ -369,6 +368,11 @@ var_smux_write(int action,
6051 break;
6052 }
6053
6054+ if (!rptr) {
6055+ DEBUGMSGTL(("smux", "[var_smux_write] unknown registration\n"));
6056+ return SNMP_ERR_GENERR;
6057+ }
6058+
6059 switch (action) {
6060 case RESERVE1:
6061 DEBUGMSGTL(("smux", "[var_smux_write] entering RESERVE1\n"));
6062@@ -1049,7 +1053,7 @@ smux_rreq_process(int sd, u_char * ptr, size_t * len)
6063 /*
6064 * no replacement found
6065 */
6066- smux_list_detach(&ActiveRegs, &rptr);
6067+ smux_list_detach(&ActiveRegs, rptr);
6068 free(rptr);
6069 }
6070 smux_send_rrsp(sd, rpriority);
6071@@ -1063,7 +1067,7 @@ smux_rreq_process(int sd, u_char * ptr, size_t * len)
6072 priority);
6073 if (rptr) {
6074 rpriority = rptr->sr_priority;
6075- smux_list_detach(&PassiveRegs, &rptr);
6076+ smux_list_detach(&PassiveRegs, rptr);
6077 free(rptr);
6078 smux_send_rrsp(sd, rpriority);
6079 return ptr;
6080@@ -1104,7 +1108,7 @@ smux_rreq_process(int sd, u_char * ptr, size_t * len)
6081 snmp_oid_compare(oid_name, oid_name_len, rptr->sr_name,
6082 rptr->sr_name_len);
6083 if (result == 0) {
6084- if ((oid_name_len == rptr->sr_name_len)) {
6085+ if (oid_name_len == rptr->sr_name_len) {
6086 if ((nrptr->sr_priority == -1)) {
6087 nrptr->sr_priority = rptr->sr_priority;
6088 do {
6089@@ -1154,9 +1158,17 @@ smux_rreq_process(int sd, u_char * ptr, size_t * len)
6090 if (nrptr->sr_priority == -1)
6091 nrptr->sr_priority = 0;
6092 smux_list_add(&ActiveRegs, nrptr);
6093- register_mib("smux", (struct variable *)
6094- smux_variables, sizeof(struct variable2),
6095- 1, nrptr->sr_name, nrptr->sr_name_len);
6096+ if (register_mib("smux", (struct variable *)
6097+ smux_variables, sizeof(struct variable2),
6098+ 1, nrptr->sr_name, nrptr->sr_name_len)
6099+ != SNMPERR_SUCCESS) {
6100+ DEBUGMSGTL(("smux", "[smux_rreq_process] Failed to register subtree\n"));
6101+ smux_list_detach(&ActiveRegs, nrptr);
6102+ free(nrptr);
6103+ smux_send_rrsp(sd, -1);
6104+ return NULL;
6105+ }
6106+
6107 done:
6108 smux_send_rrsp(sd, nrptr->sr_priority);
6109 return ptr;
6110@@ -1202,10 +1214,10 @@ smux_find_match(smux_reg * regs, int sd, oid * oid_name,
6111 static void
6112 smux_replace_active(smux_reg * actptr, smux_reg * pasptr)
6113 {
6114- smux_list_detach(&ActiveRegs, &actptr);
6115+ smux_list_detach(&ActiveRegs, actptr);
6116 unregister_mib(actptr->sr_name, actptr->sr_name_len);
6117
6118- smux_list_detach(&PassiveRegs, &pasptr);
6119+ smux_list_detach(&PassiveRegs, pasptr);
6120 (void) smux_list_add(&ActiveRegs, pasptr);
6121
6122 register_mib("smux", (struct variable *) smux_variables,
6123@@ -1215,7 +1227,7 @@ smux_replace_active(smux_reg * actptr, smux_reg * pasptr)
6124 }
6125
6126 static void
6127-smux_list_detach(smux_reg ** head, smux_reg ** m_remove)
6128+smux_list_detach(smux_reg ** head, smux_reg * m_remove)
6129 {
6130 smux_reg *rptr, *rptr2;
6131
6132@@ -1223,15 +1235,13 @@ smux_list_detach(smux_reg ** head, smux_reg ** m_remove)
6133 DEBUGMSGTL(("smux", "[smux_list_detach] Ouch!"));
6134 return;
6135 }
6136- if (*head == *m_remove) {
6137- *m_remove = *head;
6138+ if (*head == m_remove) {
6139 *head = (*head)->sr_next;
6140 return;
6141 }
6142 for (rptr = *head, rptr2 = rptr->sr_next; rptr2;
6143 rptr2 = rptr2->sr_next, rptr = rptr->sr_next) {
6144- if (rptr2 == *m_remove) {
6145- *m_remove = rptr2;
6146+ if (rptr2 == m_remove) {
6147 rptr->sr_next = rptr2->sr_next;
6148 return;
6149 }
6150@@ -1337,7 +1347,7 @@ smux_find_replacement(oid * name, size_t name_len)
6151 if (!snmp_oidtree_compare(rptr->sr_name, rptr->sr_name_len,
6152 name, name_len)) {
6153 if ((difflen = rptr->sr_name_len - name_len)
6154- < bestlen) {
6155+ < bestlen || !bestptr) {
6156 bestlen = difflen;
6157 bestptr = rptr;
6158 } else if ((difflen == bestlen) &&
6159@@ -1759,7 +1769,7 @@ smux_peer_cleanup(int sd)
6160 for (rptr = PassiveRegs; rptr; rptr = nrptr) {
6161 nrptr = rptr->sr_next;
6162 if (rptr->sr_fd == sd) {
6163- smux_list_detach(&PassiveRegs, &rptr);
6164+ smux_list_detach(&PassiveRegs, rptr);
6165 free(rptr);
6166 }
6167 rptr = nrptr;
6168@@ -1770,12 +1780,12 @@ smux_peer_cleanup(int sd)
6169 for (rptr = ActiveRegs; rptr; rptr = rptr2) {
6170 rptr2 = rptr->sr_next;
6171 if (rptr->sr_fd == sd) {
6172- smux_list_detach(&ActiveRegs, &rptr);
6173+ smux_list_detach(&ActiveRegs, rptr);
6174 unregister_mib(rptr->sr_name, rptr->sr_name_len);
6175 if ((nrptr = smux_find_replacement(rptr->sr_name,
6176 rptr->sr_name_len)) !=
6177 NULL) {
6178- smux_list_detach(&PassiveRegs, &nrptr);
6179+ smux_list_detach(&PassiveRegs, nrptr);
6180 smux_list_add(&ActiveRegs, nrptr);
6181 register_mib("smux", (struct variable *)
6182 smux_variables, sizeof(struct variable2),
6183diff --git a/agent/mibgroup/smux/snmp_bgp.c b/agent/mibgroup/smux/snmp_bgp.c
6184index 70596a1..16b0185 100644
6185--- a/agent/mibgroup/smux/snmp_bgp.c
6186+++ b/agent/mibgroup/smux/snmp_bgp.c
6187@@ -109,8 +109,6 @@ init_snmp_bdp(void)
6188 bgp_variables_oid);
6189 }
6190
6191-
6192-#endif
6193 static oid max_bgp_mib[] =
6194 { 1, 3, 6, 1, 2, 1, 15, 5, 1, 6, 255, 255, 255, 255 };
6195 static oid min_bgp_mib[] = { 1, 3, 6, 1, 2, 1, 15, 1, 0 };
6196diff --git a/agent/mibgroup/snmp-notification-mib/snmpNotifyFilterTable/snmpNotifyFilterTable_data_access.c b/agent/mibgroup/snmp-notification-mib/snmpNotifyFilterTable/snmpNotifyFilterTable_data_access.c
6197index fd7ab8e..942a865 100644
6198--- a/agent/mibgroup/snmp-notification-mib/snmpNotifyFilterTable/snmpNotifyFilterTable_data_access.c
6199+++ b/agent/mibgroup/snmp-notification-mib/snmpNotifyFilterTable/snmpNotifyFilterTable_data_access.c
6200@@ -247,7 +247,7 @@ snmpNotifyFilterTable_container_load(netsnmp_container *container)
6201 }
6202
6203 DEBUGMSGT(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_container_load",
6204- "inserted %lu records\n", (long)count));
6205+ "inserted %" NETSNMP_PRIz "u records\n", count));
6206
6207 return MFD_SUCCESS;
6208 } /* snmpNotifyFilterTable_container_load */
6209diff --git a/agent/mibgroup/target/snmpTargetAddrEntry.c b/agent/mibgroup/target/snmpTargetAddrEntry.c
6210index ac77d52..50cfed6 100644
6211--- a/agent/mibgroup/target/snmpTargetAddrEntry.c
6212+++ b/agent/mibgroup/target/snmpTargetAddrEntry.c
6213@@ -372,9 +372,7 @@ snmpTargetAddr_addName(struct targetAddrTable_struct *entry, char *cptr)
6214 "ERROR snmpTargetAddrEntry: name out of range in config string\n"));
6215 return (0);
6216 }
6217- entry->name = (char *) malloc(len + 1);
6218- strncpy(entry->name, cptr, len);
6219- entry->name[len] = '\0';
6220+ entry->name = strdup(cptr);
6221 }
6222 return (1);
6223 } /* addName */
6224@@ -508,9 +506,7 @@ snmpTargetAddr_addTagList(struct targetAddrTable_struct *entry, char *cptr)
6225 return (0);
6226 }
6227 SNMP_FREE(entry->tagList);
6228- entry->tagList = (char *) malloc(len + 1);
6229- strncpy(entry->tagList, cptr, len);
6230- entry->tagList[len] = '\0';
6231+ entry->tagList = strdup(cptr);
6232 }
6233 return (1);
6234 } /* snmpTargetAddr_addTagList */
6235@@ -534,9 +530,7 @@ snmpTargetAddr_addParams(struct targetAddrTable_struct *entry, char *cptr)
6236 "ERROR snmpTargetAddrEntry: params out of range in config string\n"));
6237 return (0);
6238 }
6239- entry->params = (char *) malloc(len + 1);
6240- strncpy(entry->params, cptr, len);
6241- entry->params[len] = '\0';
6242+ entry->params = strdup(cptr);
6243 }
6244 return (1);
6245 } /* snmpTargetAddr_addParams */
6246@@ -725,10 +719,7 @@ store_snmpTargetAddrEntry(int majorID, int minorID, void *serverarg,
6247 (int) curr_struct->tDomain[i]);
6248 line[ sizeof(line)-1 ] = 0;
6249 }
6250- if ( strlen(line)+2 < sizeof(line) ) {
6251- line[ strlen(line)+1 ] = 0;
6252- line[ strlen(line) ] = ' ';
6253- }
6254+ strlcat(line, " ", sizeof(line));
6255 read_config_save_octet_string(&line[strlen(line)],
6256 curr_struct->tAddress,
6257 curr_struct->tAddressLen);
6258@@ -860,7 +851,7 @@ var_snmpTargetAddrEntry(struct variable * vp,
6259
6260 case SNMPTARGETADDRTAGLIST:
6261 if (temp_struct->tagList != NULL) {
6262- strcpy(string, temp_struct->tagList);
6263+ strlcpy(string, temp_struct->tagList, sizeof(string));
6264 *var_len = strlen(string);
6265 return (unsigned char *) string;
6266 } else {
6267@@ -870,7 +861,7 @@ var_snmpTargetAddrEntry(struct variable * vp,
6268 case SNMPTARGETADDRPARAMS:
6269 if (temp_struct->params == NULL)
6270 return NULL;
6271- strcpy(string, temp_struct->params);
6272+ strlcpy(string, temp_struct->params, sizeof(string));
6273 *var_len = strlen(string);
6274 return (unsigned char *) string;
6275
6276@@ -1342,7 +1333,7 @@ write_snmpTargetAddrParams(int action,
6277 }
6278
6279 old_params = target->params;
6280- target->params = (char*)malloc(var_val_len + 1);
6281+ target->params = malloc(var_val_len + 1);
6282 if (target->params == NULL) {
6283 return SNMP_ERR_RESOURCEUNAVAILABLE;
6284 }
6285diff --git a/agent/mibgroup/target/snmpTargetParamsEntry.c b/agent/mibgroup/target/snmpTargetParamsEntry.c
6286index 3a796c8..eed43f0 100644
6287--- a/agent/mibgroup/target/snmpTargetParamsEntry.c
6288+++ b/agent/mibgroup/target/snmpTargetParamsEntry.c
6289@@ -319,9 +319,7 @@ snmpTargetParams_addParamName(struct targetParamTable_struct *entry,
6290 "ERROR snmpTargetParamsEntry: param name out of range in config string\n"));
6291 return (0);
6292 }
6293- entry->paramName = (char *) malloc(len + 1);
6294- strncpy(entry->paramName, cptr, len);
6295- entry->paramName[len] = '\0';
6296+ entry->paramName = strdup(cptr);
6297 }
6298 return (1);
6299 }
6300@@ -382,16 +380,12 @@ int
6301 snmpTargetParams_addSecName(struct targetParamTable_struct *entry,
6302 char *cptr)
6303 {
6304- size_t len;
6305 if (cptr == NULL) {
6306 DEBUGMSGTL(("snmpTargetParamsEntry",
6307 "ERROR snmpTargetParamsEntry: no security name in config string\n"));
6308 return (0);
6309 } else {
6310- len = strlen(cptr);
6311- entry->secName = (char *) malloc(len + 1);
6312- strncpy(entry->secName, cptr, len);
6313- entry->secName[len] = '\0';
6314+ entry->secName = strdup(cptr);
6315 }
6316 return (1);
6317 } /* snmpTargetParams_addSecName */
6318diff --git a/agent/mibgroup/target/snmpTargetParamsEntry.h b/agent/mibgroup/target/snmpTargetParamsEntry.h
6319index 2bd6e25..bd30582 100644
6320--- a/agent/mibgroup/target/snmpTargetParamsEntry.h
6321+++ b/agent/mibgroup/target/snmpTargetParamsEntry.h
6322@@ -47,6 +47,7 @@
6323 targetParamTable_struct
6324 *newEntry);
6325 struct targetParamTable_struct *snmpTargetParamTable_create(void);
6326+ void snmpTargetParamTable_dispose(struct targetParamTable_struct *);
6327
6328 /*
6329 * function definitions
6330diff --git a/agent/mibgroup/tcp-mib/data_access/tcpConn_linux.c b/agent/mibgroup/tcp-mib/data_access/tcpConn_linux.c
6331index ec0cbf0..9a5b466 100644
6332--- a/agent/mibgroup/tcp-mib/data_access/tcpConn_linux.c
6333+++ b/agent/mibgroup/tcp-mib/data_access/tcpConn_linux.c
6334@@ -291,7 +291,7 @@ _load6(netsnmp_container *container, u_int load_flags)
6335 */
6336 while (fgets(line, sizeof(line), in)) {
6337 netsnmp_tcpconn_entry *entry;
6338- int state, rc, local_port, remote_port, tmp_state;
6339+ int state, local_port, remote_port, tmp_state;
6340 unsigned long long inode;
6341 size_t buf_len, offset;
6342 char local_addr[48], remote_addr[48];
6343diff --git a/agent/mibgroup/tlstm-mib/snmpTlstmAddrTable/snmpTlstmAddrTable.c b/agent/mibgroup/tlstm-mib/snmpTlstmAddrTable/snmpTlstmAddrTable.c
6344index f8df440..5493ff9 100644
6345--- a/agent/mibgroup/tlstm-mib/snmpTlstmAddrTable/snmpTlstmAddrTable.c
6346+++ b/agent/mibgroup/tlstm-mib/snmpTlstmAddrTable/snmpTlstmAddrTable.c
6347@@ -1415,8 +1415,7 @@ _tlstmAddrTable_row_restore_mib(const char *token, char *buf)
6348 addr->hashType = hashType;
6349 addr->flags = TLSTM_ADDR_FROM_MIB | TLSTM_ADDR_NONVOLATILE;
6350
6351- if (netsnmp_tlstmAddr_add(addr) != 0)
6352- netsnmp_tlstmAddr_free(addr);
6353+ netsnmp_tlstmAddr_add(addr);
6354 }
6355 else {
6356 netsnmp_tdata_row *row;
6357diff --git a/agent/mibgroup/tlstm-mib/snmpTlstmParamsTable/snmpTlstmParamsTable.c b/agent/mibgroup/tlstm-mib/snmpTlstmParamsTable/snmpTlstmParamsTable.c
6358index 7027114..cd54452 100644
6359--- a/agent/mibgroup/tlstm-mib/snmpTlstmParamsTable/snmpTlstmParamsTable.c
6360+++ b/agent/mibgroup/tlstm-mib/snmpTlstmParamsTable/snmpTlstmParamsTable.c
6361@@ -1275,7 +1275,7 @@ _tlstmParamsTable_row_restore_mib(const char *token, char *buf)
6362 entry = row->data;
6363
6364 entry->hashType = params->hashType;
6365- strncpy(entry->snmpTlstmParamsClientFingerprint,params->fingerprint,
6366+ strlcpy(entry->snmpTlstmParamsClientFingerprint, params->fingerprint,
6367 sizeof(entry->snmpTlstmParamsClientFingerprint));
6368 entry->snmpTlstmParamsClientFingerprint_len =
6369 strlen(entry->snmpTlstmParamsClientFingerprint);
6370diff --git a/agent/mibgroup/ucd-snmp/disk.c b/agent/mibgroup/ucd-snmp/disk.c
6371index 70f67f5..324fbc4 100644
6372--- a/agent/mibgroup/ucd-snmp/disk.c
6373+++ b/agent/mibgroup/ucd-snmp/disk.c
6374@@ -409,9 +409,8 @@ add_device(char *path, char *device, int minspace, int minpercent, int override)
6375 /* add if and only if the device was found */
6376 if(device[0] != 0) {
6377 /* The following buffers are cleared above, no need to add '\0' */
6378- strncpy(disks[numdisks].path, path, sizeof(disks[numdisks].path) - 1);
6379- strncpy(disks[numdisks].device, device,
6380- sizeof(disks[numdisks].device) - 1);
6381+ strlcpy(disks[numdisks].path, path, sizeof(disks[numdisks].path));
6382+ strlcpy(disks[numdisks].device, device, sizeof(disks[numdisks].device));
6383 disks[numdisks].minimumspace = minspace;
6384 disks[numdisks].minpercent = minpercent;
6385 numdisks++;
6386@@ -595,8 +594,7 @@ find_device(char *path)
6387 }
6388 while (mntfp && NULL != (mntent = getmntent(mntfp)))
6389 if (strcmp(path, mntent->mnt_dir) == 0) {
6390- strncpy(device, mntent->mnt_fsname, sizeof(device));
6391- device[sizeof(device) - 1] = '\0';
6392+ strlcpy(device, mntent->mnt_fsname, sizeof(device));
6393 DEBUGMSGTL(("ucd-snmp/disk", "Disk: %s\n",
6394 mntent->mnt_fsname));
6395 break;
6396@@ -620,18 +618,14 @@ find_device(char *path)
6397 path, mnttab.mnt_mountp));
6398 }
6399 fclose(mntfp);
6400- if (i == 0) {
6401- strncpy(device, mnttab.mnt_special, sizeof(device));
6402- device[sizeof(device) - 1] = '\0';
6403- }
6404+ if (i == 0)
6405+ strlcpy(device, mnttab.mnt_special, sizeof(device));
6406 #endif /* HAVE_SETMNTENT */
6407 #elif HAVE_FSTAB_H
6408 stat(path, &stat1);
6409 setfsent();
6410- if ((fstab = getfsfile(path))) {
6411- strncpy(device, fstab->fs_spec, sizeof(device));
6412- device[sizeof(device) - 1] = '\0';
6413- }
6414+ if ((fstab = getfsfile(path)))
6415+ strlcpy(device, fstab->fs_spec, sizeof(device));
6416 endfsent();
6417 if (device[0] != '\0') {
6418 /*
6419@@ -641,8 +635,7 @@ find_device(char *path)
6420
6421 #elif HAVE_STATFS
6422 if (statfs(path, &statf) == 0) {
6423- strncpy(device, statf.f_mntfromname, sizeof(device) - 1);
6424- device[sizeof(device) - 1] = '\0';
6425+ strlcpy(device, statf.f_mntfromname, sizeof(device));
6426 DEBUGMSGTL(("ucd-snmp/disk", "Disk: %s\n",
6427 statf.f_mntfromname));
6428 }
6429diff --git a/agent/mibgroup/ucd-snmp/disk_hw.c b/agent/mibgroup/ucd-snmp/disk_hw.c
6430index 6fb9418..ba26479 100644
6431--- a/agent/mibgroup/ucd-snmp/disk_hw.c
6432+++ b/agent/mibgroup/ucd-snmp/disk_hw.c
6433@@ -1,5 +1,5 @@
6434 /*
6435- * disk.c
6436+ * disk_hw.c
6437 */
6438
6439 #include <net-snmp/net-snmp-config.h>
6440@@ -137,6 +137,7 @@ disk_free_config(void)
6441 if (disks) {
6442 free( disks );
6443 disks = NULL;
6444+ maxdisks = numdisks = 0;
6445 }
6446 allDisksIncluded = 0;
6447 }
6448@@ -321,7 +322,7 @@ tryAgain:
6449
6450 switch (vp->magic) {
6451 case MIBINDEX:
6452- long_ret = disknum;
6453+ long_ret = disknum + 1;
6454 return ((u_char *) (&long_ret));
6455 case ERRORNAME: /* DISKPATH */
6456 *var_len = strlen(entry->path);
6457diff --git a/agent/mibgroup/ucd-snmp/diskio.c b/agent/mibgroup/ucd-snmp/diskio.c
6458index 769a365..4d6d05c 100644
6459--- a/agent/mibgroup/ucd-snmp/diskio.c
6460+++ b/agent/mibgroup/ucd-snmp/diskio.c
6461@@ -502,7 +502,8 @@ getstats(void)
6462 {
6463 time_t now;
6464 char *t, *tp;
6465- int size, dkn_size, i;
6466+ size_t size, dkn_size;
6467+ int i;
6468
6469 now = time(NULL);
6470 if (cache_time + CACHE_TIMEOUT > now) {
6471@@ -526,6 +527,7 @@ getstats(void)
6472 if (ndisk == 0)
6473 return 0;
6474 dkname = malloc(ndisk * sizeof(char *));
6475+ dkn_size = 0;
6476 if (sysctl(nmib, 2, NULL, &dkn_size, NULL, 0) < 0) {
6477 perror("Can't get size of HW_DISKNAMES mib");
6478 return 0;
6479diff --git a/agent/mibgroup/ucd-snmp/dlmod.c b/agent/mibgroup/ucd-snmp/dlmod.c
6480index eecd38f..e9742f2 100644
6481--- a/agent/mibgroup/ucd-snmp/dlmod.c
6482+++ b/agent/mibgroup/ucd-snmp/dlmod.c
6483@@ -18,8 +18,6 @@
6484 #include <net-snmp/net-snmp-includes.h>
6485 #include <net-snmp/agent/net-snmp-agent-includes.h>
6486
6487-#if defined(HAVE_DLFCN_H) && defined(HAVE_DLOPEN)
6488-
6489 #include <dlfcn.h>
6490 #include "dlmod.h"
6491
6492@@ -124,7 +122,7 @@ dlmod_load_module(struct dlmod *dlm)
6493 dlm->status = DLMOD_ERROR;
6494 }
6495 }
6496- strncpy(dlm->path, tmp_path, sizeof(dlm->path));
6497+ strlcpy(dlm->path, tmp_path, sizeof(dlm->path));
6498 if (dlm->status == DLMOD_ERROR)
6499 return;
6500 }
6501@@ -219,16 +217,16 @@ dlmod_parse_config(const char *token, char *cptr)
6502 dlmod_delete_module(dlm);
6503 return;
6504 }
6505- strncpy(dlm->name, dlm_name, sizeof(dlm->name));
6506+ strlcpy(dlm->name, dlm_name, sizeof(dlm->name));
6507
6508 /*
6509 * dynamic module path
6510 */
6511 dlm_path = strtok_r(NULL, "\t ", &st);
6512 if (dlm_path)
6513- strncpy(dlm->path, dlm_path, sizeof(dlm->path));
6514+ strlcpy(dlm->path, dlm_path, sizeof(dlm->path));
6515 else
6516- strncpy(dlm->path, dlm_name, sizeof(dlm->path));
6517+ strlcpy(dlm->path, dlm_name, sizeof(dlm->path));
6518
6519 dlmod_load_module(dlm);
6520
6521@@ -573,9 +571,6 @@ static oid dlmod_variables_oid[] = { 1, 3, 6, 1, 4, 1, 2021, 13, 14 };
6522 void
6523 init_dlmod(void)
6524 {
6525- char *p;
6526- int len;
6527-
6528 REGISTER_MIB("dlmod", dlmod_variables, variable4, dlmod_variables_oid);
6529
6530 /*
6531@@ -588,20 +583,23 @@ init_dlmod(void)
6532 dlmod_free_config,
6533 "module-name module-path");
6534
6535- p = getenv("SNMPDLMODPATH");
6536- strncpy(dlmod_path, SNMPDLMODPATH, sizeof(dlmod_path));
6537- dlmod_path[ sizeof(dlmod_path)-1 ] = 0;
6538- if (p) {
6539- if (p[0] == ':') {
6540- len = strlen(dlmod_path);
6541- if (dlmod_path[len - 1] != ':') {
6542- strncat(dlmod_path, ":", sizeof(dlmod_path) - len -1);
6543- len++;
6544- }
6545- strncat(dlmod_path, p + 1, sizeof(dlmod_path) - len);
6546- } else
6547- strncpy(dlmod_path, p, sizeof(dlmod_path));
6548+ {
6549+ const char * const p = getenv("SNMPDLMODPATH");
6550+ strncpy(dlmod_path, SNMPDLMODPATH, sizeof(dlmod_path));
6551+ dlmod_path[ sizeof(dlmod_path) - 1 ] = 0;
6552+ if (p) {
6553+ if (p[0] == ':') {
6554+ int len = strlen(dlmod_path);
6555+ if (dlmod_path[len - 1] != ':') {
6556+ strncat(dlmod_path, ":", sizeof(dlmod_path) - len - 1);
6557+ len++;
6558+ }
6559+ strncat(dlmod_path, p + 1, sizeof(dlmod_path) - len);
6560+ } else
6561+ strncpy(dlmod_path, p, sizeof(dlmod_path));
6562+ }
6563 }
6564+
6565 dlmod_path[ sizeof(dlmod_path)-1 ] = 0;
6566 DEBUGMSGTL(("dlmod", "dlmod_path: %s\n", dlmod_path));
6567 }
6568@@ -614,19 +612,3 @@ shutdown_dlmod(void)
6569 snmpd_unregister_config_handler("dlmod");
6570 unregister_mib(dlmod_variables_oid, OID_LENGTH(dlmod_variables_oid));
6571 }
6572-
6573-#else /* no dlopen support */
6574-
6575-void
6576-init_dlmod(void)
6577-{
6578- DEBUGMSGTL(("dlmod",
6579- "Dynamic modules not support on this platform\n"));
6580-}
6581-
6582-void
6583-shutdown_dlmod(void)
6584-{
6585-}
6586-
6587-#endif
6588diff --git a/agent/mibgroup/ucd-snmp/dlmod.h b/agent/mibgroup/ucd-snmp/dlmod.h
6589index 79d960b..df8bef7 100644
6590--- a/agent/mibgroup/ucd-snmp/dlmod.h
6591+++ b/agent/mibgroup/ucd-snmp/dlmod.h
6592@@ -6,6 +6,10 @@
6593 #ifndef MIBGROUP_DLMOD_H
6594 #define MIBGROUP_DLMOD_H
6595
6596+#if !defined(HAVE_DLFCN_H) || !defined(HAVE_DLOPEN)
6597+config_error(Dynamic modules not supported on this platform)
6598+#endif
6599+
6600 config_add_mib(UCD-DLMOD-MIB)
6601
6602 void init_dlmod(void);
6603diff --git a/agent/mibgroup/ucd-snmp/errormib.c b/agent/mibgroup/ucd-snmp/errormib.c
6604index cbdd25b..7f3bcb1 100644
6605--- a/agent/mibgroup/ucd-snmp/errormib.c
6606+++ b/agent/mibgroup/ucd-snmp/errormib.c
6607@@ -137,8 +137,7 @@ seterrorstatus(const char *to, int prior)
6608 {
6609 if (errorstatusprior <= prior ||
6610 (NETSNMP_ERRORTIMELENGTH < (time(NULL) - errorstatustime))) {
6611- strncpy(errorstring, to, sizeof(errorstring));
6612- errorstring[ sizeof(errorstring)-1 ] = 0;
6613+ strlcpy(errorstring, to, sizeof(errorstring));
6614 errorstatusprior = prior;
6615 errorstatustime = time(NULL);
6616 }
6617@@ -219,8 +218,7 @@ var_extensible_errors(struct variable *vp,
6618 return ((u_char *) (&long_ret));
6619 case ERRORMSG:
6620 if ((NETSNMP_ERRORTIMELENGTH >= time(NULL) - errorstatustime) ? 1 : 0) {
6621- strncpy(errmsg, errorstring, sizeof(errmsg));
6622- errmsg[ sizeof(errmsg)-1 ] = 0;
6623+ strlcpy(errmsg, errorstring, sizeof(errmsg));
6624 } else
6625 errmsg[0] = 0;
6626 *var_len = strlen(errmsg);
6627diff --git a/agent/mibgroup/ucd-snmp/extensible.c b/agent/mibgroup/ucd-snmp/extensible.c
6628index edea93a..d1752ef 100644
6629--- a/agent/mibgroup/ucd-snmp/extensible.c
6630+++ b/agent/mibgroup/ucd-snmp/extensible.c
6631@@ -262,8 +262,7 @@ extensible_parse_config(const char *token, char *cptr)
6632 for (tcptr = cptr; *tcptr != 0 && *tcptr != '#'; tcptr++)
6633 if (*tcptr == ';' && ptmp->type == EXECPROC)
6634 break;
6635- strncpy(ptmp->command, cptr, tcptr - cptr);
6636- ptmp->command[tcptr - cptr] = 0;
6637+ sprintf(ptmp->command, "%.*s", (int) (tcptr - cptr), cptr);
6638 }
6639 #ifdef NETSNMP_EXECFIXCMD
6640 sprintf(ptmp->fixcmd, NETSNMP_EXECFIXCMD, ptmp->name);
6641@@ -419,8 +418,7 @@ execfix_parse_config(const char *token, char *cptr)
6642 return;
6643 }
6644
6645- strncpy(execp->fixcmd, cptr, sizeof(execp->fixcmd));
6646- execp->fixcmd[ sizeof(execp->fixcmd)-1 ] = 0;
6647+ strlcpy(execp->fixcmd, cptr, sizeof(execp->fixcmd));
6648 }
6649
6650 u_char *
6651@@ -623,8 +621,7 @@ var_extensible_relocatable(struct variable *vp,
6652 cp = strchr(cp1, '\n');
6653 if (cp)
6654 *cp = 0;
6655- strncpy(errmsg, cp1, sizeof(errmsg));
6656- errmsg[ sizeof(errmsg)-1 ] = 0;
6657+ strlcpy(errmsg, cp1, sizeof(errmsg));
6658 *var_len = strlen(errmsg);
6659 if (errmsg[*var_len - 1] == '\n')
6660 errmsg[--(*var_len)] = '\0';
6661diff --git a/agent/mibgroup/ucd-snmp/lmSensors.c b/agent/mibgroup/ucd-snmp/lmSensors.c
6662index d6436bf..05c60b7 100644
6663--- a/agent/mibgroup/ucd-snmp/lmSensors.c
6664+++ b/agent/mibgroup/ucd-snmp/lmSensors.c
6665@@ -331,7 +331,7 @@ var_lmSensorsTable(struct variable *vp,
6666 case LMFANSENSORSDEVICE:
6667 case LMVOLTSENSORSDEVICE:
6668 case LMMISCSENSORSDEVICE:
6669- strncpy(string, s.name, SPRINT_MAX_LEN - 1);
6670+ strlcpy(string, s.name, sizeof(string));
6671 *var_len = strlen(string);
6672 ret = (unsigned char *) string;
6673 goto leaving;
6674@@ -891,32 +891,32 @@ else{
6675 DEBUGMSG(("ucd-snmp/lmSensors", "front panel value %d\n",enc_info->value));
6676 typ = 3; /* misc */
6677 sensor_array[typ].sensor[other].value = enc_info->value;
6678- strncpy(sensor_array[typ].sensor[other].name,"FSP",MAX_NAME-1);
6679- sensor_array[typ].sensor[other].name[MAX_NAME-1]='\0'; /* null terminate */
6680+ strlcpy(sensor_array[typ].sensor[other].name, "FSP",
6681+ MAX_NAME);
6682 other++;
6683 break;
6684 case ENVCTRL_ENCL_AMBTEMPR:
6685 DEBUGMSG(("ucd-snmp/lmSensors", "ambient temp mC %d\n",enc_info->value*1000));
6686 typ = 0; /* temperature sensor */
6687 sensor_array[typ].sensor[temp].value = enc_info->value*1000;
6688- strncpy(sensor_array[typ].sensor[temp].name,"Ambient",MAX_NAME-1);
6689- sensor_array[typ].sensor[temp].name[MAX_NAME-1]='\0'; /* null terminate */
6690+ strlcpy(sensor_array[typ].sensor[temp].name, "Ambient",
6691+ MAX_NAME);
6692 temp++;
6693 break;
6694 case ENVCTRL_ENCL_BACKPLANE4:
6695 DEBUGMSG(("ucd-snmp/lmSensors", "There is a backplane4\n"));
6696 typ = 3; /* misc */
6697 sensor_array[typ].sensor[other].value = enc_info->value;
6698- strncpy(sensor_array[typ].sensor[other].name,"Backplane4",MAX_NAME-1);
6699- sensor_array[typ].sensor[other].name[MAX_NAME-1]='\0'; /* null terminate */
6700+ strlcpy(sensor_array[typ].sensor[other].name, "Backplane4",
6701+ MAX_NAME);
6702 other++;
6703 break;
6704 case ENVCTRL_ENCL_BACKPLANE8:
6705 DEBUGMSG(("ucd-snmp/lmSensors", "There is a backplane8\n"));
6706 typ = 3; /* misc */
6707 sensor_array[typ].sensor[other].value = enc_info->value;
6708- strncpy(sensor_array[typ].sensor[other].name,"Backplane8",MAX_NAME-1);
6709- sensor_array[typ].sensor[other].name[MAX_NAME-1]='\0'; /* null terminate */
6710+ strlcpy(sensor_array[typ].sensor[other].name, "Backplane8",
6711+ MAX_NAME);
6712 other++;
6713 break;
6714 case ENVCTRL_ENCL_CPUTEMPR:
6715@@ -1029,7 +1029,7 @@ else{
6716 array->current_len = new_size / sizeof(_sensor);
6717 DEBUGMSG(("ucd-snmp/lmSensors", "type #%d increased to %d elements\n", type, (int)array->current_len));
6718 } /* end if array->current */
6719- strncpy(array->sensor[array->n].name, label, MAX_NAME);
6720+ strlcpy(array->sensor[array->n].name, label, MAX_NAME);
6721 array->sensor[array->n].value = (int) (val * mul);
6722 DEBUGMSGTL(("sensors","sensor %s, value %d\n",
6723 array->sensor[array->n].name,
6724diff --git a/agent/mibgroup/ucd-snmp/loadave.c b/agent/mibgroup/ucd-snmp/loadave.c
6725index 2321d29..6efc5e9 100644
6726--- a/agent/mibgroup/ucd-snmp/loadave.c
6727+++ b/agent/mibgroup/ucd-snmp/loadave.c
6728@@ -393,8 +393,7 @@ write_laConfig(int action,
6729 double val;
6730 char *endp;
6731
6732- strncpy(buf, (char *)var_val, var_val_len);
6733- buf[var_val_len] = '\0';
6734+ sprintf(buf, "%.*s", (int) var_val_len, (char *)var_val);
6735 val = strtod(buf, &endp);
6736
6737 if (errno == ERANGE || *endp != '\0' || val < 0 || val > 65536.00) {
6738@@ -481,10 +480,12 @@ var_extensible_loadave(struct variable * vp,
6739 if (maxload[name[*length - 1] - 1] != 0 &&
6740 avenrun[name[*length - 1] - 1] >=
6741 maxload[name[*length - 1] - 1]) {
6742- sprintf(errmsg, "%d min Load Average too high (= %.2f)",
6743+ snprintf(errmsg, sizeof(errmsg),
6744+ "%d min Load Average too high (= %.2f)",
6745 (name[*length - 1] ==
6746 1) ? 1 : ((name[*length - 1] == 2) ? 5 : 15),
6747 avenrun[name[*length - 1] - 1]);
6748+ errmsg[sizeof(errmsg) - 1] = '\0';
6749 } else {
6750 errmsg[0] = 0;
6751 }
6752diff --git a/agent/mibgroup/ucd-snmp/logmatch.c b/agent/mibgroup/ucd-snmp/logmatch.c
6753index eb21a68..abca5ce 100644
6754--- a/agent/mibgroup/ucd-snmp/logmatch.c
6755+++ b/agent/mibgroup/ucd-snmp/logmatch.c
6756@@ -110,7 +110,6 @@ static void
6757 updateLogmatch(int iindex)
6758 {
6759
6760- regmatch_t myMatch;
6761 int matchResultCode;
6762 char inbuf[1024];
6763 char perfilename[1024];
6764@@ -288,7 +287,7 @@ updateLogmatch(int iindex)
6765
6766 matchResultCode =
6767 regexec(&(logmatchTable[iindex].regexBuffer),
6768- inbuf, 0, &myMatch, REG_NOTEOL);
6769+ inbuf, 0, NULL, REG_NOTEOL);
6770
6771 if (matchResultCode == 0) {
6772 logmatchTable[iindex].globalMatchCounter++;
6773diff --git a/agent/mibgroup/ucd-snmp/pass.c b/agent/mibgroup/ucd-snmp/pass.c
6774index 4440baa..ac14b41 100644
6775--- a/agent/mibgroup/ucd-snmp/pass.c
6776+++ b/agent/mibgroup/ucd-snmp/pass.c
6777@@ -33,6 +33,7 @@
6778
6779 #include "struct.h"
6780 #include "pass.h"
6781+#include "pass_common.h"
6782 #include "extensible.h"
6783 #include "util_funcs.h"
6784
6785@@ -55,152 +56,6 @@ struct variable2 extensible_passthru_variables[] = {
6786
6787
6788
6789-/*
6790- * lexicographical compare two object identifiers.
6791- * * Returns -1 if name1 < name2,
6792- * * 0 if name1 = name2,
6793- * * 1 if name1 > name2
6794- * *
6795- * * This method differs from snmp_oid_compare
6796- * * in that the comparison stops at the length
6797- * * of the smallest object identifier.
6798- */
6799-int
6800-snmp_oid_min_compare(const oid * in_name1,
6801- size_t len1, const oid * in_name2, size_t len2)
6802-{
6803- register int len;
6804- register const oid *name1 = in_name1;
6805- register const oid *name2 = in_name2;
6806-
6807- /*
6808- * len = minimum of len1 and len2
6809- */
6810- if (len1 < len2)
6811- len = len1;
6812- else
6813- len = len2;
6814- /*
6815- * find first non-matching OID
6816- */
6817- while (len-- > 0) {
6818- /*
6819- * these must be done in seperate comparisons, since
6820- * subtracting them and using that result has problems with
6821- * subids > 2^31.
6822- */
6823- if (*(name1) < *(name2))
6824- return -1;
6825- if (*(name1++) > *(name2++))
6826- return 1;
6827- }
6828- /*
6829- * both OIDs equal up to length of shorter OID
6830- */
6831-
6832- return 0;
6833-}
6834-
6835-
6836-/*
6837- * This is also called from pass_persist.c
6838- */
6839-int
6840-asc2bin(char *p)
6841-{
6842- char *r, *q = p;
6843- char c;
6844- int n = 0;
6845-
6846- for (;;) {
6847- c = (char) strtol(q, &r, 16);
6848- if (r == q)
6849- break;
6850- *p++ = c;
6851- q = r;
6852- n++;
6853- }
6854- return n;
6855-}
6856-
6857-/*
6858- * This is also called from pass_persist.c
6859- */
6860-int
6861-bin2asc(char *p, size_t n)
6862-{
6863- size_t i, flag = 0;
6864- char buffer[SNMP_MAXBUF];
6865-
6866- /* prevent buffer overflow */
6867- if (n > (sizeof(buffer) - 1))
6868- n = sizeof(buffer) - 1;
6869-
6870- for (i = 0; i < n; i++) {
6871- buffer[i] = p[i];
6872- if (!isprint((unsigned char)(p[i])))
6873- flag = 1;
6874- }
6875- if (flag == 0) {
6876- p[n] = 0;
6877- return n;
6878- }
6879- for (i = 0; i < n; i++) {
6880- sprintf(p, "%02x ", (unsigned char) (buffer[i] & 0xff));
6881- p += 3;
6882- }
6883- *--p = 0;
6884- return 3 * n - 1;
6885-}
6886-
6887-/*
6888- * This is also called from pass_persist.c
6889- */
6890-int
6891-netsnmp_pass_str_to_errno(const char *buf)
6892-{
6893- if (!strncasecmp(buf, "too-big", 7)) {
6894- /* Shouldn't happen */
6895- return SNMP_ERR_TOOBIG;
6896- } else if (!strncasecmp(buf, "no-such-name", 12)) {
6897- return SNMP_ERR_NOSUCHNAME;
6898- } else if (!strncasecmp(buf, "bad-value", 9)) {
6899- return SNMP_ERR_BADVALUE;
6900- } else if (!strncasecmp(buf, "read-only", 9)) {
6901- return SNMP_ERR_READONLY;
6902- } else if (!strncasecmp(buf, "gen-error", 9)) {
6903- return SNMP_ERR_GENERR;
6904- } else if (!strncasecmp(buf, "no-access", 9)) {
6905- return SNMP_ERR_NOACCESS;
6906- } else if (!strncasecmp(buf, "wrong-type", 10)) {
6907- return SNMP_ERR_WRONGTYPE;
6908- } else if (!strncasecmp(buf, "wrong-length", 12)) {
6909- return SNMP_ERR_WRONGLENGTH;
6910- } else if (!strncasecmp(buf, "wrong-encoding", 14)) {
6911- return SNMP_ERR_WRONGENCODING;
6912- } else if (!strncasecmp(buf, "wrong-value", 11)) {
6913- return SNMP_ERR_WRONGVALUE;
6914- } else if (!strncasecmp(buf, "no-creation", 11)) {
6915- return SNMP_ERR_NOCREATION;
6916- } else if (!strncasecmp(buf, "inconsistent-value", 18)) {
6917- return SNMP_ERR_INCONSISTENTVALUE;
6918- } else if (!strncasecmp(buf, "resource-unavailable", 20)) {
6919- return SNMP_ERR_RESOURCEUNAVAILABLE;
6920- } else if (!strncasecmp(buf, "commit-failed", 13)) {
6921- return SNMP_ERR_COMMITFAILED;
6922- } else if (!strncasecmp(buf, "undo-failed", 11)) {
6923- return SNMP_ERR_UNDOFAILED;
6924- } else if (!strncasecmp(buf, "authorization-error", 19)) {
6925- return SNMP_ERR_AUTHORIZATIONERROR;
6926- } else if (!strncasecmp(buf, "not-writable", 12)) {
6927- return SNMP_ERR_NOTWRITABLE;
6928- } else if (!strncasecmp(buf, "inconsistent-name", 17)) {
6929- return SNMP_ERR_INCONSISTENTNAME;
6930- }
6931-
6932- return SNMP_ERR_NOERROR;
6933-}
6934-
6935 void
6936 init_pass(void)
6937 {
6938@@ -276,11 +131,9 @@ pass_parse_config(const char *token, char *cptr)
6939 } else {
6940 for (tcptr = cptr; *tcptr != 0 && *tcptr != '#' && *tcptr != ';';
6941 tcptr++);
6942- strncpy((*ppass)->command, cptr, tcptr - cptr);
6943- (*ppass)->command[tcptr - cptr] = 0;
6944+ sprintf((*ppass)->command, "%.*s", (int) (tcptr - cptr), cptr);
6945 }
6946- strncpy((*ppass)->name, (*ppass)->command, sizeof((*ppass)->name));
6947- (*ppass)->name[ sizeof((*ppass)->name)-1 ] = 0;
6948+ strlcpy((*ppass)->name, (*ppass)->command, sizeof((*ppass)->name));
6949 (*ppass)->next = NULL;
6950
6951 register_mib_priority("pass", (struct variable *) extensible_passthru_variables,
6952@@ -337,18 +190,14 @@ var_extensible_pass(struct variable *vp,
6953 {
6954 oid newname[MAX_OID_LEN];
6955 int i, rtest, fd, newlen;
6956- static long long_ret;
6957- static in_addr_t addr_ret;
6958 char buf[SNMP_MAXBUF];
6959 static char buf2[SNMP_MAXBUF];
6960- static oid objid[MAX_OID_LEN];
6961 struct extensible *passthru;
6962 FILE *file;
6963
6964- long_ret = *length;
6965 for (i = 1; i <= numpassthrus; i++) {
6966 passthru = get_exten_instance(passthrus, i);
6967- rtest = snmp_oid_min_compare(name, *length,
6968+ rtest = snmp_oidtree_compare(name, *length,
6969 passthru->miboid, passthru->miblen);
6970 if ((exact && rtest == 0) || (!exact && rtest <= 0)) {
6971 /*
6972@@ -409,89 +258,7 @@ var_extensible_pass(struct variable *vp,
6973 fclose(file);
6974 wait_on_exec(passthru);
6975
6976- /*
6977- * buf contains the return type, and buf2 contains the data
6978- */
6979- if (!strncasecmp(buf, "string", 6)) {
6980- buf2[strlen(buf2) - 1] = 0; /* zap the linefeed */
6981- *var_len = strlen(buf2);
6982- vp->type = ASN_OCTET_STR;
6983- return ((unsigned char *) buf2);
6984- }
6985- else if (!strncasecmp(buf, "integer64", 9)) {
6986- static struct counter64 c64;
6987- uint64_t v64 = strtoull(buf2, NULL, 10);
6988- c64.high = (unsigned long)(v64 >> 32);
6989- c64.low = (unsigned long)(v64 & 0xffffffff);
6990- *var_len = sizeof(c64);
6991- vp->type = ASN_INTEGER64;
6992- return ((unsigned char *) &c64);
6993- }
6994- else if (!strncasecmp(buf, "integer", 7)) {
6995- *var_len = sizeof(long_ret);
6996- long_ret = strtol(buf2, NULL, 10);
6997- vp->type = ASN_INTEGER;
6998- return ((unsigned char *) &long_ret);
6999- } else if (!strncasecmp(buf, "unsigned", 8)) {
7000- *var_len = sizeof(long_ret);
7001- long_ret = strtoul(buf2, NULL, 10);
7002- vp->type = ASN_UNSIGNED;
7003- return ((unsigned char *) &long_ret);
7004- }
7005- else if (!strncasecmp(buf, "counter64", 9)) {
7006- static struct counter64 c64;
7007- uint64_t v64 = strtoull(buf2, NULL, 10);
7008- c64.high = (unsigned long)(v64 >> 32);
7009- c64.low = (unsigned long)(v64 & 0xffffffff);
7010- *var_len = sizeof(c64);
7011- vp->type = ASN_COUNTER64;
7012- return ((unsigned char *) &c64);
7013- }
7014- else if (!strncasecmp(buf, "counter", 7)) {
7015- *var_len = sizeof(long_ret);
7016- long_ret = strtoul(buf2, NULL, 10);
7017- vp->type = ASN_COUNTER;
7018- return ((unsigned char *) &long_ret);
7019- } else if (!strncasecmp(buf, "octet", 5)) {
7020- *var_len = asc2bin(buf2);
7021- vp->type = ASN_OCTET_STR;
7022- return ((unsigned char *) buf2);
7023- } else if (!strncasecmp(buf, "opaque", 6)) {
7024- *var_len = asc2bin(buf2);
7025- vp->type = ASN_OPAQUE;
7026- return ((unsigned char *) buf2);
7027- } else if (!strncasecmp(buf, "gauge", 5)) {
7028- *var_len = sizeof(long_ret);
7029- long_ret = strtoul(buf2, NULL, 10);
7030- vp->type = ASN_GAUGE;
7031- return ((unsigned char *) &long_ret);
7032- } else if (!strncasecmp(buf, "objectid", 8)) {
7033- newlen = parse_miboid(buf2, objid);
7034- *var_len = newlen * sizeof(oid);
7035- vp->type = ASN_OBJECT_ID;
7036- return ((unsigned char *) objid);
7037- } else if (!strncasecmp(buf, "timetick", 8)) {
7038- *var_len = sizeof(long_ret);
7039- long_ret = strtoul(buf2, NULL, 10);
7040- vp->type = ASN_TIMETICKS;
7041- return ((unsigned char *) &long_ret);
7042- } else if (!strncasecmp(buf, "ipaddress", 9)) {
7043- newlen = parse_miboid(buf2, objid);
7044- if (newlen != 4) {
7045- snmp_log(LOG_ERR,
7046- "invalid ipaddress returned: %s\n",
7047- buf2);
7048- *var_len = 0;
7049- return (NULL);
7050- }
7051- addr_ret =
7052- (objid[0] << (8 * 3)) + (objid[1] << (8 * 2)) +
7053- (objid[2] << 8) + objid[3];
7054- addr_ret = htonl(addr_ret);
7055- *var_len = sizeof(addr_ret);
7056- vp->type = ASN_IPADDRESS;
7057- return ((unsigned char *) &addr_ret);
7058- }
7059+ return netsnmp_internal_pass_parse(buf, buf2, var_len, vp);
7060 }
7061 *var_len = 0;
7062 return (NULL);
7063@@ -504,21 +271,16 @@ var_extensible_pass(struct variable *vp,
7064 }
7065
7066 int
7067-setPass(int action,
7068- u_char * var_val,
7069- u_char var_val_type,
7070+setPass(int action, u_char * var_val, u_char var_val_type,
7071 size_t var_val_len, u_char * statP, oid * name, size_t name_len)
7072 {
7073 int i, rtest;
7074 struct extensible *passthru;
7075-
7076 char buf[SNMP_MAXBUF], buf2[SNMP_MAXBUF];
7077- long tmp;
7078- unsigned long utmp;
7079
7080 for (i = 1; i <= numpassthrus; i++) {
7081 passthru = get_exten_instance(passthrus, i);
7082- rtest = snmp_oid_min_compare(name, name_len,
7083+ rtest = snmp_oidtree_compare(name, name_len,
7084 passthru->miboid, passthru->miblen);
7085 if (rtest <= 0) {
7086 if (action != ACTION)
7087@@ -533,60 +295,14 @@ setPass(int action,
7088 snprintf(passthru->command, sizeof(passthru->command),
7089 "%s -s %s ", passthru->name, buf);
7090 passthru->command[ sizeof(passthru->command)-1 ] = 0;
7091- switch (var_val_type) {
7092- case ASN_INTEGER:
7093- case ASN_COUNTER:
7094- case ASN_GAUGE:
7095- case ASN_TIMETICKS:
7096- tmp = *((long *) var_val);
7097- switch (var_val_type) {
7098- case ASN_INTEGER:
7099- sprintf(buf, "integer %d\n", (int) tmp);
7100- break;
7101- case ASN_COUNTER:
7102- sprintf(buf, "counter %d\n", (int) tmp);
7103- break;
7104- case ASN_GAUGE:
7105- sprintf(buf, "gauge %d\n", (int) tmp);
7106- break;
7107- case ASN_TIMETICKS:
7108- sprintf(buf, "timeticks %d\n", (int) tmp);
7109- break;
7110- }
7111- break;
7112- case ASN_IPADDRESS:
7113- utmp = *((u_long *) var_val);
7114- utmp = ntohl(utmp);
7115- sprintf(buf, "ipaddress %d.%d.%d.%d\n",
7116- (int) ((utmp & 0xff000000) >> (8 * 3)),
7117- (int) ((utmp & 0xff0000) >> (8 * 2)),
7118- (int) ((utmp & 0xff00) >> (8)),
7119- (int) ((utmp & 0xff)));
7120- break;
7121- case ASN_OCTET_STR:
7122- memcpy(buf2, var_val, var_val_len);
7123- if (var_val_len == 0)
7124- sprintf(buf, "string \"\"\n");
7125- else if (bin2asc(buf2, var_val_len) == (int) var_val_len)
7126- snprintf(buf, sizeof(buf), "string \"%s\"\n", buf2);
7127- else
7128- snprintf(buf, sizeof(buf), "octet \"%s\"\n", buf2);
7129- buf[ sizeof(buf)-1 ] = 0;
7130- break;
7131- case ASN_OBJECT_ID:
7132- sprint_mib_oid(buf2, (oid *) var_val, var_val_len/sizeof(oid));
7133- snprintf(buf, sizeof(buf), "objectid \"%s\"\n", buf2);
7134- buf[ sizeof(buf)-1 ] = 0;
7135- break;
7136- }
7137- strncat(passthru->command, buf, sizeof(passthru->command)-strlen(passthru->command)-1);
7138- passthru->command[ sizeof(passthru->command)-1 ] = 0;
7139+ netsnmp_internal_pass_set_format(buf, var_val, var_val_type, var_val_len);
7140+ strlcat(passthru->command, buf, sizeof(passthru->command));
7141 DEBUGMSGTL(("ucd-snmp/pass", "pass-running: %s",
7142 passthru->command));
7143 exec_command(passthru);
7144 DEBUGMSGTL(("ucd-snmp/pass", "pass-running returned: %s",
7145 passthru->output));
7146- return netsnmp_pass_str_to_errno(passthru->output);
7147+ return netsnmp_internal_pass_str_to_errno(passthru->output);
7148 }
7149 }
7150 if (snmp_get_do_debugging()) {
7151diff --git a/agent/mibgroup/ucd-snmp/pass.h b/agent/mibgroup/ucd-snmp/pass.h
7152index 089c9ca..51c0689 100644
7153--- a/agent/mibgroup/ucd-snmp/pass.h
7154+++ b/agent/mibgroup/ucd-snmp/pass.h
7155@@ -6,7 +6,9 @@
7156
7157 void init_pass(void);
7158
7159+config_require(ucd-snmp/pass_common)
7160 config_require(util_funcs)
7161+config_require(utilities/execute)
7162 config_add_mib(NET-SNMP-PASS-MIB)
7163
7164 extern FindVarMethod var_extensible_pass;
7165diff --git a/agent/mibgroup/ucd-snmp/pass_common.c b/agent/mibgroup/ucd-snmp/pass_common.c
7166new file mode 100644
7167index 0000000..38a0443
7168--- /dev/null
7169+++ b/agent/mibgroup/ucd-snmp/pass_common.c
7170@@ -0,0 +1,264 @@
7171+#include <net-snmp/net-snmp-config.h>
7172+
7173+#include <ctype.h>
7174+#if HAVE_STDDEF_H
7175+#include <stddef.h>
7176+#endif
7177+#include <stdio.h>
7178+#if HAVE_STRING_H
7179+#include <string.h>
7180+#else
7181+#include <strings.h>
7182+#endif
7183+
7184+#include <net-snmp/net-snmp-includes.h>
7185+#include <net-snmp/agent/net-snmp-agent-includes.h>
7186+#include "mibgroup/util_funcs.h"
7187+#include "pass_common.h"
7188+
7189+static int
7190+netsnmp_internal_asc2bin(char *p)
7191+{
7192+ char *r, *q = p;
7193+ char c;
7194+ int n = 0;
7195+
7196+ for (;;) {
7197+ c = (char) strtol(q, &r, 16);
7198+ if (r == q)
7199+ break;
7200+ *p++ = c;
7201+ q = r;
7202+ n++;
7203+ }
7204+ return n;
7205+}
7206+
7207+static int
7208+netsnmp_internal_bin2asc(char *p, size_t n)
7209+{
7210+ int i, flag = 0;
7211+ char buffer[SNMP_MAXBUF];
7212+
7213+ /* prevent buffer overflow */
7214+ if ((int)n > (sizeof(buffer) - 1))
7215+ n = sizeof(buffer) - 1;
7216+
7217+ for (i = 0; i < (int) n; i++) {
7218+ buffer[i] = p[i];
7219+ if (!isprint((unsigned char) (p[i])))
7220+ flag = 1;
7221+ }
7222+ if (flag == 0) {
7223+ p[n] = 0;
7224+ return n;
7225+ }
7226+ for (i = 0; i < (int) n; i++) {
7227+ sprintf(p, "%02x ", (unsigned char) (buffer[i] & 0xff));
7228+ p += 3;
7229+ }
7230+ *--p = 0;
7231+ return 3 * n - 1;
7232+}
7233+
7234+int
7235+netsnmp_internal_pass_str_to_errno(const char *buf)
7236+{
7237+ if (!strncasecmp(buf, "too-big", 7)) {
7238+ /* Shouldn't happen */
7239+ return SNMP_ERR_TOOBIG;
7240+ } else if (!strncasecmp(buf, "no-such-name", 12)) {
7241+ return SNMP_ERR_NOSUCHNAME;
7242+ } else if (!strncasecmp(buf, "bad-value", 9)) {
7243+ return SNMP_ERR_BADVALUE;
7244+ } else if (!strncasecmp(buf, "read-only", 9)) {
7245+ return SNMP_ERR_READONLY;
7246+ } else if (!strncasecmp(buf, "gen-error", 9)) {
7247+ return SNMP_ERR_GENERR;
7248+ } else if (!strncasecmp(buf, "no-access", 9)) {
7249+ return SNMP_ERR_NOACCESS;
7250+ } else if (!strncasecmp(buf, "wrong-type", 10)) {
7251+ return SNMP_ERR_WRONGTYPE;
7252+ } else if (!strncasecmp(buf, "wrong-length", 12)) {
7253+ return SNMP_ERR_WRONGLENGTH;
7254+ } else if (!strncasecmp(buf, "wrong-encoding", 14)) {
7255+ return SNMP_ERR_WRONGENCODING;
7256+ } else if (!strncasecmp(buf, "wrong-value", 11)) {
7257+ return SNMP_ERR_WRONGVALUE;
7258+ } else if (!strncasecmp(buf, "no-creation", 11)) {
7259+ return SNMP_ERR_NOCREATION;
7260+ } else if (!strncasecmp(buf, "inconsistent-value", 18)) {
7261+ return SNMP_ERR_INCONSISTENTVALUE;
7262+ } else if (!strncasecmp(buf, "resource-unavailable", 20)) {
7263+ return SNMP_ERR_RESOURCEUNAVAILABLE;
7264+ } else if (!strncasecmp(buf, "commit-failed", 13)) {
7265+ return SNMP_ERR_COMMITFAILED;
7266+ } else if (!strncasecmp(buf, "undo-failed", 11)) {
7267+ return SNMP_ERR_UNDOFAILED;
7268+ } else if (!strncasecmp(buf, "authorization-error", 19)) {
7269+ return SNMP_ERR_AUTHORIZATIONERROR;
7270+ } else if (!strncasecmp(buf, "not-writable", 12)) {
7271+ return SNMP_ERR_NOTWRITABLE;
7272+ } else if (!strncasecmp(buf, "inconsistent-name", 17)) {
7273+ return SNMP_ERR_INCONSISTENTNAME;
7274+ }
7275+
7276+ return SNMP_ERR_NOERROR;
7277+}
7278+
7279+unsigned char *
7280+netsnmp_internal_pass_parse(char * buf,
7281+ char * buf2,
7282+ size_t * var_len,
7283+ struct variable *vp)
7284+{
7285+ static long long_ret;
7286+ static in_addr_t addr_ret;
7287+ int newlen;
7288+ static oid objid[MAX_OID_LEN];
7289+
7290+ /*
7291+ * buf contains the return type, and buf2 contains the data
7292+ */
7293+ if (!strncasecmp(buf, "string", 6)) {
7294+ buf2[strlen(buf2) - 1] = 0; /* zap the linefeed */
7295+ *var_len = strlen(buf2);
7296+ vp->type = ASN_OCTET_STR;
7297+ return ((unsigned char *) buf2);
7298+ }
7299+#ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
7300+ else if (!strncasecmp(buf, "integer64", 9)) {
7301+ static struct counter64 c64;
7302+ uint64_t v64 = strtoull(buf2, NULL, 10);
7303+ c64.high = (unsigned long)(v64 >> 32);
7304+ c64.low = (unsigned long)(v64 & 0xffffffff);
7305+ *var_len = sizeof(c64);
7306+ vp->type = ASN_INTEGER64;
7307+ return ((unsigned char *) &c64);
7308+ }
7309+#endif
7310+ else if (!strncasecmp(buf, "integer", 7)) {
7311+ *var_len = sizeof(long_ret);
7312+ long_ret = strtol(buf2, NULL, 10);
7313+ vp->type = ASN_INTEGER;
7314+ return ((unsigned char *) &long_ret);
7315+ } else if (!strncasecmp(buf, "unsigned", 8)) {
7316+ *var_len = sizeof(long_ret);
7317+ long_ret = strtoul(buf2, NULL, 10);
7318+ vp->type = ASN_UNSIGNED;
7319+ return ((unsigned char *) &long_ret);
7320+ }
7321+ else if (!strncasecmp(buf, "counter64", 9)) {
7322+ static struct counter64 c64;
7323+ uint64_t v64 = strtoull(buf2, NULL, 10);
7324+ c64.high = (unsigned long)(v64 >> 32);
7325+ c64.low = (unsigned long)(v64 & 0xffffffff);
7326+ *var_len = sizeof(c64);
7327+ vp->type = ASN_COUNTER64;
7328+ return ((unsigned char *) &c64);
7329+ }
7330+ else if (!strncasecmp(buf, "counter", 7)) {
7331+ *var_len = sizeof(long_ret);
7332+ long_ret = strtoul(buf2, NULL, 10);
7333+ vp->type = ASN_COUNTER;
7334+ return ((unsigned char *) &long_ret);
7335+ } else if (!strncasecmp(buf, "octet", 5)) {
7336+ *var_len = netsnmp_internal_asc2bin(buf2);
7337+ vp->type = ASN_OCTET_STR;
7338+ return ((unsigned char *) buf2);
7339+ } else if (!strncasecmp(buf, "opaque", 6)) {
7340+ *var_len = netsnmp_internal_asc2bin(buf2);
7341+ vp->type = ASN_OPAQUE;
7342+ return ((unsigned char *) buf2);
7343+ } else if (!strncasecmp(buf, "gauge", 5)) {
7344+ *var_len = sizeof(long_ret);
7345+ long_ret = strtoul(buf2, NULL, 10);
7346+ vp->type = ASN_GAUGE;
7347+ return ((unsigned char *) &long_ret);
7348+ } else if (!strncasecmp(buf, "objectid", 8)) {
7349+ newlen = parse_miboid(buf2, objid);
7350+ *var_len = newlen * sizeof(oid);
7351+ vp->type = ASN_OBJECT_ID;
7352+ return ((unsigned char *) objid);
7353+ } else if (!strncasecmp(buf, "timetick", 8)) {
7354+ *var_len = sizeof(long_ret);
7355+ long_ret = strtoul(buf2, NULL, 10);
7356+ vp->type = ASN_TIMETICKS;
7357+ return ((unsigned char *) &long_ret);
7358+ } else if (!strncasecmp(buf, "ipaddress", 9)) {
7359+ newlen = parse_miboid(buf2, objid);
7360+ if (newlen != 4) {
7361+ snmp_log(LOG_ERR, "invalid ipaddress returned: %s\n", buf2);
7362+ *var_len = 0;
7363+ return (NULL);
7364+ }
7365+ addr_ret =
7366+ (objid[0] << (8 * 3)) + (objid[1] << (8 * 2)) +
7367+ (objid[2] << 8) + objid[3];
7368+ addr_ret = htonl(addr_ret);
7369+ *var_len = sizeof(addr_ret);
7370+ vp->type = ASN_IPADDRESS;
7371+ return ((unsigned char *) &addr_ret);
7372+ }
7373+ *var_len = 0;
7374+ return (NULL);
7375+}
7376+
7377+void
7378+netsnmp_internal_pass_set_format(char *buf,
7379+ const u_char *var_val,
7380+ u_char var_val_type,
7381+ size_t var_val_len)
7382+{
7383+ char buf2[SNMP_MAXBUF];
7384+ long tmp;
7385+ unsigned long utmp;
7386+
7387+ switch (var_val_type) {
7388+ case ASN_INTEGER:
7389+ case ASN_COUNTER:
7390+ case ASN_GAUGE:
7391+ case ASN_TIMETICKS:
7392+ tmp = *((const long *) var_val);
7393+ switch (var_val_type) {
7394+ case ASN_INTEGER:
7395+ sprintf(buf, "integer %d\n", (int) tmp);
7396+ break;
7397+ case ASN_COUNTER:
7398+ sprintf(buf, "counter %d\n", (int) tmp);
7399+ break;
7400+ case ASN_GAUGE:
7401+ sprintf(buf, "gauge %d\n", (int) tmp);
7402+ break;
7403+ case ASN_TIMETICKS:
7404+ sprintf(buf, "timeticks %d\n", (int) tmp);
7405+ break;
7406+ }
7407+ break;
7408+ case ASN_IPADDRESS:
7409+ utmp = *((const u_long *) var_val);
7410+ utmp = ntohl(utmp);
7411+ sprintf(buf, "ipaddress %d.%d.%d.%d\n",
7412+ (int) ((utmp & 0xff000000) >> (8 * 3)),
7413+ (int) ((utmp & 0xff0000) >> (8 * 2)),
7414+ (int) ((utmp & 0xff00) >> (8)),
7415+ (int) ((utmp & 0xff)));
7416+ break;
7417+ case ASN_OCTET_STR:
7418+ memcpy(buf2, var_val, var_val_len);
7419+ if (var_val_len == 0)
7420+ sprintf(buf, "string \"\"\n");
7421+ else if (netsnmp_internal_bin2asc(buf2, var_val_len) ==
7422+ (int) var_val_len)
7423+ snprintf(buf, sizeof(buf), "string \"%s\"\n", buf2);
7424+ else
7425+ snprintf(buf, sizeof(buf), "octet \"%s\"\n", buf2);
7426+ buf[ sizeof(buf)-1 ] = 0;
7427+ break;
7428+ case ASN_OBJECT_ID:
7429+ sprint_mib_oid(buf2, (const oid *) var_val, var_val_len/sizeof(oid));
7430+ snprintf(buf, sizeof(buf), "objectid \"%s\"\n", buf2);
7431+ buf[ sizeof(buf)-1 ] = 0;
7432+ break;
7433+ }
7434+}
7435diff --git a/agent/mibgroup/ucd-snmp/pass_common.h b/agent/mibgroup/ucd-snmp/pass_common.h
7436new file mode 100644
7437index 0000000..b1d7e4b
7438--- /dev/null
7439+++ b/agent/mibgroup/ucd-snmp/pass_common.h
7440@@ -0,0 +1,20 @@
7441+#ifndef NETSNMP_AGENT_MIBGROUP_PASS_COMMON_H
7442+#define NETSNMP_AGENT_MIBGROUP_PASS_COMMON_H
7443+
7444+/*
7445+ * This is an internal header file. The functions declared here might change
7446+ * or disappear at any time
7447+ */
7448+
7449+int
7450+netsnmp_internal_pass_str_to_errno(const char *buf);
7451+
7452+unsigned char *
7453+netsnmp_internal_pass_parse(char *buf, char *buf2, size_t *var_len,
7454+ struct variable *vp);
7455+
7456+void
7457+netsnmp_internal_pass_set_format(char *buf, const u_char *var_val,
7458+ u_char var_val_type, size_t var_val_len);
7459+
7460+#endif /* !NETSNMP_AGENT_MIBGROUP_PASS_COMMON_H */
7461diff --git a/agent/mibgroup/ucd-snmp/pass_persist.c b/agent/mibgroup/ucd-snmp/pass_persist.c
7462index c18a84c..6cce6f4 100644
7463--- a/agent/mibgroup/ucd-snmp/pass_persist.c
7464+++ b/agent/mibgroup/ucd-snmp/pass_persist.c
7465@@ -38,6 +38,7 @@
7466
7467 #include "struct.h"
7468 #include "pass_persist.h"
7469+#include "pass_common.h"
7470 #include "extensible.h"
7471 #include "util_funcs.h"
7472
7473@@ -60,15 +61,6 @@ static void destruct_persist_pipes(void);
7474 static int write_persist_pipe(int iindex, const char *data);
7475
7476 /*
7477- * These are defined in pass.c
7478- */
7479-extern int asc2bin(char *p);
7480-extern int bin2asc(char *p, size_t n);
7481-extern int netsnmp_pass_str_to_errno(const char *buf);
7482-extern int snmp_oid_min_compare(const oid *, size_t, const oid *,
7483- size_t);
7484-
7485-/*
7486 * the relocatable extensible commands variables
7487 */
7488 struct variable2 extensible_persist_passthru_variables[] = {
7489@@ -169,11 +161,9 @@ pass_persist_parse_config(const char *token, char *cptr)
7490 } else {
7491 for (tcptr = cptr; *tcptr != 0 && *tcptr != '#' && *tcptr != ';';
7492 tcptr++);
7493- strncpy((*ppass)->command, cptr, tcptr - cptr);
7494- (*ppass)->command[tcptr - cptr] = 0;
7495+ sprintf((*ppass)->command, "%.*s", (int) (tcptr - cptr), cptr);
7496 }
7497- strncpy((*ppass)->name, (*ppass)->command, sizeof((*ppass)->name));
7498- (*ppass)->name[ sizeof((*ppass)->name)-1 ] = 0;
7499+ strlcpy((*ppass)->name, (*ppass)->command, sizeof((*ppass)->name));
7500 (*ppass)->next = NULL;
7501
7502 register_mib_priority("pass_persist",
7503@@ -230,11 +220,8 @@ var_extensible_pass_persist(struct variable *vp,
7504 {
7505 oid newname[MAX_OID_LEN];
7506 int i, rtest, newlen;
7507- static long long_ret;
7508- static in_addr_t addr_ret;
7509 char buf[SNMP_MAXBUF];
7510 static char buf2[SNMP_MAXBUF];
7511- static oid objid[MAX_OID_LEN];
7512 struct extensible *persistpassthru;
7513 FILE *file;
7514
7515@@ -243,10 +230,9 @@ var_extensible_pass_persist(struct variable *vp,
7516 */
7517 init_persist_pipes();
7518
7519- long_ret = *length;
7520 for (i = 1; i <= numpersistpassthrus; i++) {
7521 persistpassthru = get_exten_instance(persistpassthrus, i);
7522- rtest = snmp_oid_min_compare(name, *length,
7523+ rtest = snmp_oidtree_compare(name, *length,
7524 persistpassthru->miboid,
7525 persistpassthru->miblen);
7526 if ((exact && rtest == 0) || (!exact && rtest <= 0)) {
7527@@ -325,89 +311,7 @@ var_extensible_pass_persist(struct variable *vp,
7528 close_persist_pipe(i);
7529 return (NULL);
7530 }
7531- /*
7532- * buf contains the return type, and buf2 contains the data
7533- */
7534- if (!strncasecmp(buf, "string", 6)) {
7535- buf2[strlen(buf2) - 1] = 0; /* zap the linefeed */
7536- *var_len = strlen(buf2);
7537- vp->type = ASN_OCTET_STR;
7538- return ((unsigned char *) buf2);
7539- }
7540- else if (!strncasecmp(buf, "integer64", 9)) {
7541- static struct counter64 c64;
7542- uint64_t v64 = strtoull(buf2, NULL, 10);
7543- c64.high = (unsigned long)(v64 >> 32);
7544- c64.low = (unsigned long)(v64 & 0xffffffff);
7545- *var_len = sizeof(c64);
7546- vp->type = ASN_INTEGER64;
7547- return ((unsigned char *) &c64);
7548- }
7549- else if (!strncasecmp(buf, "integer", 7)) {
7550- *var_len = sizeof(long_ret);
7551- long_ret = strtol(buf2, NULL, 10);
7552- vp->type = ASN_INTEGER;
7553- return ((unsigned char *) &long_ret);
7554- } else if (!strncasecmp(buf, "unsigned", 8)) {
7555- *var_len = sizeof(long_ret);
7556- long_ret = strtoul(buf2, NULL, 10);
7557- vp->type = ASN_UNSIGNED;
7558- return ((unsigned char *) &long_ret);
7559- }
7560- else if (!strncasecmp(buf, "counter64", 9)) {
7561- static struct counter64 c64;
7562- uint64_t v64 = strtoull(buf2, NULL, 10);
7563- c64.high = (unsigned long)(v64 >> 32);
7564- c64.low = (unsigned long)(v64 & 0xffffffff);
7565- *var_len = sizeof(c64);
7566- vp->type = ASN_COUNTER64;
7567- return ((unsigned char *) &c64);
7568- }
7569- else if (!strncasecmp(buf, "counter", 7)) {
7570- *var_len = sizeof(long_ret);
7571- long_ret = strtoul(buf2, NULL, 10);
7572- vp->type = ASN_COUNTER;
7573- return ((unsigned char *) &long_ret);
7574- } else if (!strncasecmp(buf, "octet", 5)) {
7575- *var_len = asc2bin(buf2);
7576- vp->type = ASN_OCTET_STR;
7577- return ((unsigned char *) buf2);
7578- } else if (!strncasecmp(buf, "opaque", 6)) {
7579- *var_len = asc2bin(buf2);
7580- vp->type = ASN_OPAQUE;
7581- return ((unsigned char *) buf2);
7582- } else if (!strncasecmp(buf, "gauge", 5)) {
7583- *var_len = sizeof(long_ret);
7584- long_ret = strtoul(buf2, NULL, 10);
7585- vp->type = ASN_GAUGE;
7586- return ((unsigned char *) &long_ret);
7587- } else if (!strncasecmp(buf, "objectid", 8)) {
7588- newlen = parse_miboid(buf2, objid);
7589- *var_len = newlen * sizeof(oid);
7590- vp->type = ASN_OBJECT_ID;
7591- return ((unsigned char *) objid);
7592- } else if (!strncasecmp(buf, "timetick", 8)) {
7593- *var_len = sizeof(long_ret);
7594- long_ret = strtoul(buf2, NULL, 10);
7595- vp->type = ASN_TIMETICKS;
7596- return ((unsigned char *) &long_ret);
7597- } else if (!strncasecmp(buf, "ipaddress", 9)) {
7598- newlen = parse_miboid(buf2, objid);
7599- if (newlen != 4) {
7600- snmp_log(LOG_ERR,
7601- "invalid ipaddress returned: %s\n",
7602- buf2);
7603- *var_len = 0;
7604- return (NULL);
7605- }
7606- addr_ret =
7607- (objid[0] << (8 * 3)) + (objid[1] << (8 * 2)) +
7608- (objid[2] << 8) + objid[3];
7609- addr_ret = htonl(addr_ret);
7610- *var_len = sizeof(addr_ret);
7611- vp->type = ASN_IPADDRESS;
7612- return ((unsigned char *) &addr_ret);
7613- }
7614+ return netsnmp_internal_pass_parse(buf, buf2, var_len, vp);
7615 }
7616 *var_len = 0;
7617 return (NULL);
7618@@ -430,8 +334,6 @@ setPassPersist(int action,
7619 struct extensible *persistpassthru;
7620
7621 char buf[SNMP_MAXBUF], buf2[SNMP_MAXBUF];
7622- long tmp;
7623- unsigned long utmp;
7624
7625 /*
7626 * Make sure that our basic pipe structure is malloced
7627@@ -440,7 +342,7 @@ setPassPersist(int action,
7628
7629 for (i = 1; i <= numpersistpassthrus; i++) {
7630 persistpassthru = get_exten_instance(persistpassthrus, i);
7631- rtest = snmp_oid_min_compare(name, name_len,
7632+ rtest = snmp_oidtree_compare(name, name_len,
7633 persistpassthru->miboid,
7634 persistpassthru->miblen);
7635 if (rtest <= 0) {
7636@@ -457,55 +359,9 @@ setPassPersist(int action,
7637 snprintf(persistpassthru->command,
7638 sizeof(persistpassthru->command), "set\n%s\n", buf);
7639 persistpassthru->command[ sizeof(persistpassthru->command)-1 ] = 0;
7640- switch (var_val_type) {
7641- case ASN_INTEGER:
7642- case ASN_COUNTER:
7643- case ASN_GAUGE:
7644- case ASN_TIMETICKS:
7645- tmp = *((long *) var_val);
7646- switch (var_val_type) {
7647- case ASN_INTEGER:
7648- sprintf(buf, "integer %d\n", (int) tmp);
7649- break;
7650- case ASN_COUNTER:
7651- sprintf(buf, "counter %d\n", (int) tmp);
7652- break;
7653- case ASN_GAUGE:
7654- sprintf(buf, "gauge %d\n", (int) tmp);
7655- break;
7656- case ASN_TIMETICKS:
7657- sprintf(buf, "timeticks %d\n", (int) tmp);
7658- break;
7659- }
7660- break;
7661- case ASN_IPADDRESS:
7662- utmp = *((u_long *) var_val);
7663- utmp = ntohl(utmp);
7664- sprintf(buf, "ipaddress %d.%d.%d.%d\n",
7665- (int) ((utmp & 0xff000000) >> (8 * 3)),
7666- (int) ((utmp & 0xff0000) >> (8 * 2)),
7667- (int) ((utmp & 0xff00) >> (8)),
7668- (int) ((utmp & 0xff)));
7669- break;
7670- case ASN_OCTET_STR:
7671- memcpy(buf2, var_val, var_val_len);
7672- if (var_val_len == 0)
7673- sprintf(buf, "string \"\"\n");
7674- else if (bin2asc(buf2, var_val_len) == (int) var_val_len)
7675- snprintf(buf, sizeof(buf), "string \"%s\"\n", buf2);
7676- else
7677- snprintf(buf, sizeof(buf), "octet \"%s\"\n", buf2);
7678- buf[ sizeof(buf)-1 ] = 0;
7679- break;
7680- case ASN_OBJECT_ID:
7681- sprint_mib_oid(buf2, (oid *) var_val, var_val_len/sizeof(oid));
7682- snprintf(buf, sizeof(buf), "objectid \"%s\"\n", buf2);
7683- buf[ sizeof(buf)-1 ] = 0;
7684- break;
7685- }
7686- strncat(persistpassthru->command, buf,
7687- sizeof(persistpassthru->command) -
7688- strlen(persistpassthru->command) - 2);
7689+ netsnmp_internal_pass_set_format(buf, var_val, var_val_type, var_val_len);
7690+ strlcat(persistpassthru->command, buf,
7691+ sizeof(persistpassthru->command));
7692 persistpassthru->command[ sizeof(persistpassthru->command)-2 ] = '\n';
7693 persistpassthru->command[ sizeof(persistpassthru->command)-1 ] = 0;
7694
7695@@ -526,7 +382,7 @@ setPassPersist(int action,
7696 return SNMP_ERR_NOTWRITABLE;
7697 }
7698
7699- return netsnmp_pass_str_to_errno(buf);
7700+ return netsnmp_internal_pass_str_to_errno(buf);
7701 }
7702 }
7703 if (snmp_get_do_debugging()) {
7704@@ -650,8 +506,8 @@ open_persist_pipe(int iindex, char *command)
7705 {
7706 static int recurse = 0; /* used to allow one level of recursion */
7707
7708- DEBUGMSGTL(("ucd-snmp/pass_persist", "open_persist_pipe(%d,'%s')\n",
7709- iindex, command));
7710+ DEBUGMSGTL(("ucd-snmp/pass_persist", "open_persist_pipe(%d,'%s') recurse=%d\n",
7711+ iindex, command, recurse));
7712 /*
7713 * Open if it's not already open
7714 */
7715@@ -683,6 +539,7 @@ open_persist_pipe(int iindex, char *command)
7716 * Setup our -non-buffered-io-
7717 */
7718 setbuf(persist_pipes[iindex].fOut, (char *) 0);
7719+ DEBUGMSGTL(("ucd-snmp/pass_persist", "open_persist_pipe: opened the pipes\n"));
7720 }
7721
7722 /*
7723@@ -702,6 +559,7 @@ open_persist_pipe(int iindex, char *command)
7724 * Recurse one time if we get a SIGPIPE
7725 */
7726 if (!recurse) {
7727+ DEBUGMSGTL(("ucd-snmp/pass_persist", "open_persist_pipe: recursing to reopen\n"));
7728 recurse = 1;
7729 return open_persist_pipe(iindex, command);
7730 }
7731@@ -717,7 +575,7 @@ open_persist_pipe(int iindex, char *command)
7732 }
7733 if (strncmp(buf, "PONG", 4)) {
7734 DEBUGMSGTL(("ucd-snmp/pass_persist",
7735- "open_persist_pipe: PONG not received!\n"));
7736+ "open_persist_pipe: Got %s instead of PONG!\n", buf));
7737 close_persist_pipe(iindex);
7738 recurse = 0;
7739 return 0;
7740@@ -728,17 +586,6 @@ open_persist_pipe(int iindex, char *command)
7741 return 1;
7742 }
7743
7744-#if HAVE_STRUCT_SIGACTION_SA_SIGACTION
7745-/*
7746- * Generic handler
7747- */
7748-void
7749-sigpipe_handler(int sig, siginfo_t * sip, void *uap)
7750-{
7751- return;
7752-}
7753-#endif
7754-
7755 static int
7756 write_persist_pipe(int iindex, const char *data)
7757 {
7758@@ -750,16 +597,16 @@ write_persist_pipe(int iindex, const char *data)
7759 * Don't write to a non-existant process
7760 */
7761 if (persist_pipes[iindex].pid == NETSNMP_NO_SUCH_PROCESS) {
7762+ DEBUGMSGTL(("ucd-snmp/pass_persist",
7763+ "write_persist_pipe: not writing %s, process is non-existent",
7764+ data));
7765 return 0;
7766 }
7767
7768 /*
7769- * Setup our signal action to catch SIGPIPEs
7770+ * Setup our signal action to ignore SIGPIPEs
7771 */
7772- sa.sa_handler = NULL;
7773-#if HAVE_STRUCT_SIGACTION_SA_SIGACTION
7774- sa.sa_sigaction = &sigpipe_handler;
7775-#endif
7776+ sa.sa_handler = SIG_IGN;
7777 sigemptyset(&sa.sa_mask);
7778 sa.sa_flags = 0;
7779 if (sigaction(SIGPIPE, &sa, &osa)) {
7780@@ -779,10 +626,10 @@ write_persist_pipe(int iindex, const char *data)
7781 sigaction(SIGPIPE, &osa, (struct sigaction *) 0);
7782
7783 if (wret < 0) {
7784- if (werrno != EINTR) {
7785+ if (werrno != EPIPE) {
7786 DEBUGMSGTL(("ucd-snmp/pass_persist",
7787- "write_persist_pipe: write returned unknown error %d\n",
7788- errno));
7789+ "write_persist_pipe: write returned unknown error %d (%s)\n",
7790+ werrno, strerror(werrno)));
7791 }
7792 close_persist_pipe(iindex);
7793 return 0;
7794diff --git a/agent/mibgroup/ucd-snmp/pass_persist.h b/agent/mibgroup/ucd-snmp/pass_persist.h
7795index c7a2aa8..0537abc 100644
7796--- a/agent/mibgroup/ucd-snmp/pass_persist.h
7797+++ b/agent/mibgroup/ucd-snmp/pass_persist.h
7798@@ -4,7 +4,9 @@
7799 #ifndef _MIBGROUP_PASS_PERSIST_H
7800 #define _MIBGROUP_PASS_PERSIST_H
7801
7802+config_require(ucd-snmp/pass_common)
7803 config_require(util_funcs)
7804+config_require(utilities/execute)
7805
7806 void init_pass_persist(void);
7807 void shutdown_pass_persist(void);
7808diff --git a/agent/mibgroup/ucd-snmp/proc.c b/agent/mibgroup/ucd-snmp/proc.c
7809index 32ac0df..e90c2e8 100644
7810--- a/agent/mibgroup/ucd-snmp/proc.c
7811+++ b/agent/mibgroup/ucd-snmp/proc.c
7812@@ -437,8 +437,7 @@ sh_count_procs(char *procname)
7813 count = 0;
7814
7815 while(getprocs(&pinfo, sizeof(pinfo), NULL, 0, &index, 1) == 1) {
7816- strncpy(pinfo_name, pinfo.pi_comm, 256);
7817- pinfo_name[255] = 0;
7818+ strlcpy(pinfo_name, pinfo.pi_comm, sizeof(pinfo_name));
7819 sep = strchr(pinfo_name, ' ');
7820 if(sep != NULL) *sep = 0;
7821 if(strcmp(procname, pinfo_name) == 0) count++;
7822diff --git a/agent/mibgroup/ucd-snmp/proxy.c b/agent/mibgroup/ucd-snmp/proxy.c
7823index ec1aac7..017fd5c 100644
7824--- a/agent/mibgroup/ucd-snmp/proxy.c
7825+++ b/agent/mibgroup/ucd-snmp/proxy.c
7826@@ -285,14 +285,13 @@ proxy_fill_in_session(netsnmp_mib_handler *handler,
7827 return 0;
7828 }
7829
7830- *configured = malloc(strlen("-c") + 1);
7831- strcpy((char*)*configured, "-c");
7832+ *configured = strdup("-c");
7833 DEBUGMSGTL(("proxy", "pdu has community string\n"));
7834 session->community_len = reqinfo->asp->pdu->community_len;
7835- session->community = (u_char*)malloc(session->community_len + 1);
7836- strncpy((char *)session->community,
7837- (const char *)reqinfo->asp->pdu->community,
7838- session->community_len);
7839+ session->community = malloc(session->community_len + 1);
7840+ sprintf((char *)session->community, "%.*s",
7841+ (int) session->community_len,
7842+ (const char *)reqinfo->asp->pdu->community);
7843 }
7844 }
7845 #endif
7846@@ -401,6 +400,8 @@ proxy_handler(netsnmp_mib_handler *handler,
7847
7848 if (!pdu || !sp) {
7849 netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
7850+ if (pdu)
7851+ snmp_free_pdu(pdu);
7852 return SNMP_ERR_NOERROR;
7853 }
7854
7855@@ -561,7 +562,7 @@ proxy_got_response(int operation, netsnmp_session * sess, int reqid,
7856 REQUEST_IS_NOT_DELEGATED);
7857 }
7858 #ifndef NETSNMP_NO_WRITE_SUPPORT
7859- else if ((cache->reqinfo->mode == MODE_SET_ACTION)) {
7860+ else if (cache->reqinfo->mode == MODE_SET_ACTION) {
7861 /*
7862 * In order for netsnmp_wrap_up_request to consider the
7863 * SET request complete,
7864diff --git a/agent/mibgroup/ucd-snmp/versioninfo.c b/agent/mibgroup/ucd-snmp/versioninfo.c
7865index 60a3c71..f7a8c63 100644
7866--- a/agent/mibgroup/ucd-snmp/versioninfo.c
7867+++ b/agent/mibgroup/ucd-snmp/versioninfo.c
7868@@ -108,22 +108,21 @@ var_extensible_version(struct variable *vp,
7869 long_ret = name[8];
7870 return ((u_char *) (&long_ret));
7871 case VERTAG:
7872- strcpy(errmsg, netsnmp_get_version());
7873+ strlcpy(errmsg, netsnmp_get_version(), sizeof(errmsg));
7874 *var_len = strlen(errmsg);
7875 return ((u_char *) errmsg);
7876 case VERDATE:
7877- sprintf(errmsg, "$Date$");
7878+ strlcpy(errmsg, "$Date$", sizeof(errmsg));
7879 *var_len = strlen(errmsg);
7880 return ((u_char *) errmsg);
7881 case VERCDATE:
7882 curtime = time(NULL);
7883 cptr = ctime(&curtime);
7884- strcpy(errmsg, cptr);
7885- *var_len = strlen(errmsg) - 1;
7886+ strlcpy(errmsg, cptr, sizeof(errmsg));
7887+ *var_len = strlen(errmsg) - 1; /* - 1 to strip trailing newline */
7888 return ((u_char *) errmsg);
7889 case VERIDENT:
7890- sprintf(errmsg,
7891- "$Id$");
7892+ strlcpy(errmsg, "$Id$", sizeof(errmsg));
7893 *var_len = strlen(errmsg);
7894 return ((u_char *) errmsg);
7895 case VERCONFIG:
7896@@ -133,7 +132,7 @@ var_extensible_version(struct variable *vp,
7897 *var_len = 1024; /* mib imposed restriction */
7898 return (u_char *) config_opts;
7899 #else
7900- sprintf(errmsg, "");
7901+ strlcpy(errmsg, "", sizeof(errmsg)));
7902 *var_len = strlen(errmsg);
7903 return ((u_char *) errmsg);
7904 #endif
7905diff --git a/agent/mibgroup/ucd-snmp/vmstat.c b/agent/mibgroup/ucd-snmp/vmstat.c
7906index b613ee1..d52a5b6 100644
7907--- a/agent/mibgroup/ucd-snmp/vmstat.c
7908+++ b/agent/mibgroup/ucd-snmp/vmstat.c
7909@@ -31,7 +31,7 @@ vmstat_handler(netsnmp_mib_handler *handler,
7910 netsnmp_request_info *requests)
7911 {
7912 oid obj;
7913- long value = 0;
7914+ unsigned long long value = 0;
7915 char cp[300];
7916 netsnmp_cpu_info *info = netsnmp_cpu_get_byIdx( -1, 0 );
7917
7918@@ -147,7 +147,7 @@ vmstat_handler(netsnmp_mib_handler *handler,
7919 else
7920 value = 0; /* or skip this entry */
7921 snmp_set_var_typed_integer(requests->requestvb,
7922- ASN_INTEGER, value);
7923+ ASN_INTEGER, value & 0x7fffffff);
7924 }
7925 break;
7926 case CPUSYSTEM:
7927@@ -159,7 +159,7 @@ vmstat_handler(netsnmp_mib_handler *handler,
7928 else
7929 value = 0; /* or skip this entry */
7930 snmp_set_var_typed_integer(requests->requestvb,
7931- ASN_INTEGER, value);
7932+ ASN_INTEGER, value & 0x7fffffff);
7933 }
7934 break;
7935 case CPUIDLE:
7936@@ -170,7 +170,7 @@ vmstat_handler(netsnmp_mib_handler *handler,
7937 else
7938 value = 0; /* or skip this entry */
7939 snmp_set_var_typed_integer(requests->requestvb,
7940- ASN_INTEGER, value);
7941+ ASN_INTEGER, value & 0x7fffffff);
7942 }
7943 break;
7944
7945@@ -190,14 +190,14 @@ vmstat_handler(netsnmp_mib_handler *handler,
7946 if ( info->history && info->history[0].total_hist ) {
7947 value = (info->nInterrupts - info->history[0].intr_hist)/60;
7948 snmp_set_var_typed_integer(requests->requestvb,
7949- ASN_INTEGER, value);
7950+ ASN_INTEGER, value & 0x7fffffff);
7951 }
7952 break;
7953 case SYSCONTEXT:
7954 if ( info->history && info->history[0].total_hist ) {
7955 value = (info->nCtxSwitches - info->history[0].ctx_hist)/60;
7956 snmp_set_var_typed_integer(requests->requestvb,
7957- ASN_INTEGER, value);
7958+ ASN_INTEGER, value & 0x7fffffff);
7959 }
7960 break;
7961
7962@@ -217,7 +217,7 @@ vmstat_handler(netsnmp_mib_handler *handler,
7963 value = (info->swapIn - info->history[0].swpi_hist)/60;
7964 /* ??? value *= PAGE_SIZE; */
7965 snmp_set_var_typed_integer(requests->requestvb,
7966- ASN_INTEGER, value);
7967+ ASN_INTEGER, value & 0x7fffffff);
7968 }
7969 break;
7970 case SWAPOUT:
7971@@ -225,7 +225,7 @@ vmstat_handler(netsnmp_mib_handler *handler,
7972 value = (info->swapOut - info->history[0].swpo_hist)/60;
7973 /* ??? value *= PAGE_SIZE; */
7974 snmp_set_var_typed_integer(requests->requestvb,
7975- ASN_INTEGER, value);
7976+ ASN_INTEGER, value & 0x7fffffff);
7977 }
7978 break;
7979
7980@@ -244,14 +244,14 @@ vmstat_handler(netsnmp_mib_handler *handler,
7981 if ( info->history && info->history[0].total_hist ) {
7982 value = (info->pageOut - info->history[0].pageo_hist)/60;
7983 snmp_set_var_typed_integer(requests->requestvb,
7984- ASN_INTEGER, value);
7985+ ASN_INTEGER, value & 0x7fffffff);
7986 }
7987 break;
7988 case IORECEIVE:
7989 if ( info->history && info->history[0].total_hist ) {
7990 value = (info->pageIn - info->history[0].pagei_hist)/60;
7991 snmp_set_var_typed_integer(requests->requestvb,
7992- ASN_INTEGER, value);
7993+ ASN_INTEGER, value & 0x7fffffff);
7994 }
7995 break;
7996
7997diff --git a/agent/mibgroup/ucd_snmp.h b/agent/mibgroup/ucd_snmp.h
7998index c371dd4..0d87ec1 100644
7999--- a/agent/mibgroup/ucd_snmp.h
8000+++ b/agent/mibgroup/ucd_snmp.h
8001@@ -8,7 +8,9 @@ config_require(ucd-snmp/loadave)
8002 config_require(agent/extend)
8003 config_require(ucd-snmp/errormib)
8004 config_require(ucd-snmp/file)
8005+#if defined(HAVE_DLFCN_H) && defined(HAVE_DLOPEN)
8006 config_require(ucd-snmp/dlmod)
8007+#endif
8008 config_require(ucd-snmp/proxy)
8009 config_require(ucd-snmp/logmatch)
8010 config_require(ucd-snmp/memory)
8011diff --git a/agent/mibgroup/udp-mib/udpEndpointTable/udpEndpointTable_data_access.c b/agent/mibgroup/udp-mib/udpEndpointTable/udpEndpointTable_data_access.c
8012index 9ea23a9..0e25c21 100644
8013--- a/agent/mibgroup/udp-mib/udpEndpointTable/udpEndpointTable_data_access.c
8014+++ b/agent/mibgroup/udp-mib/udpEndpointTable/udpEndpointTable_data_access.c
8015@@ -239,7 +239,7 @@ udpEndpointTable_container_load(netsnmp_container *container)
8016 if (NULL == ep_c)
8017 return MFD_RESOURCE_UNAVAILABLE;
8018 ep_it = CONTAINER_ITERATOR(ep_c);
8019- if (NULL == ep_c) {
8020+ if (NULL == ep_it) {
8021 netsnmp_access_udp_endpoint_container_free(ep_c, 0);
8022 return MFD_RESOURCE_UNAVAILABLE;
8023 }
8024diff --git a/agent/mibgroup/util_funcs.c b/agent/mibgroup/util_funcs.c
8025index 55d80c5..69d7190 100644
8026--- a/agent/mibgroup/util_funcs.c
8027+++ b/agent/mibgroup/util_funcs.c
8028@@ -126,31 +126,7 @@ extern int numprocs, numextens;
8029 const char *
8030 make_tempfile(void)
8031 {
8032- static char name[32];
8033- int fd = -1;
8034-
8035- strcpy(name, get_temp_file_pattern());
8036-#ifdef HAVE_MKSTEMP
8037- fd = mkstemp(name);
8038-#else
8039- if (mktemp(name)) {
8040-# ifndef WIN32
8041- fd = open(name, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR);
8042-# else
8043- /*
8044- Win32 needs _S_IREAD | _S_IWRITE to set permissions on file after closing
8045- */
8046- fd = _open(name, _O_CREAT | _O_EXCL | _O_WRONLY, _S_IREAD | _S_IWRITE);
8047-# endif
8048- }
8049-#endif
8050- if (fd >= 0) {
8051- close(fd);
8052- DEBUGMSGTL(("make_tempfile", "temp file created: %s\n", name));
8053- return name;
8054- }
8055- snmp_log(LOG_ERR,"make_tempfile: error creating file %s\n", name);
8056- return NULL;
8057+ return netsnmp_mktemp();
8058 }
8059
8060 #ifndef NETSNMP_FEATURE_REMOVE_SHELL_COMMAND
8061@@ -718,14 +694,12 @@ print_mib_oid(oid name[], size_t len)
8062 }
8063
8064 void
8065-sprint_mib_oid(char *buf, oid name[], size_t len)
8066+sprint_mib_oid(char *buf, const oid *name, size_t len)
8067 {
8068 int i;
8069- for (i = 0; i < (int) len; i++) {
8070- sprintf(buf, ".%d", (int) name[i]);
8071- while (*buf != 0)
8072- buf++;
8073- }
8074+
8075+ for (i = 0; i < (int) len; i++)
8076+ buf += sprintf(buf, ".%" NETSNMP_PRIo "u", name[i]);
8077 }
8078
8079 /*
8080@@ -798,7 +772,10 @@ parse_miboid(const char *buf, oid * oidout)
8081 if (*buf == '.')
8082 buf++;
8083 for (i = 0; isdigit((unsigned char)(*buf)); i++) {
8084- oidout[i] = atoi(buf);
8085+ /* Subidentifiers are unsigned values, up to 2^32-1
8086+ * so we need to use 'strtoul' rather than 'atoi'
8087+ */
8088+ oidout[i] = strtoul(buf, NULL, 10) & 0xffffffff;
8089 while (isdigit((unsigned char)(*buf++)));
8090 if (*buf == '.')
8091 buf++;
8092@@ -1146,7 +1123,7 @@ int net_snmp_delete_prefix_info(prefix_cbx **head,
8093 }
8094 return 0;
8095 }
8096-#endif
8097+#endif /* NETSNMP_FEATURE_REMOVE_DELETE_PREFIX_INFO */
8098
8099 #endif /* HAVE_LINUX_RTNETLINK_H */
8100
8101diff --git a/agent/mibgroup/util_funcs.h b/agent/mibgroup/util_funcs.h
8102index 5bef2a8..7f59780 100644
8103--- a/agent/mibgroup/util_funcs.h
8104+++ b/agent/mibgroup/util_funcs.h
8105@@ -43,7 +43,7 @@ int get_exec_pipes(char *cmd, int *fdIn, int *fdOut, pid_t *pid);
8106 #endif
8107 WriteMethod clear_cache;
8108 void print_mib_oid(oid *, size_t);
8109-void sprint_mib_oid(char *, oid *, size_t);
8110+void sprint_mib_oid(char *, const oid *, size_t);
8111 int checkmib(struct variable *, oid *, size_t *, int, size_t *,
8112 WriteMethod ** write_method, int);
8113 char *find_field(char *, int);
8114diff --git a/agent/mibgroup/utilities/override.c b/agent/mibgroup/utilities/override.c
8115index 298883e..2b083a9 100644
8116--- a/agent/mibgroup/utilities/override.c
8117+++ b/agent/mibgroup/utilities/override.c
8118@@ -216,6 +216,8 @@ netsnmp_parse_override(const char *token, char *line)
8119 case ASN_OBJECT_ID:
8120 read_config_read_objid(buf, (oid **) & thedata->value,
8121 &thedata->value_len);
8122+ /* We need the size of the value in bytes, not in oids */
8123+ thedata->value_len *= sizeof(oid);
8124 break;
8125
8126 case ASN_NULL:
8127diff --git a/agent/mibgroup/winExtDLL.c b/agent/mibgroup/winExtDLL.c
8128index ddf613b..c693913 100644
8129--- a/agent/mibgroup/winExtDLL.c
8130+++ b/agent/mibgroup/winExtDLL.c
8131@@ -692,7 +692,6 @@ var_winExtDLL(netsnmp_mib_handler *handler,
8132 winextdll *ext_dll_info;
8133 netsnmp_request_info *request;
8134 UINT nRequestType;
8135- const char *mode_name;
8136 int rc;
8137
8138 netsnmp_assert(ext_dll_view_info);
8139@@ -711,35 +710,27 @@ var_winExtDLL(netsnmp_mib_handler *handler,
8140
8141 switch (reqinfo->mode) {
8142 case MODE_GET:
8143- mode_name = "GET";
8144 nRequestType = SNMP_EXTENSION_GET;
8145 netsnmp_assert(!context_info_head);
8146 break;
8147 case MODE_GETNEXT:
8148- mode_name = "GETNEXT";
8149 nRequestType = SNMP_EXTENSION_GET_NEXT;
8150 netsnmp_assert(!context_info_head);
8151 break;
8152 case MODE_SET_RESERVE1:
8153- mode_name = "SET_RESERVE1";
8154 nRequestType = SNMP_EXTENSION_SET_TEST;
8155 break;
8156 case MODE_SET_RESERVE2:
8157- mode_name = "SET_RESERVE2";
8158 return SNMP_ERR_NOERROR;
8159 case MODE_SET_ACTION:
8160- mode_name = "SET_ACTION";
8161 return SNMP_ERR_NOERROR;
8162 case MODE_SET_UNDO:
8163- mode_name = "SET_UNDO";
8164 nRequestType = SNMP_EXTENSION_SET_UNDO;
8165 break;
8166 case MODE_SET_COMMIT:
8167- mode_name = "SET_COMMIT";
8168 nRequestType = SNMP_EXTENSION_SET_COMMIT;
8169 break;
8170 case MODE_SET_FREE:
8171- mode_name = "SET_FREE";
8172 nRequestType = SNMP_EXTENSION_SET_CLEANUP;
8173 break;
8174 default:
8175diff --git a/agent/snmp_agent.c b/agent/snmp_agent.c
8176index b38ef4a..2532da1 100644
8177--- a/agent/snmp_agent.c
8178+++ b/agent/snmp_agent.c
8179@@ -662,8 +662,7 @@ agent_check_and_process(int block)
8180 * The caller does not want us to block at all.
8181 */
8182
8183- tvp->tv_sec = 0;
8184- tvp->tv_usec = 0;
8185+ timerclear(tvp);
8186 }
8187
8188 count = select(numfds, &fdset, NULL, NULL, tvp);
8189@@ -778,7 +777,7 @@ netsnmp_addrcache_add(const char *addr)
8190 /*
8191 * found a match
8192 */
8193- memcpy(&addrCache[i].lastHit, &now, sizeof(struct timeval));
8194+ addrCache[i].lastHit = now;
8195 if (timercmp(&addrCache[i].lastHit, &aged, <))
8196 rc = 1; /* should have expired, so is new */
8197 else
8198@@ -825,7 +824,7 @@ netsnmp_addrcache_add(const char *addr)
8199 */
8200 addrCache[unused].addr = strdup(addr);
8201 addrCache[unused].status = SNMP_ADDRCACHE_USED;
8202- memcpy(&addrCache[unused].lastHit, &now, sizeof(struct timeval));
8203+ addrCache[unused].lastHit = now;
8204 }
8205 else { /* Otherwise, replace oldest entry */
8206 if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
8207@@ -835,7 +834,7 @@ netsnmp_addrcache_add(const char *addr)
8208
8209 free(addrCache[oldest].addr);
8210 addrCache[oldest].addr = strdup(addr);
8211- memcpy(&addrCache[oldest].lastHit, &now, sizeof(struct timeval));
8212+ addrCache[oldest].lastHit = now;
8213 }
8214 rc = 1;
8215 }
8216@@ -884,7 +883,7 @@ netsnmp_agent_check_packet(netsnmp_session * session,
8217 {
8218 char *addr_string = NULL;
8219 #ifdef NETSNMP_USE_LIBWRAP
8220- char *tcpudpaddr, *name;
8221+ char *tcpudpaddr = NULL, *name;
8222 short not_log_connection;
8223
8224 name = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
8225@@ -918,12 +917,13 @@ netsnmp_agent_check_packet(netsnmp_session * session,
8226 }
8227 #ifdef NETSNMP_USE_LIBWRAP
8228 /* Catch udp,udp6,tcp,tcp6 transports using "[" */
8229- tcpudpaddr = strstr(addr_string, "[");
8230+ if (addr_string)
8231+ tcpudpaddr = strstr(addr_string, "[");
8232 if ( tcpudpaddr != 0 ) {
8233 char sbuf[64];
8234 char *xp;
8235- strncpy(sbuf, tcpudpaddr + 1, sizeof(sbuf));
8236- sbuf[sizeof(sbuf)-1] = '\0';
8237+
8238+ strlcpy(sbuf, tcpudpaddr + 1, sizeof(sbuf));
8239 xp = strstr(sbuf, "]");
8240 if (xp)
8241 *xp = '\0';
8242@@ -3310,57 +3310,6 @@ netsnmp_handle_request(netsnmp_agent_session *asp, int status)
8243 return 1;
8244 }
8245
8246-/**
8247- * This function calls into netsnmp_set_mode_request_error, sets
8248- * error_value given a reqinfo->mode value. It's used to send specific
8249- * errors back to the agent to process accordingly.
8250- *
8251- * If error_value is set to SNMP_NOSUCHOBJECT, SNMP_NOSUCHINSTANCE,
8252- * or SNMP_ENDOFMIBVIEW the following is applicable:
8253- * Sets the error_value to request->requestvb->type if
8254- * reqinfo->mode value is set to MODE_GET. If the reqinfo->mode
8255- * value is set to MODE_GETNEXT or MODE_GETBULK the code calls
8256- * snmp_log logging an error message.
8257- *
8258- * Otherwise, the request->status value is checked, if it's < 0
8259- * snmp_log is called with an error message and SNMP_ERR_GENERR is
8260- * assigned to request->status. If the request->status value is >= 0 the
8261- * error_value is set to request->status.
8262- *
8263- * @param reqinfo is a pointer to the netsnmp_agent_request_info struct. It
8264- * contains the reqinfo->mode which is required to set error_value or
8265- * log error messages.
8266- *
8267- * @param request is a pointer to the netsnmp_request_info struct. The
8268- * error_value is set to request->requestvb->type
8269- *
8270- * @param error_value is the exception value you want to set, below are
8271- * possible values.
8272- * - SNMP_NOSUCHOBJECT
8273- * - SNMP_NOSUCHINSTANCE
8274- * - SNMP_ENDOFMIBVIEW
8275- * - SNMP_ERR_NOERROR
8276- * - SNMP_ERR_TOOBIG
8277- * - SNMP_ERR_NOSUCHNAME
8278- * - SNMP_ERR_BADVALUE
8279- * - SNMP_ERR_READONLY
8280- * - SNMP_ERR_GENERR
8281- * - SNMP_ERR_NOACCESS
8282- * - SNMP_ERR_WRONGTYPE
8283- * - SNMP_ERR_WRONGLENGTH
8284- * - SNMP_ERR_WRONGENCODING
8285- * - SNMP_ERR_WRONGVALUE
8286- * - SNMP_ERR_NOCREATION
8287- * - SNMP_ERR_INCONSISTENTVALUE
8288- * - SNMP_ERR_RESOURCEUNAVAILABLE
8289- * - SNMP_ERR_COMMITFAILED
8290- * - SNMP_ERR_UNDOFAILED
8291- * - SNMP_ERR_AUTHORIZATIONERROR
8292- * - SNMP_ERR_NOTWRITABLE
8293- * - SNMP_ERR_INCONSISTENTNAME
8294- *
8295- * @return Returns error_value under all conditions.
8296- */
8297 int
8298 handle_pdu(netsnmp_agent_session *asp)
8299 {
8300@@ -3702,9 +3651,13 @@ netsnmp_request_set_error_all( netsnmp_request_info *requests, int error)
8301 return result;
8302 }
8303
8304- /*
8305- * Return the value of 'sysUpTime' at the given marker
8306- */
8307+/**
8308+ * Return the value of 'sysUpTime' at the given marker
8309+ *
8310+ * @note Use netsnmp_get_agent_runtime() instead of this function if you need
8311+ * to know how much time elapsed since netsnmp_set_agent_starttime() has been
8312+ * called.
8313+ */
8314 u_long
8315 netsnmp_marker_uptime(marker_t pm)
8316 {
8317@@ -3738,6 +3691,22 @@ netsnmp_get_agent_starttime(void)
8318 }
8319
8320 /**
8321+ * Report the time that elapsed since the agent start time in hundredths of a
8322+ * second.
8323+ *
8324+ * @see See also netsnmp_set_agent_starttime().
8325+ */
8326+uint64_t
8327+netsnmp_get_agent_runtime(void)
8328+{
8329+ struct timeval now, delta;
8330+
8331+ gettimeofday(&now, NULL);
8332+ NETSNMP_TIMERSUB(&now, &starttime, &delta);
8333+ return delta.tv_sec * (uint64_t)100 + delta.tv_usec / 10000;
8334+}
8335+
8336+/**
8337 * Set the time at which Net-SNMP started either to the current time
8338 * (if s == NULL) or to *s (if s is not NULL).
8339 */
8340diff --git a/agent/snmp_perl.c b/agent/snmp_perl.c
8341index f974023..48d9695 100644
8342--- a/agent/snmp_perl.c
8343+++ b/agent/snmp_perl.c
8344@@ -36,6 +36,7 @@ maybe_source_perl_startup(void)
8345 const char *perl_init_file = netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID,
8346 NETSNMP_DS_AGENT_PERL_INIT_FILE);
8347 char init_file[SNMP_MAXBUF];
8348+ int res;
8349
8350 static int have_done_init = 0;
8351
8352@@ -57,8 +58,11 @@ maybe_source_perl_startup(void)
8353 env = NULL;
8354 PERL_SYS_INIT3(&argc, &argv, &env);
8355 my_perl = perl_alloc();
8356- if (!my_perl)
8357+ if (!my_perl) {
8358+ snmp_log(LOG_ERR,
8359+ "embedded perl support failed to initialize (perl_alloc())\n");
8360 goto bail_out;
8361+ }
8362
8363 perl_construct(my_perl);
8364
8365@@ -66,11 +70,21 @@ maybe_source_perl_startup(void)
8366 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
8367 #endif
8368
8369- if (perl_parse(my_perl, xs_init, 2, embedargs, NULL))
8370+ res = perl_parse(my_perl, xs_init, 2, embedargs, NULL);
8371+ if (res) {
8372+ snmp_log(LOG_ERR,
8373+ "embedded perl support failed to initialize (perl_parse(%s)"
8374+ " returned %d)\n", embedargs[1], res);
8375 goto bail_out;
8376+ }
8377
8378- if (perl_run(my_perl))
8379+ res = perl_run(my_perl);
8380+ if (res) {
8381+ snmp_log(LOG_ERR,
8382+ "embedded perl support failed to initialize (perl_run()"
8383+ " returned %d)\n", res);
8384 goto bail_out;
8385+ }
8386
8387 free(embedargs[0]);
8388 free(embedargs[1]);
8389@@ -82,7 +96,6 @@ maybe_source_perl_startup(void)
8390 bail_out:
8391 free(embedargs[0]);
8392 free(embedargs[1]);
8393- snmp_log(LOG_ERR, "embedded perl support failed to initialize\n");
8394 netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
8395 NETSNMP_DS_AGENT_DISABLE_PERL, 1);
8396 return;
8397@@ -168,5 +181,6 @@ shutdown_perl(void)
8398 }
8399 DEBUGMSGTL(("perl", "shutting down perl\n"));
8400 perl_destruct(my_perl);
8401+ my_perl = NULL;
8402 DEBUGMSGTL(("perl", "finished shutting down perl\n"));
8403 }
8404diff --git a/agent/snmpd.c b/agent/snmpd.c
8405index 0deff09..ee458c3 100644
8406--- a/agent/snmpd.c
8407+++ b/agent/snmpd.c
8408@@ -438,7 +438,6 @@ main(int argc, char *argv[])
8409 int arg, i, ret;
8410 int dont_fork = 0, do_help = 0;
8411 int log_set = 0;
8412- int uid = 0, gid = 0;
8413 int agent_mode = -1;
8414 char *pid_file = NULL;
8415 char option_compatability[] = "-Le";
8416@@ -446,12 +445,6 @@ main(int argc, char *argv[])
8417 int fd;
8418 FILE *PID;
8419 #endif
8420-#if HAVE_GETPWNAM && HAVE_PWD_H
8421- struct passwd *info;
8422-#endif
8423-#if HAVE_UNISTD_H
8424- const char *persistent_dir;
8425-#endif
8426
8427 #ifndef WIN32
8428 /*
8429@@ -602,19 +595,18 @@ main(int argc, char *argv[])
8430 int gid;
8431
8432 gid = strtoul(optarg, &ecp, 10);
8433+#if HAVE_GETGRNAM && HAVE_PWD_H
8434 if (*ecp) {
8435-#if HAVE_GETPWNAM && HAVE_PWD_H
8436 struct group *info;
8437+
8438 info = getgrnam(optarg);
8439- if (info) {
8440- gid = info->gr_gid;
8441- } else {
8442-#endif
8443- fprintf(stderr, "Bad group id: %s\n", optarg);
8444- exit(1);
8445-#if HAVE_GETPWNAM && HAVE_PWD_H
8446- }
8447+ gid = info ? info->gr_gid : -1;
8448+ endgrent();
8449+ }
8450 #endif
8451+ if (gid < 0) {
8452+ fprintf(stderr, "Bad group id: %s\n", optarg);
8453+ exit(1);
8454 }
8455 netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
8456 NETSNMP_DS_AGENT_GROUPID, gid);
8457@@ -781,18 +773,18 @@ main(int argc, char *argv[])
8458 int uid;
8459
8460 uid = strtoul(optarg, &ecp, 10);
8461- if (*ecp) {
8462 #if HAVE_GETPWNAM && HAVE_PWD_H
8463+ if (*ecp) {
8464+ struct passwd *info;
8465+
8466 info = getpwnam(optarg);
8467- if (info) {
8468- uid = info->pw_uid;
8469- } else {
8470-#endif
8471- fprintf(stderr, "Bad user id: %s\n", optarg);
8472- exit(1);
8473-#if HAVE_GETPWNAM && HAVE_PWD_H
8474- }
8475+ uid = info ? info->pw_uid : -1;
8476+ endpwent();
8477+ }
8478 #endif
8479+ if (uid < 0) {
8480+ fprintf(stderr, "Bad user id: %s\n", optarg);
8481+ exit(1);
8482 }
8483 netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
8484 NETSNMP_DS_AGENT_USERID, uid);
8485@@ -1009,7 +1001,11 @@ main(int argc, char *argv[])
8486 }
8487 #endif
8488
8489-#if HAVE_UNISTD_H
8490+#if defined(HAVE_UNISTD_H) && (defined(HAVE_CHOWN) || defined(HAVE_SETGID) || defined(HAVE_SETUID))
8491+ {
8492+ const char *persistent_dir;
8493+ int uid, gid;
8494+
8495 persistent_dir = get_persistent_directory();
8496 mkdirhier( persistent_dir, NETSNMP_AGENT_DIRECTORY_MODE, 0 );
8497
8498@@ -1025,7 +1021,7 @@ main(int argc, char *argv[])
8499
8500 #ifdef HAVE_SETGID
8501 if ((gid = netsnmp_ds_get_int(NETSNMP_DS_APPLICATION_ID,
8502- NETSNMP_DS_AGENT_GROUPID)) != 0) {
8503+ NETSNMP_DS_AGENT_GROUPID)) > 0) {
8504 DEBUGMSGTL(("snmpd/main", "Changing gid to %d.\n", gid));
8505 if (setgid(gid) == -1
8506 #ifdef HAVE_SETGROUPS
8507@@ -1042,8 +1038,10 @@ main(int argc, char *argv[])
8508 #endif
8509 #ifdef HAVE_SETUID
8510 if ((uid = netsnmp_ds_get_int(NETSNMP_DS_APPLICATION_ID,
8511- NETSNMP_DS_AGENT_USERID)) != 0) {
8512+ NETSNMP_DS_AGENT_USERID)) > 0) {
8513 #if HAVE_GETPWNAM && HAVE_PWD_H && HAVE_INITGROUPS
8514+ struct passwd *info;
8515+
8516 /*
8517 * Set supplementary groups before changing UID
8518 * (which probably involves giving up privileges)
8519@@ -1059,6 +1057,7 @@ main(int argc, char *argv[])
8520 }
8521 }
8522 }
8523+ endpwent();
8524 #endif
8525 DEBUGMSGTL(("snmpd/main", "Changing uid to %d.\n", uid));
8526 if (setuid(uid) == -1) {
8527@@ -1070,6 +1069,7 @@ main(int argc, char *argv[])
8528 }
8529 }
8530 #endif
8531+ }
8532 #endif
8533
8534 /*
8535@@ -1273,7 +1273,7 @@ receive(void)
8536 DEBUGMSGTL(("snmpd/select", "select( numfds=%d, ..., tvp=%p)\n",
8537 numfds, tvp));
8538 if(tvp)
8539- DEBUGMSGTL(("timer", "tvp %ld.%ld\n", tvp->tv_sec, tvp->tv_usec));
8540+ DEBUGMSGTL(("timer", "tvp %ld.%ld\n", tvp->tv_sec, (long)tvp->tv_usec));
8541 count = netsnmp_large_fd_set_select(numfds, &readfds, &writefds, &exceptfds,
8542 tvp);
8543 DEBUGMSGTL(("snmpd/select", "returned, count = %d\n", count));
8544diff --git a/apps/Makefile.in b/apps/Makefile.in
8545index 43cb007..77404dd 100644
8546--- a/apps/Makefile.in
8547+++ b/apps/Makefile.in
8548@@ -84,9 +84,6 @@ USEAGENTLIBS = $(MIBLIB) $(AGENTLIB) $(USELIBS)
8549 MYSQL_LIBS = @MYSQL_LIBS@
8550 MYSQL_INCLUDES = @MYSQL_INCLUDES@
8551
8552-#
8553-# link path in src dir
8554-LOCAL_LIBS = -L../snmplib/.libs -L../snmplib -L../agent/.libs -L../agent
8555 VAL_LIBS = @VAL_LIBS@
8556 LIBS = $(USELIBS) $(VAL_LIBS) @LIBS@
8557 PERLLDOPTS_FOR_APPS = @PERLLDOPTS_FOR_APPS@
8558@@ -146,65 +143,65 @@ OTHERUNINSTALL=snmpinformuninstall snmptrapdperluninstall
8559 # build rules
8560 #
8561 snmpwalk$(EXEEXT): snmpwalk.$(OSUFFIX) $(USELIBS)
8562- $(LINK) ${CFLAGS} -o $@ snmpwalk.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8563+ $(LINK) ${CFLAGS} -o $@ snmpwalk.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8564
8565 snmpbulkwalk$(EXEEXT): snmpbulkwalk.$(OSUFFIX) $(USELIBS)
8566- $(LINK) ${CFLAGS} -o $@ snmpbulkwalk.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8567+ $(LINK) ${CFLAGS} -o $@ snmpbulkwalk.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8568
8569 snmpbulkget$(EXEEXT): snmpbulkget.$(OSUFFIX) $(USELIBS)
8570- $(LINK) ${CFLAGS} -o $@ snmpbulkget.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8571+ $(LINK) ${CFLAGS} -o $@ snmpbulkget.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8572
8573 snmptranslate$(EXEEXT): snmptranslate.$(OSUFFIX) $(USELIBS)
8574- $(LINK) ${CFLAGS} -o $@ snmptranslate.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8575+ $(LINK) ${CFLAGS} -o $@ snmptranslate.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8576
8577 snmpstatus$(EXEEXT): snmpstatus.$(OSUFFIX) $(USELIBS)
8578- $(LINK) ${CFLAGS} -o $@ snmpstatus.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8579+ $(LINK) ${CFLAGS} -o $@ snmpstatus.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8580
8581 snmpget$(EXEEXT): snmpget.$(OSUFFIX) $(USELIBS)
8582- $(LINK) ${CFLAGS} -o $@ snmpget.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8583+ $(LINK) ${CFLAGS} -o $@ snmpget.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8584
8585 snmpdelta$(EXEEXT): snmpdelta.$(OSUFFIX) $(USELIBS)
8586- $(LINK) ${CFLAGS} -o $@ snmpdelta.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8587+ $(LINK) ${CFLAGS} -o $@ snmpdelta.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8588
8589 snmptable$(EXEEXT): snmptable.$(OSUFFIX) $(USELIBS)
8590- $(LINK) ${CFLAGS} -o $@ snmptable.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8591+ $(LINK) ${CFLAGS} -o $@ snmptable.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8592
8593 snmptest$(EXEEXT): snmptest.$(OSUFFIX) $(USELIBS)
8594- $(LINK) ${CFLAGS} -o $@ snmptest.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8595+ $(LINK) ${CFLAGS} -o $@ snmptest.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8596
8597 snmptrapd$(EXEEXT): $(TRAPD_OBJECTS) $(USETRAPLIBS) $(INSTALLLIBS)
8598- $(LINK) ${CFLAGS} -o $@ $(TRAPD_OBJECTS) $(INSTALLLIBS) $(LOCAL_LIBS) ${LDFLAGS} ${TRAPLIBS}
8599+ $(LINK) ${CFLAGS} -o $@ $(TRAPD_OBJECTS) $(INSTALLLIBS) ${LDFLAGS} ${TRAPLIBS}
8600
8601 snmptrap$(EXEEXT): snmptrap.$(OSUFFIX) $(USELIBS)
8602- $(LINK) ${CFLAGS} -o $@ snmptrap.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8603+ $(LINK) ${CFLAGS} -o $@ snmptrap.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8604
8605 snmpinform$(EXEEXT): snmptrap$(EXEEXT)
8606 rm -f snmpinform
8607 $(LN_S) snmptrap$(EXEEXT) snmpinform$(EXEEXT)
8608
8609 snmpset$(EXEEXT): snmpset.$(OSUFFIX) $(USELIBS)
8610- $(LINK) ${CFLAGS} -o $@ snmpset.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8611+ $(LINK) ${CFLAGS} -o $@ snmpset.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8612
8613 snmpusm$(EXEEXT): snmpusm.$(OSUFFIX) $(USELIBS)
8614- $(LINK) ${CFLAGS} -o $@ snmpusm.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8615+ $(LINK) ${CFLAGS} -o $@ snmpusm.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8616
8617 snmpvacm$(EXEEXT): snmpvacm.$(OSUFFIX) $(USELIBS)
8618- $(LINK) ${CFLAGS} -o $@ snmpvacm.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8619+ $(LINK) ${CFLAGS} -o $@ snmpvacm.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8620
8621 snmptls$(EXEEXT): snmptls.$(OSUFFIX) $(USELIBS)
8622- $(LINK) ${CFLAGS} -o $@ snmptls.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8623+ $(LINK) ${CFLAGS} -o $@ snmptls.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8624
8625 agentxtrap$(EXEEXT): agentxtrap.$(OSUFFIX) $(USEAGENTLIBS)
8626- $(LINK) ${CFLAGS} -o $@ agentxtrap.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} $(USEAGENTLIBS) $(PERLLDOPTS_FOR_APPS) ${LIBS}
8627+ $(LINK) ${CFLAGS} -o $@ agentxtrap.$(OSUFFIX) ${LDFLAGS} $(USEAGENTLIBS) $(PERLLDOPTS_FOR_APPS) ${LIBS}
8628
8629 snmpgetnext$(EXEEXT): snmpgetnext.$(OSUFFIX) $(USELIBS)
8630- $(LINK) ${CFLAGS} -o $@ snmpgetnext.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8631+ $(LINK) ${CFLAGS} -o $@ snmpgetnext.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8632
8633 encode_keychange$(EXEEXT): encode_keychange.$(OSUFFIX) $(USELIBS)
8634- $(LINK) ${CFLAGS} -o $@ encode_keychange.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8635+ $(LINK) ${CFLAGS} -o $@ encode_keychange.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8636
8637 snmpdf$(EXEEXT): snmpdf.$(OSUFFIX) $(USELIBS)
8638- $(LINK) ${CFLAGS} -o $@ snmpdf.$(OSUFFIX) $(LOCAL_LIBS) ${LDFLAGS} ${LIBS}
8639+ $(LINK) ${CFLAGS} -o $@ snmpdf.$(OSUFFIX) ${LDFLAGS} ${LIBS}
8640
8641 libnetsnmptrapd.$(LIB_EXTENSION)$(LIB_VERSION): $(LLIBTRAPD_OBJS)
8642 $(LIB_LD_CMD) $@ ${LLIBTRAPD_OBJS} $(MIBLIB) $(USELIBS) $(PERLLDOPTS_FOR_LIBS) $(LIB_LD_LIBS)
8643diff --git a/apps/encode_keychange.c b/apps/encode_keychange.c
8644index bae2139..5bf8e4c 100644
8645--- a/apps/encode_keychange.c
8646+++ b/apps/encode_keychange.c
8647@@ -108,7 +108,7 @@ int _getch(void);
8648 int
8649 main(int argc, char **argv)
8650 {
8651- int rval = SNMPERR_SUCCESS;
8652+ int rval = 1;
8653 size_t oldKu_len = SNMP_MAXBUF_SMALL,
8654 newKu_len = SNMP_MAXBUF_SMALL,
8655 oldkul_len = SNMP_MAXBUF_SMALL,
8656@@ -170,6 +170,7 @@ main(int argc, char **argv)
8657 break;
8658 case 'h':
8659 rval = 0;
8660+ /* fallthrough */
8661 default:
8662 usage_to_file(stdout);
8663 exit(rval);
8664@@ -201,7 +202,7 @@ main(int argc, char **argv)
8665 "Unrecognized hash transform: \"%s\".\n",
8666 transform_type_input);
8667 usage_synopsis(stderr);
8668- QUITFUN(rval = SNMPERR_GENERR, main_quit);
8669+ QUITFUN(SNMPERR_GENERR, main_quit);
8670 }
8671
8672 if (verbose) {
8673@@ -254,12 +255,12 @@ main(int argc, char **argv)
8674 if (strlen(oldpass) < USM_LENGTH_P_MIN) {
8675 fprintf(stderr, "Old passphrase must be greater than %d "
8676 "characters in length.\n", USM_LENGTH_P_MIN);
8677- QUITFUN(rval = SNMPERR_GENERR, main_quit);
8678+ QUITFUN(SNMPERR_GENERR, main_quit);
8679
8680 } else if (strlen(newpass) < USM_LENGTH_P_MIN) {
8681 fprintf(stderr, "New passphrase must be greater than %d "
8682 "characters in length.\n", USM_LENGTH_P_MIN);
8683- QUITFUN(rval = SNMPERR_GENERR, main_quit);
8684+ QUITFUN(SNMPERR_GENERR, main_quit);
8685 }
8686
8687 if (verbose) {
8688@@ -503,13 +504,13 @@ get_user_passphrases(void)
8689 */
8690 if (stat(path, &statbuf) < 0) {
8691 fprintf(stderr, "Cannot access directory \"%s\".\n", path);
8692- QUITFUN(rval = SNMPERR_GENERR, get_user_passphrases_quit);
8693+ QUITFUN(SNMPERR_GENERR, get_user_passphrases_quit);
8694 #ifndef WIN32
8695 } else if (statbuf.st_mode & (S_IRWXG | S_IRWXO)) {
8696 fprintf(stderr,
8697 "Directory \"%s\" is accessible by group or world.\n",
8698 path);
8699- QUITFUN(rval = SNMPERR_GENERR, get_user_passphrases_quit);
8700+ QUITFUN(SNMPERR_GENERR, get_user_passphrases_quit);
8701 #endif /* !WIN32 */
8702 }
8703
8704@@ -520,12 +521,12 @@ get_user_passphrases(void)
8705 path[ sizeof(path)-1 ] = 0;
8706 if (stat(path, &statbuf) < 0) {
8707 fprintf(stderr, "Cannot access file \"%s\".\n", path);
8708- QUITFUN(rval = SNMPERR_GENERR, get_user_passphrases_quit);
8709+ QUITFUN(SNMPERR_GENERR, get_user_passphrases_quit);
8710 #ifndef WIN32
8711 } else if (statbuf.st_mode & (S_IRWXG | S_IRWXO)) {
8712 fprintf(stderr,
8713 "File \"%s\" is accessible by group or world.\n", path);
8714- QUITFUN(rval = SNMPERR_GENERR, get_user_passphrases_quit);
8715+ QUITFUN(SNMPERR_GENERR, get_user_passphrases_quit);
8716 #endif /* !WIN32 */
8717 }
8718
8719@@ -534,7 +535,7 @@ get_user_passphrases(void)
8720 */
8721 if ((fp = fopen(path, "r")) == NULL) {
8722 fprintf(stderr, "Cannot open \"%s\".", path);
8723- QUITFUN(rval = SNMPERR_GENERR, get_user_passphrases_quit);
8724+ QUITFUN(SNMPERR_GENERR, get_user_passphrases_quit);
8725 }
8726
8727 /*
8728diff --git a/apps/snmpbulkwalk.c b/apps/snmpbulkwalk.c
8729index 62874fa..379d2ae 100644
8730--- a/apps/snmpbulkwalk.c
8731+++ b/apps/snmpbulkwalk.c
8732@@ -184,7 +184,7 @@ main(int argc, char *argv[])
8733 size_t rootlen;
8734 int count;
8735 int running;
8736- int status;
8737+ int status = STAT_ERROR;
8738 int check;
8739 int exitval = 0;
8740
8741diff --git a/apps/snmpdelta.c b/apps/snmpdelta.c
8742index e334698..08e2ebc 100644
8743--- a/apps/snmpdelta.c
8744+++ b/apps/snmpdelta.c
8745@@ -471,7 +471,7 @@ main(int argc, char *argv[])
8746 printf("\t%s", vip->descriptor);
8747 } else {
8748 vip->oidlen = 0;
8749- strcpy(vip->descriptor, SumFile);
8750+ strlcpy(vip->descriptor, SumFile, sizeof(vip->descriptor));
8751 }
8752 vip->value = 0;
8753 zeroU64(&vip->c64value);
8754diff --git a/apps/snmpnetstat/inet.c b/apps/snmpnetstat/inet.c
8755index 00b14e0..0ae810d 100644
8756--- a/apps/snmpnetstat/inet.c
8757+++ b/apps/snmpnetstat/inet.c
8758@@ -249,7 +249,7 @@ tcpprotopr_bulkget(const char *name, oid *root, size_t root_len)
8759 /*
8760 * setup initial object name
8761 */
8762- memmove(tcpConnState_oid, root, sizeof(root) * root_len);
8763+ memmove(tcpConnState_oid, root, sizeof(oid) * root_len);
8764 tcpConnState_len = root_len;
8765
8766 /*
8767diff --git a/apps/snmpnetstat/inet6.c b/apps/snmpnetstat/inet6.c
8768index bad4db9..d4ad391 100644
8769--- a/apps/snmpnetstat/inet6.c
8770+++ b/apps/snmpnetstat/inet6.c
8771@@ -128,7 +128,7 @@ tcp6protopr(const char *name)
8772 return;
8773
8774 for (vp = var; vp ; vp=vp->next_variable) {
8775- state = *var->val.integer;
8776+ state = *vp->val.integer;
8777 if (!aflag && state == MIB_TCPCONNSTATE_LISTEN)
8778 continue;
8779
8780@@ -144,12 +144,12 @@ tcp6protopr(const char *name)
8781
8782 /* Extract the local/remote information from the index values */
8783 for (i=0; i<16; i++)
8784- localAddr[i] = var->name[ 10+i ];
8785- localPort = var->name[ 26 ];
8786+ localAddr[i] = vp->name[ 10+i ];
8787+ localPort = vp->name[ 26 ];
8788 for (i=0; i<16; i++)
8789- remoteAddr[i] = var->name[ 27+i ];
8790- remotePort = var->name[ 43 ];
8791- ifIndex = var->name[ 44 ];
8792+ remoteAddr[i] = vp->name[ 27+i ];
8793+ remotePort = vp->name[ 43 ];
8794+ ifIndex = vp->name[ 44 ];
8795
8796 printf("%-5.5s", name);
8797 inet6print(localAddr, localPort, name, 1);
8798@@ -196,9 +196,9 @@ udp6protopr(const char *name)
8799 * the IP address from the varbind value, (which is why
8800 * we walked udpLocalAddress rather than udpLocalPort)
8801 */
8802- localPort = var->name[ var->name_length-2 ];
8803- ifIndex = var->name[ var->name_length-1 ];
8804- inet6print(var->val.string, localPort, name, 1);
8805+ localPort = vp->name[ vp->name_length-2 ];
8806+ ifIndex = vp->name[ vp->name_length-1 ];
8807+ inet6print(vp->val.string, localPort, name, 1);
8808 printf(" %4d\n", ifIndex );
8809 }
8810 snmp_free_varbind( var );
8811@@ -223,20 +223,21 @@ _dump_v6stats( const char *name, oid *oid_buf, size_t buf_len,
8812 {
8813 netsnmp_variable_list *var, *vp;
8814 struct stat_table *sp;
8815- oid *stats, stat;
8816+ long *stats;
8817+ oid stat;
8818 unsigned int max_stat = 0;
8819 int active = 0;
8820
8821 var = NULL;
8822 for (sp=stable; sp->entry; sp++) {
8823 oid_buf[buf_len-1] = sp->entry;
8824- if (sp->entry>max_stat)
8825+ if (sp->entry > max_stat)
8826 max_stat = sp->entry;
8827 snmp_varlist_add_variable( &var, oid_buf, buf_len,
8828 ASN_NULL, NULL, 0);
8829 }
8830 oid_buf[buf_len-1] = stable[0].entry;
8831- stats = (oid *)calloc(max_stat+1, sizeof(oid));
8832+ stats = (long *)calloc(max_stat+1, sizeof(long));
8833
8834 /*
8835 * Walk the specified column(s), and total the individual statistics
8836@@ -244,12 +245,12 @@ _dump_v6stats( const char *name, oid *oid_buf, size_t buf_len,
8837 while (1) {
8838 if (netsnmp_query_getnext( var, ss ) != SNMP_ERR_NOERROR)
8839 break;
8840- if ( snmp_oid_compare( oid_buf, buf_len-1,
8841- var->name, buf_len-1) != 0 )
8842+ if ( snmp_oid_compare( oid_buf, buf_len,
8843+ var->name, buf_len) != 0 )
8844 break; /* End of Table */
8845
8846 for ( vp=var; vp; vp=vp->next_variable ) {
8847- stat = var->name[ buf_len-1 ];
8848+ stat = vp->name[ buf_len-1 ];
8849 stats[stat] += *vp->val.integer;
8850 }
8851 active=1;
8852diff --git a/apps/snmpset.c b/apps/snmpset.c
8853index aaacf8c..1b29a6c 100644
8854--- a/apps/snmpset.c
8855+++ b/apps/snmpset.c
8856@@ -171,6 +171,7 @@ main(int argc, char *argv[])
8857 case '=':
8858 case 'i':
8859 case 'u':
8860+ case '3':
8861 case 't':
8862 case 'a':
8863 case 'o':
8864diff --git a/apps/snmptls.c b/apps/snmptls.c
8865index 7dffcd9..93b648b 100644
8866--- a/apps/snmptls.c
8867+++ b/apps/snmptls.c
8868@@ -332,7 +332,7 @@ optProc(int argc, char *const *argv, int opt)
8869
8870 case 's':
8871 if (optind < argc) {
8872- if (isdigit(argv[optind][0]))
8873+ if (isdigit(0xFF & argv[optind][0]))
8874 _storage_type = atoi(argv[optind++]);
8875 else
8876 _storage_type_str = argv[optind++];
8877@@ -345,7 +345,7 @@ optProc(int argc, char *const *argv, int opt)
8878
8879 case 'h':
8880 if (optind < argc) {
8881- if (isdigit(argv[optind][0]))
8882+ if (isdigit(0xFF & argv[optind][0]))
8883 _hash_type = atoi(argv[optind++]);
8884 }
8885 else {
8886diff --git a/apps/snmptrapd.c b/apps/snmptrapd.c
8887index 7742eff..1a52080 100644
8888--- a/apps/snmptrapd.c
8889+++ b/apps/snmptrapd.c
8890@@ -217,8 +217,6 @@ LPCTSTR app_name_long = _T("Net-SNMP Trap Handler"); /* Application
8891
8892 const char *app_name = "snmptrapd";
8893
8894-struct timeval Now;
8895-
8896 void trapd_update_config(void);
8897
8898 #ifdef WIN32SERVICE
8899@@ -360,8 +358,8 @@ pre_parse(netsnmp_session * session, netsnmp_transport *transport,
8900 if ( tcpudpaddr != 0 ) {
8901 char sbuf[64];
8902 char *xp;
8903- strncpy(sbuf, tcpudpaddr + 1, sizeof(sbuf));
8904- sbuf[sizeof(sbuf)-1] = '\0';
8905+
8906+ strlcpy(sbuf, tcpudpaddr + 1, sizeof(sbuf));
8907 xp = strstr(sbuf, "]");
8908 if (xp)
8909 *xp = '\0';
8910@@ -423,15 +421,20 @@ void
8911 parse_trapd_address(const char *token, char *cptr)
8912 {
8913 char buf[BUFSIZ];
8914+ char *p;
8915 cptr = copy_nword(cptr, buf, sizeof(buf));
8916
8917 if (default_port == ddefault_port) {
8918 default_port = strdup(buf);
8919 } else {
8920- strcat( buf, "," );
8921- strcat( buf, default_port );
8922+ p = malloc(strlen(buf) + 1 + strlen(default_port) + 1);
8923+ if (p) {
8924+ strcat(p, buf);
8925+ strcat(p, ",");
8926+ strcat(p, default_port );
8927+ }
8928 free(default_port);
8929- default_port = strdup(buf);
8930+ default_port = p;
8931 }
8932 }
8933
8934@@ -469,13 +472,10 @@ parse_config_pidFile(const char *token, char *cptr)
8935 void
8936 parse_config_agentuser(const char *token, char *cptr)
8937 {
8938-#if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
8939- struct passwd *info;
8940-#endif
8941-
8942 if (cptr[0] == '#') {
8943 char *ecp;
8944 int uid;
8945+
8946 uid = strtoul(cptr + 1, &ecp, 10);
8947 if (*ecp != 0) {
8948 config_perror("Bad number");
8949@@ -483,44 +483,47 @@ parse_config_agentuser(const char *token, char *cptr)
8950 netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
8951 NETSNMP_DS_AGENT_USERID, uid);
8952 }
8953- }
8954 #if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
8955- else if ((info = getpwnam(cptr)) != NULL) {
8956- netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
8957- NETSNMP_DS_AGENT_USERID, info->pw_uid);
8958 } else {
8959- config_perror("User not found in passwd database");
8960- }
8961- endpwent();
8962+ struct passwd *info;
8963+
8964+ info = getpwnam(cptr);
8965+ if (info)
8966+ netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
8967+ NETSNMP_DS_AGENT_USERID, info->pw_uid);
8968+ else
8969+ config_perror("User not found in passwd database");
8970+ endpwent();
8971 #endif
8972+ }
8973 }
8974
8975 void
8976 parse_config_agentgroup(const char *token, char *cptr)
8977 {
8978-#if defined(HAVE_GETGRNAM) && defined(HAVE_GRP_H)
8979- struct group *info;
8980-#endif
8981-
8982 if (cptr[0] == '#') {
8983 char *ecp;
8984 int gid = strtoul(cptr + 1, &ecp, 10);
8985+
8986 if (*ecp != 0) {
8987 config_perror("Bad number");
8988 } else {
8989 netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
8990 NETSNMP_DS_AGENT_GROUPID, gid);
8991 }
8992- }
8993 #if defined(HAVE_GETGRNAM) && defined(HAVE_GRP_H)
8994- else if ((info = getgrnam(cptr)) != NULL) {
8995- netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
8996- NETSNMP_DS_AGENT_GROUPID, info->gr_gid);
8997 } else {
8998- config_perror("Group not found in group database");
8999- }
9000- endpwent();
9001+ struct group *info;
9002+
9003+ info = getgrnam(cptr);
9004+ if (info)
9005+ netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
9006+ NETSNMP_DS_AGENT_GROUPID, info->gr_gid);
9007+ else
9008+ config_perror("Group not found in group database");
9009+ endgrent();
9010 #endif
9011+ }
9012 }
9013 #endif
9014
9015@@ -550,6 +553,74 @@ parse_config_outputOption(const char *token, char *cptr)
9016 }
9017 }
9018
9019+static void
9020+snmptrapd_main_loop(void)
9021+{
9022+ int count, numfds, block;
9023+ fd_set readfds,writefds,exceptfds;
9024+ struct timeval timeout, *tvp;
9025+
9026+ while (netsnmp_running) {
9027+ if (reconfig) {
9028+ /*
9029+ * If we are logging to a file, receipt of SIGHUP also
9030+ * indicates that the log file should be closed and
9031+ * re-opened. This is useful for users that want to
9032+ * rotate logs in a more predictable manner.
9033+ */
9034+ netsnmp_logging_restart();
9035+ snmp_log(LOG_INFO, "NET-SNMP version %s restarted\n",
9036+ netsnmp_get_version());
9037+ trapd_update_config();
9038+ if (trap1_fmt_str_remember) {
9039+ parse_format( NULL, trap1_fmt_str_remember );
9040+ }
9041+ reconfig = 0;
9042+ }
9043+ numfds = 0;
9044+ FD_ZERO(&readfds);
9045+ FD_ZERO(&writefds);
9046+ FD_ZERO(&exceptfds);
9047+ block = 0;
9048+ tvp = &timeout;
9049+ timerclear(tvp);
9050+ tvp->tv_sec = 5;
9051+ snmp_select_info(&numfds, &readfds, tvp, &block);
9052+ if (block == 1)
9053+ tvp = NULL; /* block without timeout */
9054+#ifndef NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER
9055+ netsnmp_external_event_info(&numfds, &readfds, &writefds, &exceptfds);
9056+#endif /* NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER */
9057+ count = select(numfds, &readfds, &writefds, &exceptfds, tvp);
9058+ if (count > 0) {
9059+#ifndef NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER
9060+ netsnmp_dispatch_external_events(&count, &readfds, &writefds,
9061+ &exceptfds);
9062+#endif /* NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER */
9063+ /* If there are any more events after external events, then
9064+ * try SNMP events. */
9065+ if (count > 0) {
9066+ snmp_read(&readfds);
9067+ }
9068+ } else {
9069+ switch (count) {
9070+ case 0:
9071+ snmp_timeout();
9072+ break;
9073+ case -1:
9074+ if (errno == EINTR)
9075+ continue;
9076+ snmp_log_perror("select");
9077+ netsnmp_running = 0;
9078+ break;
9079+ default:
9080+ fprintf(stderr, "select returned %d\n", count);
9081+ netsnmp_running = 0;
9082+ }
9083+ }
9084+ run_alarms();
9085+ }
9086+}
9087
9088 /*******************************************************************-o-******
9089 * main - Non Windows
9090@@ -579,9 +650,6 @@ main(int argc, char *argv[])
9091 netsnmp_transport *transport = NULL;
9092 int arg, i = 0;
9093 int uid = 0, gid = 0;
9094- int count, numfds, block;
9095- fd_set readfds,writefds,exceptfds;
9096- struct timeval timeout, *tvp;
9097 char *cp, *listen_ports = NULL;
9098 #if defined(USING_AGENTX_SUBAGENT_MODULE) && !defined(NETSNMP_SNMPTRAPD_DISABLE_AGENTX)
9099 int agentx_subagent = 1;
9100@@ -732,7 +800,7 @@ main(int argc, char *argv[])
9101 *cp = ' ';
9102 } else {
9103 /* Old style: implicitly "print=format" */
9104- trap1_fmt_str_remember = (char *)malloc(strlen(optarg) + 7);
9105+ trap1_fmt_str_remember = malloc(strlen(optarg) + 7);
9106 sprintf( trap1_fmt_str_remember, "print %s", optarg );
9107 }
9108 } else {
9109@@ -863,19 +931,18 @@ main(int argc, char *argv[])
9110 char *ecp;
9111
9112 uid = strtoul(optarg, &ecp, 10);
9113- if (*ecp) {
9114 #if HAVE_GETPWNAM && HAVE_PWD_H
9115+ if (*ecp) {
9116 struct passwd *info;
9117+
9118 info = getpwnam(optarg);
9119- if (info) {
9120- uid = info->pw_uid;
9121- } else {
9122-#endif
9123- fprintf(stderr, "Bad user id: %s\n", optarg);
9124- exit(1);
9125-#if HAVE_GETPWNAM && HAVE_PWD_H
9126- }
9127+ uid = info ? info->pw_uid : -1;
9128+ endpwent();
9129+ }
9130 #endif
9131+ if (uid < 0) {
9132+ fprintf(stderr, "Bad user id: %s\n", optarg);
9133+ exit(1);
9134 }
9135 netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
9136 NETSNMP_DS_AGENT_USERID, uid);
9137@@ -916,7 +983,7 @@ main(int argc, char *argv[])
9138 for (i = optind; i < argc; i++) {
9139 char *astring;
9140 if (listen_ports != NULL) {
9141- astring = (char *)malloc(strlen(listen_ports) + 2 + strlen(argv[i]));
9142+ astring = malloc(strlen(listen_ports) + 2 + strlen(argv[i]));
9143 if (astring == NULL) {
9144 fprintf(stderr, "malloc failure processing argv[%d]\n", i);
9145 exit(1);
9146@@ -1247,66 +1314,8 @@ main(int argc, char *argv[])
9147 #ifdef WIN32SERVICE
9148 trapd_status = SNMPTRAPD_RUNNING;
9149 #endif
9150- while (netsnmp_running) {
9151- if (reconfig) {
9152- /*
9153- * If we are logging to a file, receipt of SIGHUP also
9154- * indicates the the log file should be closed and
9155- * re-opened. This is useful for users that want to
9156- * rotate logs in a more predictable manner.
9157- */
9158- netsnmp_logging_restart();
9159- snmp_log(LOG_INFO, "NET-SNMP version %s restarted\n",
9160- netsnmp_get_version());
9161- trapd_update_config();
9162- if (trap1_fmt_str_remember) {
9163- parse_format( NULL, trap1_fmt_str_remember );
9164- }
9165- reconfig = 0;
9166- }
9167- numfds = 0;
9168- FD_ZERO(&readfds);
9169- FD_ZERO(&writefds);
9170- FD_ZERO(&exceptfds);
9171- block = 0;
9172- tvp = &timeout;
9173- timerclear(tvp);
9174- tvp->tv_sec = 5;
9175- snmp_select_info(&numfds, &readfds, tvp, &block);
9176- if (block == 1)
9177- tvp = NULL; /* block without timeout */
9178-#ifndef NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER
9179- netsnmp_external_event_info(&numfds, &readfds, &writefds, &exceptfds);
9180-#endif /* NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER */
9181- count = select(numfds, &readfds, &writefds, &exceptfds, tvp);
9182- gettimeofday(&Now, NULL);
9183- if (count > 0) {
9184-#ifndef NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER
9185- netsnmp_dispatch_external_events(&count, &readfds, &writefds,
9186- &exceptfds);
9187-#endif /* NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER */
9188- /* If there are any more events after external events, then
9189- * try SNMP events. */
9190- if (count > 0) {
9191- snmp_read(&readfds);
9192- }
9193- } else
9194- switch (count) {
9195- case 0:
9196- snmp_timeout();
9197- break;
9198- case -1:
9199- if (errno == EINTR)
9200- continue;
9201- snmp_log_perror("select");
9202- netsnmp_running = 0;
9203- break;
9204- default:
9205- fprintf(stderr, "select returned %d\n", count);
9206- netsnmp_running = 0;
9207- }
9208- run_alarms();
9209- }
9210+
9211+ snmptrapd_main_loop();
9212
9213 if (snmp_get_do_logging()) {
9214 struct tm *tm;
9215diff --git a/apps/snmptrapd_log.c b/apps/snmptrapd_log.c
9216index c1742f4..774f797 100644
9217--- a/apps/snmptrapd_log.c
9218+++ b/apps/snmptrapd_log.c
9219@@ -1020,6 +1020,8 @@ realloc_handle_auth_fmt(u_char ** buf, size_t * buf_len, size_t * out_len,
9220 #if !defined(NETSNMP_DISABLE_SNMPV1) || !defined(NETSNMP_DISABLE_SNMPV2C)
9221 while ((*out_len + pdu->community_len + 1) >= *buf_len) {
9222 if (!(allow_realloc && snmp_realloc(buf, buf_len))) {
9223+ if (temp_buf)
9224+ free(temp_buf);
9225 return 0;
9226 }
9227 }
9228diff --git a/apps/snmptrapd_sql.c b/apps/snmptrapd_sql.c
9229index c7433dc..ccba258 100644
9230--- a/apps/snmptrapd_sql.c
9231+++ b/apps/snmptrapd_sql.c
9232@@ -437,7 +437,11 @@ netsnmp_mysql_init(void)
9233 return -1;
9234 }
9235
9236+#ifdef HAVE_BROKEN_LIBMYSQLCLIENT
9237+ my_init();
9238+#else
9239 MY_INIT("snmptrapd");
9240+#endif
9241
9242 /** load .my.cnf values */
9243 load_defaults ("my", _sql.groups, &not_argc, &not_argv);
9244@@ -704,7 +708,7 @@ _sql_save_trap_info(sql_buf *sqlb, netsnmp_pdu *pdu,
9245 struct tm *cur_time;
9246 size_t tmp_size;
9247 size_t buf_host_len_t, buf_oid_len_t, buf_user_len_t;
9248- int oid_overflow, rc, trap_oid_len;
9249+ int oid_overflow, trap_oid_len;
9250 netsnmp_variable_list *vars;
9251
9252 if ((NULL == sqlb) || (NULL == pdu) || (NULL == transport))
9253@@ -727,8 +731,8 @@ _sql_save_trap_info(sql_buf *sqlb, netsnmp_pdu *pdu,
9254 /** host name */
9255 buf_host_len_t = 0;
9256 tmp_size = sizeof(sqlb->host);
9257- rc = realloc_format_trap((u_char**)&sqlb->host, &tmp_size,
9258- &buf_host_len_t, 1, "%B", pdu, transport);
9259+ realloc_format_trap((u_char**)&sqlb->host, &tmp_size,
9260+ &buf_host_len_t, 1, "%B", pdu, transport);
9261 sqlb->host_len = buf_host_len_t;
9262
9263 /* snmpTrapOID */
9264@@ -782,8 +786,8 @@ _sql_save_trap_info(sql_buf *sqlb, netsnmp_pdu *pdu,
9265 /** community string/user name */
9266 tmp_size = 0;
9267 buf_user_len_t = 0;
9268- rc = realloc_format_trap((u_char**)&sqlb->user, &tmp_size,
9269- &buf_user_len_t, 1, "%u", pdu, transport);
9270+ realloc_format_trap((u_char**)&sqlb->user, &tmp_size,
9271+ &buf_user_len_t, 1, "%u", pdu, transport);
9272 sqlb->user_len = buf_user_len_t;
9273
9274 /** transport */
9275diff --git a/apps/snmpwalk.c b/apps/snmpwalk.c
9276index 7473b91..2bed0e8 100644
9277--- a/apps/snmpwalk.c
9278+++ b/apps/snmpwalk.c
9279@@ -185,7 +185,7 @@ main(int argc, char *argv[])
9280 size_t end_len = 0;
9281 int count;
9282 int running;
9283- int status;
9284+ int status = STAT_ERROR;
9285 int check;
9286 int exitval = 0;
9287 struct timeval tv1, tv2, tv_a, tv_b;
9288diff --git a/configure b/configure
9289index 8b2a66f..77c0475 100755
9290--- a/configure
9291+++ b/configure
9292@@ -3434,6 +3434,10 @@ if test "${with_openssl+set}" = set; then :
9293 elif test "x$withval" = "xno"; then
9294 tryopenssl=no
9295 elif test -d "$withval"; then
9296+ if test -d "$withval/lib/MinGW"; then
9297+ LDFLAGS="-L$withval/lib/MinGW $LDFLAGS"
9298+ CPPFLAGS="-I$withval/include $CPPFLAGS"
9299+ else
9300
9301 if test "x$withval" != x -a -d $withval; then
9302 if test -d $withval/lib; then
9303@@ -3444,6 +3448,7 @@ if test "${with_openssl+set}" = set; then :
9304 fi
9305 fi
9306
9307+ fi
9308 tryopenssl=yes
9309 askedopenssl=yes
9310 fi
9311@@ -16180,8 +16185,29 @@ fi
9312 done
9313
9314
9315+# Library and Agent:
9316+for ac_header in nlist.h
9317+do :
9318+ ac_fn_c_check_header_compile "$LINENO" "nlist.h" "ac_cv_header_nlist_h" "
9319+$ac_includes_default
9320+
9321+#ifndef LIBBSD_DISABLE_DEPRECATED
9322+#define LIBBSD_DISABLE_DEPRECATED 1
9323+#endif
9324+
9325+"
9326+if test "x$ac_cv_header_nlist_h" = xyes; then :
9327+ cat >>confdefs.h <<_ACEOF
9328+#define HAVE_NLIST_H 1
9329+_ACEOF
9330+
9331+fi
9332+
9333+done
9334+
9335+
9336 # Library:
9337-for ac_header in fcntl.h io.h kstat.h limits.h locale.h nlist.h sys/file.h sys/ioctl.h sys/sockio.h sys/stat.h sys/systemcfg.h sys/systeminfo.h sys/times.h sys/uio.h sys/utsname.h netipx/ipx.h
9338+for ac_header in fcntl.h io.h kstat.h limits.h locale.h sys/file.h sys/ioctl.h sys/sockio.h sys/stat.h sys/systemcfg.h sys/systeminfo.h sys/times.h sys/uio.h sys/utsname.h netipx/ipx.h
9339 do :
9340 as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
9341 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
9342@@ -16196,7 +16222,7 @@ done
9343
9344
9345 # Agent:
9346-for ac_header in dlfcn.h err.h fcntl.h fstab.h grp.h io.h ioctls.h kstat.h kvm.h limits.h mntent.h mtab.h nlist.h pkglocs.h pwd.h utmpx.h utsname.h
9347+for ac_header in dlfcn.h err.h fcntl.h fstab.h grp.h io.h ioctls.h kstat.h kvm.h limits.h mntent.h mtab.h pkglocs.h pwd.h utmpx.h utsname.h
9348 do :
9349 as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
9350 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
9351@@ -18318,7 +18344,7 @@ while test "x$new_transport_list" != "x"; do
9352 /* end confdefs.h. */
9353
9354 #include NETSNMP_SYSTEM_INCLUDE_FILE
9355-#define NETSNMP_FEATURE_CHECKING
9356+#undef NETSNMP_MINIMAL_CODE
9357 #define NET_SNMP_CONFIG_H
9358 #undef config_require
9359 #define config_require(foo) config_checkit_require(foo)
9360@@ -19861,6 +19887,99 @@ done
9361
9362 LIBS="$netsnmp_save_LIBS"
9363
9364+#
9365+# dynamic module support
9366+#
9367+
9368+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing dlopen" >&5
9369+$as_echo_n "checking for library containing dlopen... " >&6; }
9370+if ${netsnmp_cv_func_dlopen_LMIBLIBS+:} false; then :
9371+ $as_echo_n "(cached) " >&6
9372+else
9373+ netsnmp_func_search_save_LIBS="$LIBS"
9374+ netsnmp_target_val="$LMIBLIBS"
9375+ netsnmp_temp_LIBS="${netsnmp_target_val} $LAGENTLIBS $LSNMPLIBS ${LIBS}"
9376+ netsnmp_result=no
9377+ LIBS="${netsnmp_temp_LIBS}"
9378+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
9379+/* end confdefs.h. */
9380+
9381+/* Override any GCC internal prototype to avoid an error.
9382+ Use char because int might match the return type of a GCC
9383+ builtin and then its argument prototype would still apply. */
9384+#ifdef __cplusplus
9385+extern "C"
9386+#endif
9387+char dlopen ();
9388+int
9389+main ()
9390+{
9391+return dlopen ();
9392+ ;
9393+ return 0;
9394+}
9395+_ACEOF
9396+if ac_fn_c_try_link "$LINENO"; then :
9397+ netsnmp_result="none required"
9398+else
9399+ for netsnmp_cur_lib in dl ; do
9400+ LIBS="-l${netsnmp_cur_lib} ${netsnmp_temp_LIBS}"
9401+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
9402+/* end confdefs.h. */
9403+
9404+/* Override any GCC internal prototype to avoid an error.
9405+ Use char because int might match the return type of a GCC
9406+ builtin and then its argument prototype would still apply. */
9407+#ifdef __cplusplus
9408+extern "C"
9409+#endif
9410+char dlopen ();
9411+int
9412+main ()
9413+{
9414+return dlopen ();
9415+ ;
9416+ return 0;
9417+}
9418+_ACEOF
9419+if ac_fn_c_try_link "$LINENO"; then :
9420+ netsnmp_result=-l${netsnmp_cur_lib}
9421+ break
9422+fi
9423+rm -f core conftest.err conftest.$ac_objext \
9424+ conftest$ac_exeext conftest.$ac_ext
9425+ done
9426+fi
9427+rm -f core conftest.err conftest.$ac_objext \
9428+ conftest$ac_exeext conftest.$ac_ext
9429+ LIBS="${netsnmp_func_search_save_LIBS}"
9430+ netsnmp_cv_func_dlopen_LMIBLIBS="${netsnmp_result}"
9431+fi
9432+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $netsnmp_cv_func_dlopen_LMIBLIBS" >&5
9433+$as_echo "$netsnmp_cv_func_dlopen_LMIBLIBS" >&6; }
9434+ if test "${netsnmp_cv_func_dlopen_LMIBLIBS}" != "no" ; then
9435+ if test "${netsnmp_cv_func_dlopen_LMIBLIBS}" != "none required" ; then
9436+ LMIBLIBS="${netsnmp_result} ${netsnmp_target_val}"
9437+ fi
9438+
9439+
9440+ fi
9441+
9442+netsnmp_save_LIBS="$LIBS"
9443+LIBS="$LMIBLIBS $LAGENTLIBS $LSNMPLIBS $LIBS"
9444+for ac_func in dlopen
9445+do :
9446+ ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen"
9447+if test "x$ac_cv_func_dlopen" = xyes; then :
9448+ cat >>confdefs.h <<_ACEOF
9449+#define HAVE_DLOPEN 1
9450+_ACEOF
9451+
9452+fi
9453+done
9454+
9455+LIBS="$netsnmp_save_LIBS"
9456+
9457 # -*- autoconf -*-
9458 #
9459 # generate empty files
9460@@ -20087,7 +20206,8 @@ _ACEOF
9461 module_type=mib_module
9462 if test -f $srcdir/$mibdir/$i.h; then
9463
9464- module_type=`$MODULECPP module_tmp_header.h | $GREP config_belongs_in | $SED 's@.*config_belongs_in(\([^)]*\)).*@\1@'`
9465+ module_type=`$MODULECPP module_tmp_header.h | \
9466+ $SED -n 's@.*config_belongs_in(\([^)]*\)).*@\1@p'`
9467
9468 fi
9469 if test "x$module_type" = "x" ; then
9470@@ -20188,7 +20308,8 @@ _ACEOF
9471 # check if $i has any conflicts
9472 #
9473
9474- new_list_excl=`$MODULECPP module_tmp_header.h | $GREP config_exclude | $SED 's/.*config_exclude(\(.*\)).*/\1/'`
9475+ new_list_excl=`$MODULECPP module_tmp_header.h | \
9476+ $SED -n 's/.*config_exclude(\(.*\)).*/\1/p'`
9477 if test "x$new_list_excl" != "x"; then
9478
9479 if test $module_debug = 1; then
9480@@ -20233,7 +20354,8 @@ EOF
9481 #
9482
9483
9484- new_list_arch=`$MODULECPP module_tmp_header.h | $GREP config_arch_require | $SED 's/.*config_arch_require( *\([^ ]*\) *, *\([^ ]*\) *).*/\1-xarchx-\2/'`
9485+ new_list_arch=`$MODULECPP module_tmp_header.h | \
9486+ $SED -n 's/.*config_arch_require( *\([^ ]*\) *, *\([^ ]*\) *).*/\1-xarchx-\2/p'`
9487
9488 if test "x$new_list_arch" != "x"; then
9489 for j in $new_list_arch
9490@@ -20264,11 +20386,7 @@ EOF
9491 #
9492
9493 new_list_alt3=`$MODULECPP module_tmp_header.h | \
9494- $GREP config_version_require | \
9495- $SED -e 's/ */ /g' \
9496- -e 's/.*config_version_require(( *\([^)]*\) *)).*/\1/' \
9497- -e 's/ *, */,/g' | \
9498- awk '
9499+ $AWK '
9500 BEGIN {
9501 if("'"$enable_new_features"'" == "yes")
9502 method="max";
9503@@ -20280,7 +20398,10 @@ EOF
9504 split("'"$with_features_of"'", a);
9505 version=sprintf("%03d%03d%03d%03d", a[1], a[2], a[3], a[4]);
9506 }
9507- {
9508+ /config_version_require/ {
9509+ gsub("^.*config_version_require *\\\\(\\\\(", "");
9510+ gsub("\\\\)\\\\).*$", "");
9511+ gsub(", *", ",");
9512 FS = ",";
9513 n = split($0, a);
9514 FS = ".";
9515@@ -20311,7 +20432,8 @@ EOF
9516 # check if $i has any other required modules
9517 #
9518
9519- new_list="$new_list `$MODULECPP module_tmp_header.h | $GREP config_require | $SED 's/.*config_require(\(.*\)).*/\1/'`"
9520+ new_list="$new_list `$MODULECPP module_tmp_header.h | \
9521+ $SED -n 's/.*config_require(\(.*\)).*/\1/p'`"
9522
9523 if test $module_debug = 1; then
9524 echo " $i will test: $new_list"
9525@@ -20369,7 +20491,8 @@ EOF
9526 # check if $i has any mibs to add
9527 #
9528
9529- new_mibs=`$MODULECPP module_tmp_header.h | $GREP config_add_mib | $SED 's/.*config_add_mib(\(.*\)).*/\1/'`
9530+ new_mibs=`$MODULECPP module_tmp_header.h | \
9531+ $SED -n 's/.*config_add_mib(\(.*\)).*/\1/p'`
9532 if test "x$new_mibs" != "x"; then
9533 for j in $new_mibs
9534 do
9535@@ -20410,7 +20533,7 @@ EOF
9536 #-------------------
9537 # check for unsupported config_load_mib
9538 #
9539- if $MODULECPP module_tmp_header.h | $GREP config_load_mib > /dev/null 2>&1; then
9540+ if $MODULECPP module_tmp_header.h | $GREP -q config_load_mib; then
9541 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: mib module error" >&5
9542 $as_echo "$as_me: WARNING: mib module error" >&2;}
9543 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: mib module \"$i\" uses the \"config_load_mib\" directive, which is no longer supported. It probably won't work." >&5
9544@@ -20423,7 +20546,8 @@ $as_echo "$as_me: WARNING: mib module \"$i\" uses the \"config_load_mib\" direct
9545 #
9546
9547
9548- $MODULECPP module_tmp_header.h | $GREP config_parse_dot_conf | $SED 's@.*config_parse_dot_conf(\([^)]*\), *\([^),]*\), *\([^),]*\), *\([^),]*\)).*@register_config_handler("snmpd",\1, \2, \3, \4);@' >> $mibdir/mib_module_dot_conf.h
9549+ $MODULECPP module_tmp_header.h | \
9550+ $SED -n 's@.*config_parse_dot_conf(\([^)]*\), *\([^),]*\), *\([^),]*\), *\([^),]*\)).*@register_config_handler("snmpd",\1, \2, \3, \4);@p' >> $mibdir/mib_module_dot_conf.h
9551
9552
9553 #---------------------
9554@@ -20433,7 +20557,8 @@ $as_echo "$as_me: WARNING: mib module \"$i\" uses the \"config_load_mib\" direct
9555 # check if $i has any errors, or warnings
9556 #
9557
9558- error=`$MODULECPP module_tmp_header.h | $GREP config_error | $SED 's/.*config_error(\(.*\)).*/\1/'`
9559+ error=`$MODULECPP module_tmp_header.h | \
9560+ $SED -n 's/.*config_error(\(.*\)).*/\1/p'`
9561 if test "x$error" != "x"; then
9562 echo
9563 echo
9564@@ -20445,7 +20570,8 @@ $as_echo "$as_me: WARNING: mib module \"$i\" uses the \"config_load_mib\" direct
9565 # - used to signal a configuration "warning" to be printed to the user
9566 #
9567
9568- warning=`$MODULECPP module_tmp_header.h | $GREP config_warning | $SED 's/.*config_warning(\(.*\)).*/\1/'`
9569+ warning=`$MODULECPP module_tmp_header.h | \
9570+ $SED -n 's/.*config_warning(\(.*\)).*/\1/p'`
9571 if test "x$warning" != "x"; then
9572 all_warnings="$all_warnings $warning
9573 "
9574@@ -21653,99 +21779,6 @@ $as_echo "#define HAVE_LIBKSTAT 1" >>confdefs.h
9575
9576
9577
9578-# dynamic module support
9579-#
9580-
9581- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing dlopen" >&5
9582-$as_echo_n "checking for library containing dlopen... " >&6; }
9583-if ${netsnmp_cv_func_dlopen_LMIBLIBS+:} false; then :
9584- $as_echo_n "(cached) " >&6
9585-else
9586- netsnmp_func_search_save_LIBS="$LIBS"
9587- netsnmp_target_val="$LMIBLIBS"
9588- netsnmp_temp_LIBS="${netsnmp_target_val} ${LIBS}"
9589- netsnmp_result=no
9590- LIBS="${netsnmp_temp_LIBS}"
9591- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
9592-/* end confdefs.h. */
9593-
9594-/* Override any GCC internal prototype to avoid an error.
9595- Use char because int might match the return type of a GCC
9596- builtin and then its argument prototype would still apply. */
9597-#ifdef __cplusplus
9598-extern "C"
9599-#endif
9600-char dlopen ();
9601-int
9602-main ()
9603-{
9604-return dlopen ();
9605- ;
9606- return 0;
9607-}
9608-_ACEOF
9609-if ac_fn_c_try_link "$LINENO"; then :
9610- netsnmp_result="none required"
9611-else
9612- for netsnmp_cur_lib in dl ; do
9613- LIBS="-l${netsnmp_cur_lib} ${netsnmp_temp_LIBS}"
9614- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
9615-/* end confdefs.h. */
9616-
9617-/* Override any GCC internal prototype to avoid an error.
9618- Use char because int might match the return type of a GCC
9619- builtin and then its argument prototype would still apply. */
9620-#ifdef __cplusplus
9621-extern "C"
9622-#endif
9623-char dlopen ();
9624-int
9625-main ()
9626-{
9627-return dlopen ();
9628- ;
9629- return 0;
9630-}
9631-_ACEOF
9632-if ac_fn_c_try_link "$LINENO"; then :
9633- netsnmp_result=-l${netsnmp_cur_lib}
9634- break
9635-fi
9636-rm -f core conftest.err conftest.$ac_objext \
9637- conftest$ac_exeext conftest.$ac_ext
9638- done
9639-fi
9640-rm -f core conftest.err conftest.$ac_objext \
9641- conftest$ac_exeext conftest.$ac_ext
9642- LIBS="${netsnmp_func_search_save_LIBS}"
9643- netsnmp_cv_func_dlopen_LMIBLIBS="${netsnmp_result}"
9644-fi
9645-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $netsnmp_cv_func_dlopen_LMIBLIBS" >&5
9646-$as_echo "$netsnmp_cv_func_dlopen_LMIBLIBS" >&6; }
9647- if test "${netsnmp_cv_func_dlopen_LMIBLIBS}" != "no" ; then
9648- if test "${netsnmp_cv_func_dlopen_LMIBLIBS}" != "none required" ; then
9649- LMIBLIBS="${netsnmp_result} ${netsnmp_target_val}"
9650- fi
9651-
9652-
9653- fi
9654-
9655-netsnmp_save_LIBS="$LIBS"
9656-LIBS="$LMIBLIBS $LIBS"
9657-for ac_func in dlopen
9658-do :
9659- ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen"
9660-if test "x$ac_cv_func_dlopen" = xyes; then :
9661- cat >>confdefs.h <<_ACEOF
9662-#define HAVE_DLOPEN 1
9663-_ACEOF
9664-
9665-fi
9666-done
9667-
9668-LIBS="$netsnmp_save_LIBS"
9669-
9670-
9671 ##
9672 # MIB-module-specific checks
9673 ##
9674@@ -22482,6 +22515,54 @@ $as_echo "#define HAVE_AES_CFB128_ENCRYPT 1" >>confdefs.h
9675
9676 fi
9677
9678+
9679+ as_ac_Lib=`$as_echo "ac_cv_lib_${CRYPTO}''_EVP_MD_CTX_create" | $as_tr_sh`
9680+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for EVP_MD_CTX_create in -l${CRYPTO}" >&5
9681+$as_echo_n "checking for EVP_MD_CTX_create in -l${CRYPTO}... " >&6; }
9682+if eval \${$as_ac_Lib+:} false; then :
9683+ $as_echo_n "(cached) " >&6
9684+else
9685+ ac_check_lib_save_LIBS=$LIBS
9686+LIBS="-l${CRYPTO} $LIBS"
9687+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
9688+/* end confdefs.h. */
9689+
9690+/* Override any GCC internal prototype to avoid an error.
9691+ Use char because int might match the return type of a GCC
9692+ builtin and then its argument prototype would still apply. */
9693+#ifdef __cplusplus
9694+extern "C"
9695+#endif
9696+char EVP_MD_CTX_create ();
9697+int
9698+main ()
9699+{
9700+return EVP_MD_CTX_create ();
9701+ ;
9702+ return 0;
9703+}
9704+_ACEOF
9705+if ac_fn_c_try_link "$LINENO"; then :
9706+ eval "$as_ac_Lib=yes"
9707+else
9708+ eval "$as_ac_Lib=no"
9709+fi
9710+rm -f core conftest.err conftest.$ac_objext \
9711+ conftest$ac_exeext conftest.$ac_ext
9712+LIBS=$ac_check_lib_save_LIBS
9713+fi
9714+eval ac_res=\$$as_ac_Lib
9715+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
9716+$as_echo "$ac_res" >&6; }
9717+if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
9718+
9719+$as_echo "#define HAVE_EVP_MD_CTX_CREATE /**/" >>confdefs.h
9720+
9721+
9722+$as_echo "#define HAVE_EVP_MD_CTX_DESTROY /**/" >>confdefs.h
9723+
9724+fi
9725+
9726 fi
9727 if echo " $transport_result_list " | $GREP "DTLS" > /dev/null; then
9728 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for DTLSv1_method in -lssl" >&5
9729@@ -22984,6 +23065,38 @@ fi
9730 fi
9731 MYSQL_LIBS=`$MYSQLCONFIG --libs`
9732 MYSQL_INCLUDES=`$MYSQLCONFIG --cflags`
9733+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether MY_INIT() works" >&5
9734+$as_echo_n "checking whether MY_INIT() works... " >&6; }
9735+ _libs="${LIBS}"
9736+ _cppflags="${CPPFLAGS}"
9737+ LIBS="${LIBS} ${MYSQL_LIBS}"
9738+ CPPFLAGS="${CPPFLAGS} ${MYSQL_INCLUDES}"
9739+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
9740+/* end confdefs.h. */
9741+#include <mysql/my_global.h>
9742+ #include <mysql/my_sys.h>
9743+int
9744+main ()
9745+{
9746+MY_INIT("my_init_test")
9747+ ;
9748+ return 0;
9749+}
9750+_ACEOF
9751+if ac_fn_c_try_link "$LINENO"; then :
9752+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
9753+$as_echo "yes" >&6; }
9754+else
9755+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
9756+$as_echo "no" >&6; }
9757+
9758+$as_echo "#define HAVE_BROKEN_LIBMYSQLCLIENT 1" >>confdefs.h
9759+
9760+fi
9761+rm -f core conftest.err conftest.$ac_objext \
9762+ conftest$ac_exeext conftest.$ac_ext
9763+ CPPFLAGS="${_cppflags}"
9764+ LIBS="${_libs}"
9765
9766 cat >> configure-summary << EOF
9767 MYSQL Trap Logging: enabled
9768@@ -24771,7 +24884,7 @@ done
9769
9770
9771 # Library:
9772-for ac_func in closedir fork getipnodebyname gettimeofday if_nametoindex mkstemp opendir readdir regcomp setenv setitimer setlocale setsid snprintf strcasestr strdup strerror strncasecmp sysconf times vsnprintf
9773+for ac_func in closedir fgetc_unlocked flockfile fork funlockfile getipnodebyname gettimeofday if_nametoindex mkstemp opendir readdir regcomp setenv setitimer setlocale setsid snprintf strcasestr strdup strerror strncasecmp sysconf times vsnprintf
9774 do :
9775 as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
9776 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
9777@@ -24941,6 +25054,19 @@ esac
9778
9779 fi
9780
9781+ac_fn_c_check_func "$LINENO" "strlcat" "ac_cv_func_strlcat"
9782+if test "x$ac_cv_func_strlcat" = xyes; then :
9783+ $as_echo "#define HAVE_STRLCAT 1" >>confdefs.h
9784+
9785+else
9786+ case " $LIBOBJS " in
9787+ *" strlcat.$ac_objext "* ) ;;
9788+ *) LIBOBJS="$LIBOBJS strlcat.$ac_objext"
9789+ ;;
9790+esac
9791+
9792+fi
9793+
9794 ac_fn_c_check_func "$LINENO" "strlcpy" "ac_cv_func_strlcpy"
9795 if test "x$ac_cv_func_strlcpy" = xyes; then :
9796 $as_echo "#define HAVE_STRLCPY 1" >>confdefs.h
9797@@ -25651,6 +25777,28 @@ _ACEOF
9798 fi
9799
9800
9801+# struct ethtool_cmd
9802+#
9803+if test "x$ac_cv_header_linux_ethtool_h" = "xyes" ; then
9804+ac_fn_c_check_member "$LINENO" "struct ethtool_cmd" "speed_hi" "ac_cv_member_struct_ethtool_cmd_speed_hi" "
9805+ $ac_includes_default
9806+
9807+#ifdef HAVE_LINUX_ETHTOOL_H
9808+#include <linux/ethtool.h>
9809+#endif
9810+
9811+"
9812+if test "x$ac_cv_member_struct_ethtool_cmd_speed_hi" = xyes; then :
9813+
9814+cat >>confdefs.h <<_ACEOF
9815+#define HAVE_STRUCT_ETHTOOL_CMD_SPEED_HI 1
9816+_ACEOF
9817+
9818+
9819+fi
9820+
9821+fi
9822+
9823 # struct ipstat
9824 # Agent:
9825 #
9826@@ -26526,6 +26674,50 @@ _ACEOF
9827 fi
9828
9829
9830+# extern timezone
9831+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking extern timezone" >&5
9832+$as_echo_n "checking extern timezone... " >&6; }
9833+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
9834+/* end confdefs.h. */
9835+
9836+#if TIME_WITH_SYS_TIME
9837+# include <sys/time.h>
9838+# include <time.h>
9839+#else
9840+# if HAVE_SYS_TIME_H
9841+# include <sys/time.h>
9842+# else
9843+# include <time.h>
9844+# endif
9845+#endif
9846+
9847+int
9848+main ()
9849+{
9850+
9851+ return timezone;
9852+
9853+ ;
9854+ return 0;
9855+}
9856+_ACEOF
9857+if ac_fn_c_try_link "$LINENO"; then :
9858+
9859+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
9860+$as_echo "yes" >&6; }
9861+
9862+$as_echo "#define HAVE_TIMEZONE_VARIABLE 1" >>confdefs.h
9863+
9864+
9865+else
9866+
9867+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
9868+$as_echo "no" >&6; }
9869+
9870+fi
9871+rm -f core conftest.err conftest.$ac_objext \
9872+ conftest$ac_exeext conftest.$ac_ext
9873+
9874 # struct timezone
9875 # Library:
9876 #
9877diff --git a/configure.d/config_modules_agent b/configure.d/config_modules_agent
9878index 87ec3a5..3272679 100644
9879--- a/configure.d/config_modules_agent
9880+++ b/configure.d/config_modules_agent
9881@@ -189,7 +189,8 @@ while test "x$new_module_list" != "x"; do
9882 module_type=mib_module
9883 if test -f $srcdir/$mibdir/$i.h; then
9884 changequote(, )
9885- module_type=`$MODULECPP module_tmp_header.h | $GREP config_belongs_in | $SED 's@.*config_belongs_in(\([^)]*\)).*@\1@'`
9886+ module_type=`$MODULECPP module_tmp_header.h | \
9887+ $SED -n 's@.*config_belongs_in(\([^)]*\)).*@\1@p'`
9888 changequote([, ])
9889 fi
9890 if test "x$module_type" = "x" ; then
9891@@ -270,7 +271,8 @@ while test "x$new_module_list" != "x"; do
9892 # check if $i has any conflicts
9893 #
9894 AH_TOP([#define config_exclude(x)])
9895- new_list_excl=`$MODULECPP module_tmp_header.h | $GREP config_exclude | $SED 's/.*config_exclude(\(.*\)).*/\1/'`
9896+ new_list_excl=`$MODULECPP module_tmp_header.h | \
9897+ $SED -n 's/.*config_exclude(\(.*\)).*/\1/p'`
9898 if test "x$new_list_excl" != "x"; then
9899 AC_MSG_MODULE_DBG("$i excludes $new_list_excl")
9900 for j in $new_list_excl
9901@@ -299,7 +301,8 @@ while test "x$new_module_list" != "x"; do
9902 #
9903 AH_TOP([#define config_arch_require(x,y)])
9904 changequote(, )
9905- new_list_arch=`$MODULECPP module_tmp_header.h | $GREP config_arch_require | $SED 's/.*config_arch_require( *\([^ ]*\) *, *\([^ ]*\) *).*/\1-xarchx-\2/'`
9906+ new_list_arch=`$MODULECPP module_tmp_header.h | \
9907+ $SED -n 's/.*config_arch_require( *\([^ ]*\) *, *\([^ ]*\) *).*/\1-xarchx-\2/p'`
9908 changequote([, ])
9909 if test "x$new_list_arch" != "x"; then
9910 for j in $new_list_arch
9911@@ -320,11 +323,7 @@ while test "x$new_module_list" != "x"; do
9912 #
9913 AH_TOP([#define config_version_require(x)])
9914 [new_list_alt3=`$MODULECPP module_tmp_header.h | \
9915- $GREP config_version_require | \
9916- $SED -e 's/ */ /g' \
9917- -e 's/.*config_version_require(( *\([^)]*\) *)).*/\1/' \
9918- -e 's/ *, */,/g' | \
9919- awk '
9920+ $AWK '
9921 BEGIN {
9922 if("'"$enable_new_features"'" == "yes")
9923 method="max";
9924@@ -336,7 +335,10 @@ while test "x$new_module_list" != "x"; do
9925 split("'"$with_features_of"'", a);
9926 version=sprintf("%03d%03d%03d%03d", a[1], a[2], a[3], a[4]);
9927 }
9928- {
9929+ /config_version_require/ {
9930+ gsub("^.*config_version_require *\\\\(\\\\(", "");
9931+ gsub("\\\\)\\\\).*$", "");
9932+ gsub(", *", ",");
9933 FS = ",";
9934 n = split($0, a);
9935 FS = ".";
9936@@ -362,7 +364,8 @@ while test "x$new_module_list" != "x"; do
9937 # check if $i has any other required modules
9938 #
9939 AH_TOP([#define config_require(x)])
9940- new_list="$new_list `$MODULECPP module_tmp_header.h | $GREP config_require | $SED 's/.*config_require(\(.*\)).*/\1/'`"
9941+ new_list="$new_list `$MODULECPP module_tmp_header.h | \
9942+ $SED -n 's/.*config_require(\(.*\)).*/\1/p'`"
9943 AC_MSG_MODULE_DBG(" $i will test: $new_list")
9944 if test "x$new_list" != "x"; then
9945 for j in $new_list
9946@@ -398,7 +401,8 @@ while test "x$new_module_list" != "x"; do
9947 # check if $i has any mibs to add
9948 #
9949 AH_TOP([#define config_add_mib(x)])
9950- new_mibs=`$MODULECPP module_tmp_header.h | $GREP config_add_mib | $SED 's/.*config_add_mib(\(.*\)).*/\1/'`
9951+ new_mibs=`$MODULECPP module_tmp_header.h | \
9952+ $SED -n 's/.*config_add_mib(\(.*\)).*/\1/p'`
9953 if test "x$new_mibs" != "x"; then
9954 for j in $new_mibs
9955 do
9956@@ -434,7 +438,7 @@ while test "x$new_module_list" != "x"; do
9957 #-------------------
9958 # check for unsupported config_load_mib
9959 #
9960- if $MODULECPP module_tmp_header.h | $GREP config_load_mib > /dev/null 2>&1; then
9961+ if $MODULECPP module_tmp_header.h | $GREP -q config_load_mib; then
9962 AC_MSG_WARN([mib module error])
9963 AC_MSG_WARN([mib module "$i" uses the "config_load_mib" directive, which is no longer supported. It probably won't work.])
9964 fi # grep config_load_mib
9965@@ -445,7 +449,8 @@ while test "x$new_module_list" != "x"; do
9966 #
9967 AH_TOP([#define config_parse_dot_conf(w,x,y,z)])
9968 changequote(, )
9969- $MODULECPP module_tmp_header.h | $GREP config_parse_dot_conf | $SED 's@.*config_parse_dot_conf(\([^)]*\), *\([^),]*\), *\([^),]*\), *\([^),]*\)).*@register_config_handler("snmpd",\1, \2, \3, \4);@' >> $mibdir/mib_module_dot_conf.h
9970+ $MODULECPP module_tmp_header.h | \
9971+ $SED -n 's@.*config_parse_dot_conf(\([^)]*\), *\([^),]*\), *\([^),]*\), *\([^),]*\)).*@register_config_handler("snmpd",\1, \2, \3, \4);@p' >> $mibdir/mib_module_dot_conf.h
9972 changequote([, ])
9973
9974 #---------------------
9975@@ -455,7 +460,8 @@ while test "x$new_module_list" != "x"; do
9976 # check if $i has any errors, or warnings
9977 #
9978 AH_TOP([#define config_error(x)])
9979- error=`$MODULECPP module_tmp_header.h | $GREP config_error | $SED 's/.*config_error(\(.*\)).*/\1/'`
9980+ error=`$MODULECPP module_tmp_header.h | \
9981+ $SED -n 's/.*config_error(\(.*\)).*/\1/p'`
9982 if test "x$error" != "x"; then
9983 echo
9984 echo
9985@@ -467,7 +473,8 @@ while test "x$new_module_list" != "x"; do
9986 # - used to signal a configuration "warning" to be printed to the user
9987 #
9988 AH_TOP([#define config_warning(x)])
9989- warning=`$MODULECPP module_tmp_header.h | $GREP config_warning | $SED 's/.*config_warning(\(.*\)).*/\1/'`
9990+ warning=`$MODULECPP module_tmp_header.h | \
9991+ $SED -n 's/.*config_warning(\(.*\)).*/\1/p'`
9992 if test "x$warning" != "x"; then
9993 all_warnings="$all_warnings $warning
9994 "
9995diff --git a/configure.d/config_modules_transports b/configure.d/config_modules_transports
9996index 2a49da8..b10b960 100644
9997--- a/configure.d/config_modules_transports
9998+++ b/configure.d/config_modules_transports
9999@@ -71,7 +71,7 @@ while test "x$new_transport_list" != "x"; do
10000 rm -f conftest.$ac_ext module_tmp_header.h
10001 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
10002 #include NETSNMP_SYSTEM_INCLUDE_FILE
10003-#define NETSNMP_FEATURE_CHECKING
10004+#undef NETSNMP_MINIMAL_CODE
10005 #define NET_SNMP_CONFIG_H
10006 #undef config_require
10007 #define config_require(foo) config_checkit_require(foo)
10008diff --git a/configure.d/config_os_functions b/configure.d/config_os_functions
10009index 7736994..3c5385b 100644
10010--- a/configure.d/config_os_functions
10011+++ b/configure.d/config_os_functions
10012@@ -31,7 +31,8 @@ AC_CHECK_FUNCS([lrand48 rand random ] dnl
10013 [signal sigset ] )
10014
10015 # Library:
10016-AC_CHECK_FUNCS([closedir fork getipnodebyname ] dnl
10017+AC_CHECK_FUNCS([closedir fgetc_unlocked flockfile ] dnl
10018+ [fork funlockfile getipnodebyname ] dnl
10019 [gettimeofday if_nametoindex mkstemp ] dnl
10020 [opendir readdir regcomp ] dnl
10021 [setenv setitimer setlocale ] dnl
10022@@ -82,8 +83,8 @@ esac
10023 AC_CONFIG_LIBOBJ_DIR([snmplib])
10024
10025 AC_REPLACE_FUNCS([getopt inet_ntop inet_pton ] dnl
10026- [strlcpy strtok_r strtol ] dnl
10027- [strtoul strtoull ] )
10028+ [strlcat strlcpy strtok_r ] dnl
10029+ [strtol strtoul strtoull ] )
10030
10031 # Agent:
10032 AC_CHECK_FUNCS([cgetnext chown execv ] dnl
10033@@ -133,7 +134,7 @@ fi
10034 AC_MSG_CHECKING([[for two-argument statfs with struct fs_data (Ultrix)]])
10035 AC_CACHE_VAL(
10036 fu_cv_sys_stat_fs_data,
10037- [AC_TRY_RUN([
10038+ [AC_RUN_IFELSE([AC_LANG_SOURCE([[
10039 #ifdef HAVE_SYS_PARAM_H
10040 #include <sys/param.h>
10041 #endif
10042@@ -150,10 +151,10 @@ struct fs_data fsd;
10043 /* Ultrix's statfs returns 1 for success,
10044 0 for not mounted, -1 for failure. */
10045 exit (statfs (".", &fsd) != 1);
10046-}],
10047- fu_cv_sys_stat_fs_data=yes,
10048- fu_cv_sys_stat_fs_data=no,
10049- fu_cv_sys_stat_fs_data=no)])
10050+}]])],
10051+ [fu_cv_sys_stat_fs_data=yes],
10052+ [fu_cv_sys_stat_fs_data=no],
10053+ [fu_cv_sys_stat_fs_data=no])])
10054 AC_MSG_RESULT($fu_cv_sys_stat_fs_data)
10055 if test $fu_cv_sys_stat_fs_data = yes; then
10056 AC_DEFINE(STAT_STATFS_FS_DATA, 1,
10057@@ -309,10 +310,11 @@ if echo " $transport_result_list " | $GREP "DTLS" > /dev/null; then
10058 [
10059 oldLIBS="$LIBS"
10060 LIBS="$LIBS -lcrypto"
10061- AC_TRY_LINK(
10062- [#include <openssl/bio.h>],
10063- [BIO_dgram_get_peer(NULL, NULL);],,
10064- AC_MSG_ERROR([DTLS support requires a newer version of OpenSSL]))
10065+ AC_LINK_IFELSE(
10066+ [AC_LANG_PROGRAM(
10067+ [[#include <openssl/bio.h>]],
10068+ [[BIO_dgram_get_peer(NULL, NULL);]])], [],
10069+ [AC_MSG_ERROR(DTLS support requires a newer version of OpenSSL)])
10070
10071 LIBS="$oldLIBS"
10072 ]
10073diff --git a/configure.d/config_os_headers b/configure.d/config_os_headers
10074index 23cc38d..d903f58 100644
10075--- a/configure.d/config_os_headers
10076+++ b/configure.d/config_os_headers
10077@@ -30,9 +30,18 @@ AC_CHECK_HEADERS([getopt.h pthread.h regex.h ] dnl
10078 [sys/timeb.h ] dnl
10079 [sys/un.h ])
10080
10081+# Library and Agent:
10082+AC_CHECK_HEADERS([nlist.h],,,[
10083+AC_INCLUDES_DEFAULT
10084+[
10085+#ifndef LIBBSD_DISABLE_DEPRECATED
10086+#define LIBBSD_DISABLE_DEPRECATED 1
10087+#endif
10088+]])
10089+
10090 # Library:
10091 AC_CHECK_HEADERS([fcntl.h io.h kstat.h ] dnl
10092- [limits.h locale.h nlist.h ] dnl
10093+ [limits.h locale.h ] dnl
10094 [sys/file.h sys/ioctl.h ] dnl
10095 [sys/sockio.h sys/stat.h ] dnl
10096 [sys/systemcfg.h sys/systeminfo.h ] dnl
10097@@ -45,7 +54,7 @@ AC_CHECK_HEADERS([dlfcn.h err.h fcntl.h fstab.h ] dnl
10098 [ grp.h io.h ] dnl
10099 [ioctls.h kstat.h kvm.h limits.h ] dnl
10100 [ mntent.h mtab.h ] dnl
10101- [nlist.h pkglocs.h pwd.h ] dnl
10102+ [ pkglocs.h pwd.h ] dnl
10103 [ utmpx.h utsname.h ])
10104
10105 AC_CHECK_HEADERS([sys/diskio.h sys/dkio.h ] dnl
10106diff --git a/configure.d/config_os_libs1 b/configure.d/config_os_libs1
10107index ce33d34..35f052a 100644
10108--- a/configure.d/config_os_libs1
10109+++ b/configure.d/config_os_libs1
10110@@ -84,3 +84,12 @@ netsnmp_save_LIBS="$LIBS"
10111 LIBS="$LAGENTLIBS $LMIBLIBS $LIBS"
10112 AC_CHECK_FUNCS([kvm_openfiles kvm_getprocs kvm_getproc2 kvm_getswapinfo])
10113 LIBS="$netsnmp_save_LIBS"
10114+
10115+#
10116+# dynamic module support
10117+#
10118+NETSNMP_SEARCH_LIBS([dlopen], [dl],,, [$LAGENTLIBS $LSNMPLIBS], [LMIBLIBS])
10119+netsnmp_save_LIBS="$LIBS"
10120+LIBS="$LMIBLIBS $LAGENTLIBS $LSNMPLIBS $LIBS"
10121+AC_CHECK_FUNCS([dlopen])
10122+LIBS="$netsnmp_save_LIBS"
10123diff --git a/configure.d/config_os_libs2 b/configure.d/config_os_libs2
10124index 22ab764..fa846c8 100644
10125--- a/configure.d/config_os_libs2
10126+++ b/configure.d/config_os_libs2
10127@@ -158,15 +158,6 @@ NETSNMP_SEARCH_LIBS(kstat_lookup, kstat,
10128 LNETSNMPLIBS)
10129
10130
10131-# dynamic module support
10132-#
10133-NETSNMP_SEARCH_LIBS(dlopen, dl,,,,LMIBLIBS)
10134-netsnmp_save_LIBS="$LIBS"
10135-LIBS="$LMIBLIBS $LIBS"
10136-AC_CHECK_FUNCS([dlopen])
10137-LIBS="$netsnmp_save_LIBS"
10138-
10139-
10140 ##
10141 # MIB-module-specific checks
10142 ##
10143@@ -277,6 +268,12 @@ if test "x$tryopenssl" != "xno" -a "x$tryopenssl" != "xinternal"; then
10144 AC_CHECK_LIB(${CRYPTO}, AES_cfb128_encrypt,
10145 AC_DEFINE(HAVE_AES_CFB128_ENCRYPT, 1,
10146 [Define to 1 if you have the `AES_cfb128_encrypt' function.]))
10147+
10148+ AC_CHECK_LIB(${CRYPTO}, EVP_MD_CTX_create,
10149+ AC_DEFINE([HAVE_EVP_MD_CTX_CREATE], [],
10150+ [Define to 1 if you have the `EVP_MD_CTX_create' function.])
10151+ AC_DEFINE([HAVE_EVP_MD_CTX_DESTROY], [],
10152+ [Define to 1 if you have the `EVP_MD_CTX_destroy' function.]))
10153 fi
10154 if echo " $transport_result_list " | $GREP "DTLS" > /dev/null; then
10155 AC_CHECK_LIB(ssl, DTLSv1_method,
10156@@ -408,12 +405,11 @@ if test "$with_libwrap" != "no"; then
10157 LIBS="$LIBS -lwrap"
10158 AC_MSG_CHECKING([for TCP wrappers library -lwrap])
10159 # XXX: should check for hosts_ctl
10160- AC_TRY_LINK(
10161- [#include <sys/types.h>
10162+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
10163 #include <tcpd.h>
10164 int allow_severity = 0;
10165- int deny_severity = 0;],
10166- [hosts_access((void *)0)],
10167+ int deny_severity = 0;]],
10168+ [[hosts_access((void *)0)]])],
10169 [AC_MSG_RESULT([yes])
10170 AC_DEFINE(NETSNMP_USE_LIBWRAP)
10171 test "$with_libwrap" != no -a "$with_libwrap" != yes && _wraplibs="-L$with_libwrap/lib"
10172@@ -423,12 +419,11 @@ if test "$with_libwrap" != "no"; then
10173 AC_CHECK_FUNC(yp_get_default_domain, ,
10174 AC_CHECK_LIB(nsl, yp_get_default_domain))
10175 AC_MSG_CHECKING([for TCP wrappers library -lwrap linked with -lnsl])
10176- AC_TRY_LINK(
10177- [#include <sys/types.h>
10178+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
10179 #include <tcpd.h>
10180 int allow_severity = 0;
10181- int deny_severity = 0;],
10182- [hosts_access((void *)0)],
10183+ int deny_severity = 0;]],
10184+ [[hosts_access((void *)0)]])],
10185 [AC_MSG_RESULT(yes)
10186 AC_DEFINE(NETSNMP_USE_LIBWRAP)
10187 test "$with_libwrap" != no -a "$with_libwrap" != yes && _wraplibs="-L$with_libwrap/lib"
10188@@ -454,6 +449,17 @@ if test "x$with_mysql" = "xyes" ; then
10189 fi
10190 MYSQL_LIBS=`$MYSQLCONFIG --libs`
10191 MYSQL_INCLUDES=`$MYSQLCONFIG --cflags`
10192+ AC_MSG_CHECKING([whether MY_INIT() works])
10193+ _libs="${LIBS}"
10194+ _cppflags="${CPPFLAGS}"
10195+ LIBS="${LIBS} ${MYSQL_LIBS}"
10196+ CPPFLAGS="${CPPFLAGS} ${MYSQL_INCLUDES}"
10197+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <mysql/my_global.h>
10198+ #include <mysql/my_sys.h>]], [[MY_INIT("my_init_test")]])],[AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)
10199+ AC_DEFINE([HAVE_BROKEN_LIBMYSQLCLIENT], 1,
10200+ [Define if using MY_INIT() causes a linker error])])
10201+ CPPFLAGS="${_cppflags}"
10202+ LIBS="${_libs}"
10203 AC_MSG_CACHE_ADD(MYSQL Trap Logging: enabled)
10204 else
10205 AC_MSG_CACHE_ADD(MYSQL Trap Logging: unavailable)
10206diff --git a/configure.d/config_os_struct_members b/configure.d/config_os_struct_members
10207index 17bb489..9f015ac 100644
10208--- a/configure.d/config_os_struct_members
10209+++ b/configure.d/config_os_struct_members
10210@@ -57,6 +57,18 @@ AC_CHECK_MEMBERS([struct dirent.d_type],,,[
10211 #endif
10212 ]])
10213
10214+# struct ethtool_cmd
10215+#
10216+if test "x$ac_cv_header_linux_ethtool_h" = "xyes" ; then
10217+AC_CHECK_MEMBERS([struct ethtool_cmd.speed_hi],,,[
10218+ AC_INCLUDES_DEFAULT()
10219+ [
10220+#ifdef HAVE_LINUX_ETHTOOL_H
10221+#include <linux/ethtool.h>
10222+#endif
10223+ ]])
10224+fi
10225+
10226 # struct ipstat
10227 # Agent:
10228 #
10229@@ -310,6 +322,28 @@ AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,[
10230 #endif
10231 ]])
10232
10233+# extern timezone
10234+AC_MSG_CHECKING([extern timezone])
10235+AC_LINK_IFELSE([AC_LANG_PROGRAM([[
10236+#if TIME_WITH_SYS_TIME
10237+# include <sys/time.h>
10238+# include <time.h>
10239+#else
10240+# if HAVE_SYS_TIME_H
10241+# include <sys/time.h>
10242+# else
10243+# include <time.h>
10244+# endif
10245+#endif
10246+]], [[
10247+ return timezone;
10248+]])], [
10249+AC_MSG_RESULT([yes])
10250+AC_DEFINE([HAVE_TIMEZONE_VARIABLE], [1], [Define if a timezone variable is declared in <sys/time.h>])
10251+], [
10252+AC_MSG_RESULT([no])
10253+])
10254+
10255 # struct timezone
10256 # Library:
10257 #
10258diff --git a/configure.d/config_project_with_enable b/configure.d/config_project_with_enable
10259index 732742b..2cf7aec 100644
10260--- a/configure.d/config_project_with_enable
10261+++ b/configure.d/config_project_with_enable
10262@@ -93,7 +93,12 @@ NETSNMP_ARG_WITH(openssl,
10263 elif test "x$withval" = "xno"; then
10264 tryopenssl=no
10265 elif test -d "$withval"; then
10266- AC_ADD_SEARCH_PATH($withval)
10267+ if test -d "$withval/lib/MinGW"; then
10268+ LDFLAGS="-L$withval/lib/MinGW $LDFLAGS"
10269+ CPPFLAGS="-I$withval/include $CPPFLAGS"
10270+ else
10271+ AC_ADD_SEARCH_PATH($withval)
10272+ fi
10273 tryopenssl=yes
10274 askedopenssl=yes
10275 fi,
10276diff --git a/dist/extractnews b/dist/extractnews
10277index 848909a..bce94c9 100755
10278--- a/dist/extractnews
10279+++ b/dist/extractnews
10280@@ -19,12 +19,13 @@ LocalGetOptions(\%opts,
10281 "",
10282 ['c|changes-file=s','A file to save CHANGES entries to'],
10283 ['n|news-file=s','A file to save NEWS entries to'],
10284+ ['d|debug-line=s', 'Debugging output for lines matching STRING'],
10285 "",
10286 ['GUI:otherargs_text','Input files to parse'],
10287 );
10288
10289 my $maybecontinue = 0;
10290-my $lasttext = 0;
10291+my $lasttext = "";
10292 my $lastfile;
10293 my $lastcomponent;
10294
10295@@ -41,32 +42,51 @@ foreach my $argv (@ARGV) {
10296
10297 last if ($opts{'e'} && /$opts{e}/o);
10298
10299+ print STDERR "here: $_" if ($opts{'d'} && /$opts{'d'}/o);
10300+
10301 # don't use this:
10302 # FILE: BUGS: 123,456: text
10303 ($file, $patbug, $nums, $text) =
10304 /(NEWS|CHANGES):\s*-*\s*\[*(BUG|PATCH)(?:ES|S|):*\s*([\d,\s*]*)\]*:*\s*-*\s*(.*)/;
10305
10306+ print STDERR " 1:$file, $component, $patbug, $nums, $text\n" if ($opts{'d'} && /$opts{'d'}/o);
10307+
10308 # or this:
10309 # FILE: component - text
10310 ($file, $component, $text) =
10311 /(NEWS|CHANGES):\s*(\w+)\s*-+\s*(.*)/ if (!$file);
10312
10313+ print STDERR " 2:$file, $component, $patbug, $nums, $text\n" if ($opts{'d'} && /$opts{'d'}/o);
10314+
10315 # what you should use:
10316- # FILE: component: text
10317- # or
10318 # FILE: component: BUGS: 123,456: text
10319 #
10320 # or
10321 # FILE: component: PATCH: 123,456: from someone text
10322 # FILE: component: PATCH: 123,456: from "someone long" text
10323 ($file, $component, $patbug, $nums, $text) =
10324- /(NEWS|CHANGES):\s*([^:]+):\s*-*\s*\[*(BUG|PATCH)*(?:ES|S|):*\s*([\d,\s*]*)\]*:*\s*-*\s*(?:from ["'][^"]+["']|from \w+|):*\s*(.*)/ if (!$file);
10325+ /(NEWS|CHANGES):\s*([^:]+):\s*-*\s*\[*(BUG|PATCH)(?:ES|S):*\s*([\d,\s*]*)\]*:*\s*-*\s*(?:from ["'][^"]+["']|from \w+|):*\s*(.*)/ if (!$file);
10326+
10327+ print STDERR " 3:$file, $component, $patbug, $nums, $text\n" if ($opts{'d'} && /$opts{'d'}/o);
10328+
10329+ # or at least:
10330+ # FILE: component: text
10331+ ($file, $component, $text) =
10332+ /(NEWS|CHANGES):\s*([^:]+):\s*-*\s*(.*)/ if (!$file);
10333+
10334+ print STDERR " 4:$file, $component, $patbug, $nums, $text\n" if ($opts{'d'} && /$opts{'d'}/o);
10335
10336 # component left out
10337 # FILE: [BUGS: 123,456]: text
10338 ($file, $patbug, $nums, $text) =
10339 /(NEWS|CHANGES):\s*\[*(BUG|PATCH)*(?:ES|S|):*\s*([\d,\s*]*)\]*:*\s*-*\s*(.*)/ if (!$file);
10340
10341+ print STDERR " 5:$file, $component, $patbug, $nums, $text\n" if ($opts{'d'} && /$opts{'d'}/o);
10342+
10343+ if ($opts{'d'} && /$opts{'d'}/o) {
10344+ my $bogus = 1; # breakable point
10345+ }
10346+
10347 if (!$file && $maybecontinue) {
10348 if (/^\s*(.+)$/) {
10349 $text = $1;
10350@@ -94,7 +114,8 @@ foreach my $argv (@ARGV) {
10351 } else {
10352 $lasttext .= " $text";
10353 }
10354- $lasttext =~ s/^ //;
10355+ $lasttext =~ s/^ //; # get rid of leading spaces
10356+ $lasttext =~ s/^([a-z])/uc($1)/e; # capitalize the first letter
10357 $text = wrap(" - "," ","$lasttext") . "\n";
10358
10359 #
10360@@ -108,6 +129,7 @@ foreach my $argv (@ARGV) {
10361 $component =~ s/^snmp/0snmp/;
10362 $component =~ s/^agent/0snmpd/; # Merge "agent" into "snmpd"
10363 $component =~ s/^([A-Z])/zz\1/;
10364+ print STDERR " t:$file, $component, $patbug, $nums, $text\n" if ($opts{'d'} && /$opts{'d'}/o);
10365 push @{$output{$opts{'c'}}{$component}}, $text;
10366 push @{$output{$opts{'n'}}{$component}}, $text if ($file eq 'NEWS');
10367 $lastfile = $file;
10368diff --git a/dist/makerelease.xml b/dist/makerelease.xml
10369index 1d65e2c..758e889 100644
10370--- a/dist/makerelease.xml
10371+++ b/dist/makerelease.xml
10372@@ -33,6 +33,15 @@
10373 should be labeled ".rcN" like 5.4.1.rc1.
10374 </text>
10375 </step>
10376+ <step type="prompt" prompt="Enter the last version number:"
10377+ title="Enter the last version number"
10378+ parameter="LASTVERSION">
10379+ <text>
10380+ Please enter the last version number that the changelog should be
10381+ generated from. This should be easy for a new release on a branch,
10382+ but may be more tricky for a main release.
10383+ </text>
10384+ </step>
10385 <step type="perl" title="Defining a second internal version string"
10386 mandatory="1">
10387 <perl>
10388@@ -41,6 +50,9 @@
10389 $self->{'parameters'}{'VERSIONTAGNAME'} =
10390 "v" . $self->{'parameters'}{'VERSION'};
10391
10392+ $self->{'parameters'}{'LASTVERSIONTAGNAME'} =
10393+ "v" . $self->{'parameters'}{'LASTVERSION'};
10394+
10395 # target version number (without preN/rcN)
10396 $self->{'parameters'}{'VERSIONTARGET'} =
10397 $self->{'parameters'}{'VERSION'};
10398@@ -361,22 +373,19 @@
10399 <command>git commit -m "make depend for {VERSION}" `find . -name Makefile.depend`</command>
10400 </commands>
10401 </step>
10402- <step type="system" stepname="changelog:svn2cl" title="changelog:svn2cl">
10403+ <step type="system" stepname="changelog:create" title="Creating a changelog update">
10404 <text>We need to extract the portions of the change logs
10405 committed to the repository.</text>
10406- <!-- XXX: git2cl needs to be truncated quite a bit rather than searching the whole history -->
10407- <!-- XXX: following branches properly may prove to be interesting -->
10408 <commands>
10409- <command>git2cl | head -10000 &gt; ChangeLog.add</command>
10410- <command>perl dist/changelogfix &lt; ChangeLog.add &gt; ChangeLog.reallyadd</command>
10411+ <command>git log --no-merges {LASTVERSIONTAGNAME}..HEAD &gt; ChangeLog.add</command>
10412 </commands>
10413 </step>
10414 <step type="informational" pause="true" stepname="changelog:manualedit" title="changelog:manualedit">
10415 <text>
10416 You need to manually insert the *relevent* portions of
10417- 'ChangeLog.reallyadd' into the ChangeLog file.
10418+ 'ChangeLog.add' into the ChangeLog file.
10419
10420- I also suggest truncating ChangeLog.reallyadd to only contain
10421+ I also suggest truncating ChangeLog.add to only contain
10422 the *relevent* portions for this release, as this will make
10423 CHANGES.new2 and NEWS.new2 more accurate later on.
10424
10425@@ -396,7 +405,7 @@
10426 </step>
10427 <step type="system" stepname="docs:newnews" title="docs:newnews">
10428 <commands>
10429- <command>perl dist/extractnews -c CHANGES.new2 -n NEWS.new2 ChangeLog.reallyadd</command>
10430+ <command>perl dist/extractnews -c CHANGES.new2 -n NEWS.new2 ChangeLog.add</command>
10431 </commands>
10432 </step>
10433 <step type="informational" pause="true" stepname="docs:README-and-NEWS" title="docs:README">
10434diff --git a/dist/release b/dist/release
10435index 9e02b5c..52b45b1 100644
10436--- a/dist/release
10437+++ b/dist/release
10438@@ -4,4 +4,4 @@
10439 # a branch name followed by 'rc' when the branch is in rc phase of a release.
10440 #
10441 #master rc
10442-V5-7-patches rc
10443+#V5-7-patches rc
10444diff --git a/doxygen.conf b/doxygen.conf
10445index 6b5eb58..20e457d 100644
10446--- a/doxygen.conf
10447+++ b/doxygen.conf
10448@@ -280,7 +280,7 @@ WARNINGS = YES
10449 # for undocumented members. If EXTRACT_ALL is set to YES then this flag will
10450 # automatically be disabled.
10451
10452-WARN_IF_UNDOCUMENTED = YES
10453+WARN_IF_UNDOCUMENTED = NO
10454
10455 # The WARN_FORMAT tag determines the format of the warning messages that
10456 # doxygen can produce. The string should contain the $file, $line, and $text
10457diff --git a/include/net-snmp/agent/auto_nlist.h b/include/net-snmp/agent/auto_nlist.h
10458index c7cd872..21b6b8c 100644
10459--- a/include/net-snmp/agent/auto_nlist.h
10460+++ b/include/net-snmp/agent/auto_nlist.h
10461@@ -12,9 +12,9 @@ extern "C" {
10462 #endif
10463
10464 #ifdef NETSNMP_CAN_USE_NLIST
10465-int auto_nlist(const char *, char *, int);
10466+int auto_nlist(const char *, char *, size_t);
10467 long auto_nlist_value(const char *);
10468-int KNLookup(struct nlist *, int, char *, int);
10469+int KNLookup(struct nlist *, int, char *, size_t);
10470 #else
10471 int auto_nlist_noop(void);
10472 # define auto_nlist(x,y,z) auto_nlist_noop()
10473diff --git a/include/net-snmp/agent/hardware/cpu.h b/include/net-snmp/agent/hardware/cpu.h
10474index bc6f75b..f6e43e5 100644
10475--- a/include/net-snmp/agent/hardware/cpu.h
10476+++ b/include/net-snmp/agent/hardware/cpu.h
10477@@ -3,18 +3,18 @@ extern int cpu_num;
10478
10479 /* For rolling averages */
10480 struct netsnmp_cpu_history {
10481- long user_hist;
10482- long sys_hist;
10483- long idle_hist;
10484- long nice_hist;
10485- long total_hist;
10486+ unsigned long long user_hist;
10487+ unsigned long long sys_hist;
10488+ unsigned long long idle_hist;
10489+ unsigned long long nice_hist;
10490+ unsigned long long total_hist;
10491
10492- long ctx_hist;
10493- long intr_hist;
10494- long swpi_hist;
10495- long swpo_hist;
10496- long pagei_hist;
10497- long pageo_hist;
10498+ unsigned long long ctx_hist;
10499+ unsigned long long intr_hist;
10500+ unsigned long long swpi_hist;
10501+ unsigned long long swpo_hist;
10502+ unsigned long long pagei_hist;
10503+ unsigned long long pageo_hist;
10504 };
10505
10506 struct netsnmp_cpu_info_s {
10507@@ -25,30 +25,30 @@ struct netsnmp_cpu_info_s {
10508 int status;
10509
10510 /* For UCD cpu stats */
10511- long user_ticks;
10512- long nice_ticks;
10513- long sys_ticks;
10514- long idle_ticks;
10515- long wait_ticks;
10516- long kern_ticks;
10517- long intrpt_ticks;
10518- long sirq_ticks;
10519- long steal_ticks;
10520- long guest_ticks;
10521- long guestnice_ticks;
10522+ unsigned long long user_ticks;
10523+ unsigned long long nice_ticks;
10524+ unsigned long long sys_ticks;
10525+ unsigned long long idle_ticks;
10526+ unsigned long long wait_ticks;
10527+ unsigned long long kern_ticks;
10528+ unsigned long long intrpt_ticks;
10529+ unsigned long long sirq_ticks;
10530+ unsigned long long steal_ticks;
10531+ unsigned long long guest_ticks;
10532+ unsigned long long guestnice_ticks;
10533
10534- long total_ticks;
10535- long sys2_ticks; /* For non-atomic system counts */
10536+ unsigned long long total_ticks;
10537+ unsigned long long sys2_ticks; /* For non-atomic system counts */
10538
10539 /* For paging-related UCD stats */
10540 /* XXX - Do these belong elsewhere ?? */
10541 /* XXX - Do Not Use - Subject to Change */
10542- long pageIn;
10543- long pageOut;
10544- long swapIn;
10545- long swapOut;
10546- long nInterrupts;
10547- long nCtxSwitches;
10548+ unsigned long long pageIn;
10549+ unsigned long long pageOut;
10550+ unsigned long long swapIn;
10551+ unsigned long long swapOut;
10552+ unsigned long long nInterrupts;
10553+ unsigned long long nCtxSwitches;
10554
10555 struct netsnmp_cpu_history *history;
10556
10557diff --git a/include/net-snmp/agent/snmp_agent.h b/include/net-snmp/agent/snmp_agent.h
10558index 240ca94..aad8837 100644
10559--- a/include/net-snmp/agent/snmp_agent.h
10560+++ b/include/net-snmp/agent/snmp_agent.h
10561@@ -271,6 +271,7 @@ extern "C" {
10562 u_long netsnmp_marker_uptime(marker_t pm);
10563 u_long netsnmp_timeval_uptime(struct timeval *tv);
10564 const_marker_t netsnmp_get_agent_starttime(void);
10565+ uint64_t netsnmp_get_agent_runtime(void);
10566 void netsnmp_set_agent_starttime(marker_t s);
10567 u_long netsnmp_get_agent_uptime(void);
10568 void netsnmp_set_agent_uptime(u_long hsec);
10569diff --git a/include/net-snmp/library/default_store.h b/include/net-snmp/library/default_store.h
10570index e1b2e24..3c3c519 100644
10571--- a/include/net-snmp/library/default_store.h
10572+++ b/include/net-snmp/library/default_store.h
10573@@ -37,7 +37,8 @@ extern "C" {
10574 * begin storage definitions
10575 */
10576 /**
10577- * @def NETSNMP_DS_LIBRARY_ID These definitions correspond with the "storid" argument to the API
10578+ * @def NETSNMP_DS_LIBRARY_ID
10579+ * These definitions correspond with the "storid" argument to the API.
10580 */
10581 #define NETSNMP_DS_LIBRARY_ID 0
10582 #define NETSNMP_DS_APPLICATION_ID 1
10583diff --git a/include/net-snmp/library/large_fd_set.h b/include/net-snmp/library/large_fd_set.h
10584index 67a473c..9b547cd 100644
10585--- a/include/net-snmp/library/large_fd_set.h
10586+++ b/include/net-snmp/library/large_fd_set.h
10587@@ -16,7 +16,7 @@
10588 #include <sys/select.h>
10589 #endif
10590
10591-#if defined(HAVE_WINSOCK_H) && ! defined(_WINSOCKAPI_) && ! defined(_WINSOCK_H)
10592+#if defined(HAVE_WINSOCK_H) && !defined(_WINSOCKAPI_) && !defined(_WINSOCK_H)
10593 #error <winsock.h> or <winsock2.h> must have been included before this file.
10594 #endif
10595
10596@@ -44,15 +44,19 @@ extern "C" {
10597
10598 /**
10599 * Test whether set *fdset contains socket fd.
10600- * Do nothing if fd >= fdset->lfs_setsize.
10601+ * Evaluates to zero (false) if fd >= fdset->lfs_setsize.
10602 */
10603 #define NETSNMP_LARGE_FD_ISSET(fd, fdset) \
10604 netsnmp_large_fd_is_set(fd, fdset)
10605
10606-#if ! defined(cygwin) && defined(HAVE_WINSOCK_H)
10607+#if !defined(cygwin) && defined(HAVE_WINSOCK_H)
10608
10609-/** Number of bytes needed to store setsize file descriptors. */
10610-#define NETSNMP_FD_SET_BYTES(setsize) (sizeof(fd_set) + sizeof(SOCKET) * (setsize - FD_SETSIZE))
10611+/**
10612+ * Number of bytes needed to store a number of file descriptors as a
10613+ * struct fd_set.
10614+ */
10615+#define NETSNMP_FD_SET_BYTES(setsize) \
10616+ (sizeof(fd_set) + ((setsize) - FD_SETSIZE) * sizeof(SOCKET))
10617
10618 /** Remove all sockets from the set *fdset. */
10619 #define NETSNMP_LARGE_FD_ZERO(fdset) \
10620@@ -74,28 +78,29 @@ int netsnmp_large_fd_is_set(SOCKET fd, netsnmp_large_fd_set *fdset);
10621 * According to SUSv2, this array must have the name fds_bits. See also
10622 * <a href="http://www.opengroup.org/onlinepubs/007908775/xsh/systime.h.html">The Single UNIX Specification, Version 2, &lt;sys/time.h&gt;</a>.
10623 */
10624-#define NETSNMP_FD_MASK_SIZE sizeof(((fd_set*)0)->fds_bits)
10625+#define NETSNMP_FD_MASK_SIZE sizeof(((fd_set*)0)->fds_bits[0])
10626
10627-/** Number of bits in one element of the fd_set::fds_bits array. */
10628+/** Number of bits in one element of the fd_set.fds_bits array. */
10629 #define NETSNMP_BITS_PER_FD_MASK (8 * NETSNMP_FD_MASK_SIZE)
10630
10631 /** Number of elements needed for the fds_bits array. */
10632 #define NETSNMP_FD_SET_ELEM_COUNT(setsize) \
10633 (setsize + NETSNMP_BITS_PER_FD_MASK - 1) / NETSNMP_BITS_PER_FD_MASK
10634
10635-/** Number of bytes needed to store setsize file descriptors. */
10636-#define NETSNMP_FD_SET_BYTES(setsize) \
10637- (NETSNMP_FD_SET_ELEM_COUNT(setsize) * NETSNMP_FD_MASK_SIZE)
10638+/**
10639+ * Number of bytes needed to store a number of file descriptors as a
10640+ * struct fd_set.
10641+ */
10642+#define NETSNMP_FD_SET_BYTES(setsize) \
10643+ (sizeof(fd_set) + NETSNMP_FD_SET_ELEM_COUNT((setsize) - FD_SETSIZE) \
10644+ * NETSNMP_FD_MASK_SIZE)
10645
10646 /** Remove all file descriptors from the set *fdset. */
10647-#define NETSNMP_LARGE_FD_ZERO(fdset) \
10648- do { \
10649- int __i; \
10650- fd_set *__arr = &(fdset)->lfs_set; \
10651- __i = NETSNMP_FD_SET_ELEM_COUNT((fdset)->lfs_setsize); \
10652- for ( ; __i > 0; __i--) \
10653- __arr->fds_bits[__i - 1] = 0; \
10654- } while (0)
10655+#define NETSNMP_LARGE_FD_ZERO(fdset) \
10656+ do { \
10657+ memset((fdset)->lfs_setptr, 0, \
10658+ NETSNMP_FD_SET_BYTES((fdset)->lfs_setsize)); \
10659+ } while (0)
10660
10661
10662 void netsnmp_large_fd_setfd( int fd, netsnmp_large_fd_set *fdset);
10663@@ -118,8 +123,10 @@ void netsnmp_large_fd_set_init( netsnmp_large_fd_set *fdset, int setsize);
10664 /**
10665 * Modify the size of a file descriptor set and preserve the first
10666 * min(fdset->lfs_setsize, setsize) file descriptors.
10667+ *
10668+ * Returns 1 upon success or 0 if memory allocation failed.
10669 */
10670-void netsnmp_large_fd_set_resize( netsnmp_large_fd_set *fdset, int setsize);
10671+int netsnmp_large_fd_set_resize( netsnmp_large_fd_set *fdset, int setsize);
10672
10673 /**
10674 * Synchronous I/O multiplexing for large file descriptor sets.
10675diff --git a/include/net-snmp/library/oid.h b/include/net-snmp/library/oid.h
10676index 5468713..e7adf41 100644
10677--- a/include/net-snmp/library/oid.h
10678+++ b/include/net-snmp/library/oid.h
10679@@ -7,7 +7,7 @@
10680
10681 #ifndef EIGHTBIT_SUBIDS
10682 typedef u_long oid;
10683-#define MAX_SUBID 0xFFFFFFFF
10684+#define MAX_SUBID 0xFFFFFFFFUL
10685 #define NETSNMP_PRIo "l"
10686 #else
10687 typedef uint8_t oid;
10688diff --git a/include/net-snmp/library/snmp_alarm.h b/include/net-snmp/library/snmp_alarm.h
10689index 0fe2cf1..8437c1d 100644
10690--- a/include/net-snmp/library/snmp_alarm.h
10691+++ b/include/net-snmp/library/snmp_alarm.h
10692@@ -55,6 +55,8 @@ extern "C" {
10693 NETSNMP_IMPORT void run_alarms(void);
10694 RETSIGTYPE alarm_handler(int a);
10695 void set_an_alarm(void);
10696+ int netsnmp_get_next_alarm_time(struct timeval *alarm_tm,
10697+ const struct timeval *now);
10698 int get_next_alarm_delay_time(struct timeval *delta);
10699
10700
10701diff --git a/include/net-snmp/library/snmp_api.h b/include/net-snmp/library/snmp_api.h
10702index e32d62b..f57b678 100644
10703--- a/include/net-snmp/library/snmp_api.h
10704+++ b/include/net-snmp/library/snmp_api.h
10705@@ -418,7 +418,6 @@ typedef struct request_list {
10706 #endif
10707
10708 int create_user_from_session(netsnmp_session * session);
10709- int snmp_get_fd_for_session(struct snmp_session *sessp);
10710 int snmpv3_probe_contextEngineID_rfc5343(void *slp,
10711 netsnmp_session *session);
10712
10713diff --git a/include/net-snmp/library/snmp_enum.h b/include/net-snmp/library/snmp_enum.h
10714index 3ab470e..237891d 100644
10715--- a/include/net-snmp/library/snmp_enum.h
10716+++ b/include/net-snmp/library/snmp_enum.h
10717@@ -94,10 +94,11 @@ extern "C" {
10718 * Persistent enumeration lists
10719 */
10720 void se_store_enum_list(struct snmp_enum_list *new_list,
10721- const char *token, char *type);
10722- void se_store_list(unsigned int major, unsigned int minor, char *type);
10723+ const char *token, const char *type);
10724+ void se_store_list(unsigned int major, unsigned int minor,
10725+ const char *type);
10726 void se_clear_slist(const char *listname);
10727- void se_store_slist(const char *listname, char *type);
10728+ void se_store_slist(const char *listname, const char *type);
10729 int se_store_slist_callback(int majorID, int minorID,
10730 void *serverargs, void *clientargs);
10731 void se_read_conf(const char *word, char *cptr);
10732diff --git a/include/net-snmp/library/snmp_parse_args.h b/include/net-snmp/library/snmp_parse_args.h
10733index 384aff0..1ad63e0 100644
10734--- a/include/net-snmp/library/snmp_parse_args.h
10735+++ b/include/net-snmp/library/snmp_parse_args.h
10736@@ -1,8 +1,5 @@
10737 #ifndef SNMP_PARSE_ARGS_H
10738 #define SNMP_PARSE_ARGS_H
10739-#ifdef __cplusplus
10740-extern "C" {
10741-#endif
10742
10743 /**
10744 * @file snmp_parse_args.h
10745@@ -11,6 +8,10 @@ extern "C" {
10746 * line arguments
10747 */
10748
10749+#ifdef __cplusplus
10750+extern "C" {
10751+#endif
10752+
10753 /** Don't enable any logging even if there is no -L argument */
10754 #define NETSNMP_PARSE_ARGS_NOLOGGING 0x0001
10755 /** Don't zero out sensitive arguments as they are not on the command line
10756@@ -47,11 +48,12 @@ extern "C" {
10757 * from it.
10758 * @param argc Number of elements in argv
10759 * @param argv string array of at least argc elements
10760+ * @param session
10761 * @param localOpts Additional option characters to accept
10762 * @param proc function pointer used to process any unhandled arguments
10763 * @param flags flags directing how to handle the string
10764 *
10765- * @reval 0 (= #NETSNMP_PARSE_ARGS_SUCCESS) on success
10766+ * @retval 0 (= #NETSNMP_PARSE_ARGS_SUCCESS) on success
10767 * @retval #NETSNMP_PARSE_ARGS_SUCCESS_EXIT when the application is expected
10768 * to exit with zero exit code (e.g. '-V' option was found)
10769 * @retval #NETSNMP_PARSE_ARGS_ERROR_USAGE when the function failed to parse
10770diff --git a/include/net-snmp/library/system.h b/include/net-snmp/library/system.h
10771index 9ae1067..5c58e4a 100644
10772--- a/include/net-snmp/library/system.h
10773+++ b/include/net-snmp/library/system.h
10774@@ -194,6 +194,11 @@ SOFTWARE.
10775 NETSNMP_IMPORT
10776 size_t strlcpy(char *, const char *, size_t);
10777 #endif
10778+#ifndef HAVE_STRLCAT
10779+ NETSNMP_IMPORT
10780+ size_t strlcat(char * __restrict, const char * __restrict,
10781+ size_t);
10782+#endif
10783
10784 int netsnmp_os_prematch(const char *ospmname,
10785 const char *ospmrelprefix);
10786diff --git a/include/net-snmp/library/testing.h b/include/net-snmp/library/testing.h
10787index aabe52f..ec6135a 100644
10788--- a/include/net-snmp/library/testing.h
10789+++ b/include/net-snmp/library/testing.h
10790@@ -7,10 +7,10 @@
10791 static int __test_counter = 0;
10792 static int __did_plan = 0;
10793
10794-#define OK(isok, description) { printf("%s %d - %s\n", ((isok) ? "ok" : "not ok"), ++__test_counter, description); }
10795+#define OK(isok, description) do { printf("%s %d - %s\n", ((isok) ? "ok" : "not ok"), ++__test_counter, description); } while (0)
10796
10797-#define OKF(isok, description) { printf("%s %d - \n", ((isok) ? "ok" : "not ok"), ++__test_counter); printf description; printf("\n"); }
10798+#define OKF(isok, description) do { printf("%s %d - ", ((isok) ? "ok" : "not ok"), ++__test_counter); printf description; printf("\n"); } while (0)
10799
10800-#define PLAN(number) { printf("1..%d\n", number); __did_plan = 1;}
10801+#define PLAN(number) do { printf("1..%d\n", number); __did_plan = 1; } while (0)
10802
10803 #endif /* NETSNMP_LIBRARY_TESTING_H */
10804diff --git a/include/net-snmp/library/tools.h b/include/net-snmp/library/tools.h
10805index d3514b7..66415da 100644
10806--- a/include/net-snmp/library/tools.h
10807+++ b/include/net-snmp/library/tools.h
10808@@ -113,7 +113,7 @@ extern "C" {
10809 * Expands to string with value of the s.
10810 * If s is macro, the resulting string is value of the macro.
10811 * Example:
10812- * #define TEST 1234
10813+ * \#define TEST 1234
10814 * SNMP_MACRO_VAL_TO_STR(TEST) expands to "1234"
10815 * SNMP_MACRO_VAL_TO_STR(TEST+1) expands to "1234+1"
10816 */
10817@@ -286,8 +286,8 @@ extern "C" {
10818 NETSNMP_IMPORT
10819 u_long uatime_hdiff(const_marker_t first, const_marker_t second); /* 1/100th sec */
10820 NETSNMP_IMPORT
10821- int atime_ready(const_marker_t pm, int deltaT);
10822- int uatime_ready(const_marker_t pm, unsigned int deltaT);
10823+ int atime_ready(const_marker_t pm, int delta_ms);
10824+ int uatime_ready(const_marker_t pm, unsigned int delta_ms);
10825
10826 int marker_tticks(const_marker_t pm);
10827 int timeval_tticks(const struct timeval *tv);
10828diff --git a/include/net-snmp/net-snmp-config.h.in b/include/net-snmp/net-snmp-config.h.in
10829index d9b9d15..d6ef3ab 100644
10830--- a/include/net-snmp/net-snmp-config.h.in
10831+++ b/include/net-snmp/net-snmp-config.h.in
10832@@ -96,6 +96,9 @@
10833 /* Define to 1 if you have the <asm/types.h> header file. */
10834 #undef HAVE_ASM_TYPES_H
10835
10836+/* Define if using MY_INIT() causes a linker error */
10837+#undef HAVE_BROKEN_LIBMYSQLCLIENT
10838+
10839 /* Define to 1 if you have the `cgetnext' function. */
10840 #undef HAVE_CGETNEXT
10841
10842@@ -140,6 +143,12 @@
10843 /* Define to 1 if you have the `eval_pv' function. */
10844 #undef HAVE_EVAL_PV
10845
10846+/* Define to 1 if you have the `EVP_MD_CTX_create' function. */
10847+#undef HAVE_EVP_MD_CTX_CREATE
10848+
10849+/* Define to 1 if you have the `EVP_MD_CTX_destroy' function. */
10850+#undef HAVE_EVP_MD_CTX_DESTROY
10851+
10852 /* Define if you have EVP_sha224/256 in openssl */
10853 #undef HAVE_EVP_SHA224
10854
10855@@ -152,12 +161,21 @@
10856 /* Define to 1 if you have the <fcntl.h> header file. */
10857 #undef HAVE_FCNTL_H
10858
10859+/* Define to 1 if you have the `fgetc_unlocked' function. */
10860+#undef HAVE_FGETC_UNLOCKED
10861+
10862+/* Define to 1 if you have the `flockfile' function. */
10863+#undef HAVE_FLOCKFILE
10864+
10865 /* Define to 1 if you have the `fork' function. */
10866 #undef HAVE_FORK
10867
10868 /* Define to 1 if you have the <fstab.h> header file. */
10869 #undef HAVE_FSTAB_H
10870
10871+/* Define to 1 if you have the `funlockfile' function. */
10872+#undef HAVE_FUNLOCKFILE
10873+
10874 /* Define to 1 if you have the `gai_strerror' function. */
10875 #undef HAVE_GAI_STRERROR
10876
10877@@ -746,6 +764,9 @@
10878 /* Define to 1 if you have the <string.h> header file. */
10879 #undef HAVE_STRING_H
10880
10881+/* Define to 1 if you have the `strlcat' function. */
10882+#undef HAVE_STRLCAT
10883+
10884 /* Define to 1 if you have the `strlcpy' function. */
10885 #undef HAVE_STRLCPY
10886
10887@@ -773,6 +794,9 @@
10888 /* Define to 1 if `d_type' is a member of `struct dirent'. */
10889 #undef HAVE_STRUCT_DIRENT_D_TYPE
10890
10891+/* Define to 1 if `speed_hi' is a member of `struct ethtool_cmd'. */
10892+#undef HAVE_STRUCT_ETHTOOL_CMD_SPEED_HI
10893+
10894 /* Define to 1 if `ifa_next' is a member of `struct ifaddr'. */
10895 #undef HAVE_STRUCT_IFADDR_IFA_NEXT
10896
10897@@ -1166,6 +1190,9 @@
10898 /* Define to 1 if you have the `times' function. */
10899 #undef HAVE_TIMES
10900
10901+/* Define if a timezone variable is declared in <sys/time.h> */
10902+#undef HAVE_TIMEZONE_VARIABLE
10903+
10904 /* Define to 1 if you have the <ufs/ffs/fs.h> header file. */
10905 #undef HAVE_UFS_FFS_FS_H
10906
10907diff --git a/include/net-snmp/session_api.h b/include/net-snmp/session_api.h
10908index 9721fc4..88dbc41 100644
10909--- a/include/net-snmp/session_api.h
10910+++ b/include/net-snmp/session_api.h
10911@@ -147,12 +147,6 @@ extern "C" {
10912 int snmp_select_info2(int *, netsnmp_large_fd_set *,
10913 struct timeval *, int *);
10914
10915- /*
10916- * snmp_sess_select_info_flags() and
10917- * snmp_sess_select_info2_flags() is similar to
10918- * snmp_sess_select_info() and snmp_sess_select_info2(), but
10919- * accepts a list of flags to control aspects of its behavior.
10920- */
10921 #define NETSNMP_SELECT_NOFLAGS 0x00
10922 #define NETSNMP_SELECT_NOALARMS 0x01
10923 NETSNMP_IMPORT
10924diff --git a/include/net-snmp/system/netbsd.h b/include/net-snmp/system/netbsd.h
10925index c67260d..1f22a44 100644
10926--- a/include/net-snmp/system/netbsd.h
10927+++ b/include/net-snmp/system/netbsd.h
10928@@ -34,8 +34,36 @@
10929
10930 #define UDP_ADDRESSES_IN_HOST_ORDER 1
10931
10932+#ifdef netbsdelf6
10933+#define netbsd6
10934+#define netbsdelf5
10935+#endif
10936+#ifdef netbsdelf5
10937+#define netbsd5
10938+#define netbsdelf4
10939+#endif
10940+#ifdef netbsdelf4
10941+#define netbsd4
10942+#define netbsdelf3
10943+#endif
10944+#ifdef netbsdelf3
10945+#define netbsd3
10946+#endif
10947+
10948+#if defined(netbsd6) && !defined(netbsd5)
10949+#define netbsd5 netbsd5
10950+#endif
10951+#if defined(netbsd5) && !defined(netbsd4)
10952+#define netbsd4 netbsd4
10953+#endif
10954+#if defined(netbsd4) && !defined(netbsd3)
10955+#define netbsd3 netbsd3
10956+#endif
10957+#if defined(netbsd3) && !defined(netbsd2)
10958+#define netbsd2 netbsd2
10959+#endif
10960 #ifndef netbsd1
10961-# define netbsd1 netbsd1
10962+#define netbsd1 netbsd1
10963 #endif
10964
10965 #if __NetBSD_Version__ >= 499005800
10966diff --git a/local/mib2c.container.conf b/local/mib2c.container.conf
10967index c051b4c..e76621f 100644
10968--- a/local/mib2c.container.conf
10969+++ b/local/mib2c.container.conf
10970@@ -174,6 +174,7 @@ initialize_table_$i(void)
10971 */
10972 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
10973 snmp_log(LOG_ERR,"error registering table handler for $i\n");
10974+ reg = NULL; /* it was freed inside netsnmp_register_table */
10975 goto bail;
10976 }
10977
10978diff --git a/local/mib2c.notify.conf b/local/mib2c.notify.conf
10979index a8ee7e3..77f3330 100644
10980--- a/local/mib2c.notify.conf
10981+++ b/local/mib2c.notify.conf
10982@@ -30,7 +30,7 @@ int send_${i}_trap(void);
10983 #include <net-snmp/agent/net-snmp-agent-includes.h>
10984 #include "${name}.h"
10985
10986-extern const oid snmptrap_oid;
10987+extern const oid snmptrap_oid[];
10988 extern const size_t snmptrap_oid_len;
10989
10990 @foreach $i notifications@
10991diff --git a/local/mib2c.table_data.conf b/local/mib2c.table_data.conf
10992index d263914..2cc665c 100644
10993--- a/local/mib2c.table_data.conf
10994+++ b/local/mib2c.table_data.conf
10995@@ -348,6 +348,9 @@ ${i}_handler(
10996 */
10997 case MODE_GET:
10998 for (request=requests; request; request=request->next) {
10999+ if (request->processed)
11000+ continue;
11001+
11002 table_entry = (struct ${i}_entry *)
11003 netsnmp_tdata_extract_entry(request);
11004 table_info = netsnmp_extract_table_info( request);
11005@@ -386,6 +389,9 @@ ${i}_handler(
11006 */
11007 case MODE_SET_RESERVE1:
11008 for (request=requests; request; request=request->next) {
11009+ if (request->processed)
11010+ continue;
11011+
11012 table_entry = (struct ${i}_entry *)
11013 netsnmp_tdata_extract_entry(request);
11014 table_info = netsnmp_extract_table_info( request);
11015@@ -425,6 +431,9 @@ ${i}_handler(
11016 case MODE_SET_RESERVE2:
11017 @if $i.creatable@
11018 for (request=requests; request; request=request->next) {
11019+ if (request->processed)
11020+ continue;
11021+
11022 table_row = netsnmp_tdata_extract_row( request);
11023 table_data = netsnmp_tdata_extract_table(request);
11024 table_info = netsnmp_extract_table_info( request);
11025@@ -492,6 +501,9 @@ ${i}_handler(
11026 case MODE_SET_FREE:
11027 @if $i.creatable@
11028 for (request=requests; request; request=request->next) {
11029+ if (request->processed)
11030+ continue;
11031+
11032 table_entry = (struct ${i}_entry *)
11033 netsnmp_tdata_extract_entry(request);
11034 table_row = netsnmp_tdata_extract_row( request);
11035@@ -530,6 +542,9 @@ ${i}_handler(
11036
11037 case MODE_SET_ACTION:
11038 for (request=requests; request; request=request->next) {
11039+ if (request->processed)
11040+ continue;
11041+
11042 table_entry = (struct ${i}_entry *)
11043 netsnmp_tdata_extract_entry(request);
11044 table_info = netsnmp_extract_table_info( request);
11045@@ -591,6 +606,9 @@ ${i}_handler(
11046
11047 case MODE_SET_UNDO:
11048 for (request=requests; request; request=request->next) {
11049+ if (request->processed)
11050+ continue;
11051+
11052 table_entry = (struct ${i}_entry *)
11053 netsnmp_tdata_extract_entry(request);
11054 table_row = netsnmp_tdata_extract_row( request);
11055@@ -667,6 +685,9 @@ ${i}_handler(
11056 case MODE_SET_COMMIT:
11057 @if $i.creatable@
11058 for (request=requests; request; request=request->next) {
11059+ if (request->processed)
11060+ continue;
11061+
11062 table_entry = (struct ${i}_entry *)
11063 netsnmp_tdata_extract_entry(request);
11064 @if $i.rowstatus@
11065diff --git a/local/pass_persisttest b/local/pass_persisttest
11066index 4f37c11..f4045cc 100755
11067--- a/local/pass_persisttest
11068+++ b/local/pass_persisttest
11069@@ -5,17 +5,23 @@
11070 # put the following in your snmpd.conf file to call this script:
11071 #
11072 # Unix systems and Cygwin:
11073-# pass_persist .1.3.6.1.4.1.2021.255 /path/to/pass_persisttest
11074+# pass_persist .1.3.6.1.4.1.8072.2.255 /path/to/pass_persisttest
11075 # Windows systems except Cygwin:
11076-# pass_persist .1.3.6.1.4.1.2021.255 perl /path/to/pass_persisttest
11077+# pass_persist .1.3.6.1.4.1.8072.2.255 perl /path/to/pass_persisttest
11078
11079 # Forces a buffer flush after every print
11080 $|=1;
11081
11082+# Save my PID, to help kill this instance.
11083+$PIDFILE=$ENV{'PASS_PERSIST_PIDFILE'} || "/tmp/pass_persist.pid";
11084+open(PIDFILE, ">$PIDFILE");
11085+print PIDFILE "$$\n";
11086+close(PIDFILE);
11087+
11088 use strict;
11089
11090 my $counter = 0;
11091-my $place = ".1.3.6.1.4.1.2021.255";
11092+my $place = ".1.3.6.1.4.1.8072.2.255";
11093
11094 while (<>){
11095 if (m!^PING!){
11096@@ -30,21 +36,33 @@ while (<>){
11097 chomp($req);
11098
11099 if ( $cmd eq "getnext" ) {
11100- if ($req eq $place) {
11101- $ret = "$place.1";
11102- } elsif ($req eq "$place.1") {
11103- $ret = "$place.2.1";
11104- } elsif ($req eq "$place.2.1") {
11105- $ret = "$place.2.2";
11106- } elsif ($req eq "$place.2.2") {
11107- $ret = "$place.3";
11108- } elsif ($req eq "$place.3") {
11109- $ret = "$place.4";
11110- } elsif ($req eq "$place.4") {
11111- $ret = "$place.5";
11112- } elsif ($req eq "$place.5") {
11113- $ret = "$place.6";
11114- } else {
11115+ if (($req eq "$place") ||
11116+ ($req eq "$place.0") ||
11117+ ($req =~ m/$place\.0\..*/) ||
11118+ ($req eq "$place.1")) { $ret = "$place.1.0";} # netSnmpPassString.0
11119+ elsif (($req =~ m/$place\.1\..*/) ||
11120+ ($req eq "$place.2") ||
11121+ ($req eq "$place.2.0") ||
11122+ ($req =~ m/$place\.2\.0\..*/) ||
11123+ ($req eq "$place.2.1") ||
11124+ ($req eq "$place.2.1.0") ||
11125+ ($req =~ m/$place\.2\.1\.0\..*/) ||
11126+ ($req eq "$place.2.1.1") ||
11127+ ($req =~ m/$place\.2\.1\.1\..*/) ||
11128+ ($req eq "$place.2.1.2") ||
11129+ ($req eq "$place.2.1.2.0")) { $ret = "$place.2.1.2.1";} # netSnmpPassInteger.1
11130+ elsif (($req =~ m/$place\.2\.1\.2\..*/) ||
11131+ ($req eq "$place.2.1.3") ||
11132+ ($req eq "$place.2.1.3.0")) { $ret = "$place.2.1.3.1";} # netSnmpPassOID.1
11133+ elsif (($req =~ m/$place\.2\..*/) ||
11134+ ($req eq "$place.3")) { $ret = "$place.3.0";} # netSnmpPassTimeTicks.0
11135+ elsif (($req =~ m/$place\.3\..*/) ||
11136+ ($req eq "$place.4")) { $ret = "$place.4.0";} # netSnmpPassIpAddress.0
11137+ elsif (($req =~ m/$place\.4\..*/) ||
11138+ ($req eq "$place.5")) { $ret = "$place.5.0";} # netSnmpPassCounter.0
11139+ elsif (($req =~ m/$place\.5\..*/) ||
11140+ ($req eq "$place.6")) { $ret = "$place.6.0";} # netSnmpPassGauge.0
11141+ else {
11142 print "NONE\n";
11143 next;
11144 }
11145@@ -59,20 +77,20 @@ while (<>){
11146
11147 print "$ret\n";
11148
11149- if ($ret eq "$place.1") {
11150- print "string\nlife the universe and everything\n";
11151- } elsif ($ret eq "$place.2.1") {
11152- print "integer\n423\n";
11153- } elsif ($ret eq "$place.2.2") {
11154- print "objectid\n.1.3.6.1.4.42.42.42\n";
11155- } elsif ($ret eq "$place.3") {
11156+ if ($ret eq "$place.1.0") {
11157+ print "string\nLife, the Universe, and Everything\n";
11158+ } elsif ($ret eq "$place.2.1.2.1") {
11159+ print "integer\n42\n";
11160+ } elsif ($ret eq "$place.2.1.3.1") {
11161+ print "objectid\n$place.99\n";
11162+ } elsif ($ret eq "$place.3.0") {
11163 print "timeticks\n363136200\n";
11164- } elsif ($ret eq "$place.4") {
11165+ } elsif ($ret eq "$place.4.0") {
11166 print "ipaddress\n127.0.0.1\n";
11167- } elsif ($ret eq "$place.5") {
11168+ } elsif ($ret eq "$place.5.0") {
11169 $counter++;
11170 print "counter\n$counter\n";
11171- } elsif ($ret eq "$place.6") {
11172+ } elsif ($ret eq "$place.6.0") {
11173 print "gauge\n42\n";
11174 } else {
11175 print "string\nack... $ret $req\n";
11176diff --git a/local/passtest b/local/passtest
11177index dc5735c..40209c9 100755
11178--- a/local/passtest
11179+++ b/local/passtest
11180@@ -1,7 +1,5 @@
11181 #!/bin/sh -f
11182
11183-PATH=$path:/bin:/usr/bin:/usr/ucb
11184-
11185 PLACE=".1.3.6.1.4.1.8072.2.255" # NET-SNMP-PASS-MIB::netSnmpPassExamples
11186 REQ="$2" # Requested OID
11187
11188@@ -20,34 +18,34 @@ fi
11189 #
11190 if [ "$1" = "-n" ]; then
11191 case "$REQ" in
11192- $PLACE|
11193- $PLACE.0|
11194- $PLACE.0.*|
11195+ $PLACE| \
11196+ $PLACE.0| \
11197+ $PLACE.0.*| \
11198 $PLACE.1) RET=$PLACE.1.0 ;; # netSnmpPassString.0
11199
11200- $PLACE.1.*|
11201- $PLACE.2|
11202- $PLACE.2.0|
11203- $PLACE.2.0.*|
11204- $PLACE.2.1|
11205- $PLACE.2.1.0|
11206- $PLACE.2.1.0.*|
11207- $PLACE.2.1.1|
11208- $PLACE.2.1.1.*|
11209- $PLACE.2.1.2|
11210+ $PLACE.1.*| \
11211+ $PLACE.2| \
11212+ $PLACE.2.0| \
11213+ $PLACE.2.0.*| \
11214+ $PLACE.2.1| \
11215+ $PLACE.2.1.0| \
11216+ $PLACE.2.1.0.*| \
11217+ $PLACE.2.1.1| \
11218+ $PLACE.2.1.1.*| \
11219+ $PLACE.2.1.2| \
11220 $PLACE.2.1.2.0) RET=$PLACE.2.1.2.1 ;; # netSnmpPassInteger.1
11221
11222- $PLACE.2.1.2.*|
11223- $PLACE.2.1.3|
11224+ $PLACE.2.1.2.*| \
11225+ $PLACE.2.1.3| \
11226 $PLACE.2.1.3.0) RET=$PLACE.2.1.3.1 ;; # netSnmpPassOID.1
11227
11228- $PLACE.2.*|
11229+ $PLACE.2.*| \
11230 $PLACE.3) RET=$PLACE.3.0 ;; # netSnmpPassTimeTicks.0
11231- $PLACE.3.*|
11232+ $PLACE.3.*| \
11233 $PLACE.4) RET=$PLACE.4.0 ;; # netSnmpPassIpAddress.0
11234- $PLACE.4.*|
11235+ $PLACE.4.*| \
11236 $PLACE.5) RET=$PLACE.5.0 ;; # netSnmpPassCounter.0
11237- $PLACE.5.*|
11238+ $PLACE.5.*| \
11239 $PLACE.6) RET=$PLACE.6.0 ;; # netSnmpPassGauge.0
11240
11241 *) exit 0 ;;
11242@@ -57,12 +55,12 @@ else
11243 # GET requests - check for valid instance
11244 #
11245 case "$REQ" in
11246- $PLACE.1.0|
11247- $PLACE.2.1.2.1|
11248- $PLACE.2.1.3.1|
11249- $PLACE.3.0|
11250- $PLACE.4.0|
11251- $PLACE.5.0|
11252+ $PLACE.1.0| \
11253+ $PLACE.2.1.2.1| \
11254+ $PLACE.2.1.3.1| \
11255+ $PLACE.3.0| \
11256+ $PLACE.4.0| \
11257+ $PLACE.5.0| \
11258 $PLACE.6.0) RET=$REQ ;;
11259 *) exit 0 ;;
11260 esac
11261diff --git a/local/passtest.pl b/local/passtest.pl
11262index 049cf45..c87fe18 100755
11263--- a/local/passtest.pl
11264+++ b/local/passtest.pl
11265@@ -66,7 +66,7 @@ else {
11266 print "$ret\n";
11267 if ($ret eq "$place.1.0") { print "string\nLife, the Universe, and Everything\n"; exit 0;}
11268 elsif ($ret eq "$place.2.1.2.1") { print "integer\n42\n"; exit 0;}
11269-elsif ($ret eq "$place.2.1.3.1") { print "objectid\n.1.3.6.1.4.42.42.42\n"; exit 0;}
11270+elsif ($ret eq "$place.2.1.3.1") { print "objectid\n$place.99\n"; exit 0;}
11271 elsif ($ret eq "$place.3.0") { print "timeticks\n363136200\n"; exit 0;}
11272 elsif ($ret eq "$place.4.0") { print "ipaddress\n127.0.0.1\n"; exit 0;}
11273 elsif ($ret eq "$place.5.0") { print "counter\n42\n"; exit 0;}
11274diff --git a/local/snmp-bridge-mib b/local/snmp-bridge-mib
11275index a4c2c80..4a9415e 100644
11276--- a/local/snmp-bridge-mib
11277+++ b/local/snmp-bridge-mib
11278@@ -1004,7 +1004,7 @@ sub readindexes()
11279 next if $if eq "..";
11280
11281 my $port=hex(readfile($brifdir.$if."/port_no", 0));
11282- my $index=readfile($netdir.$if."/ifindex", STP_PROP_HEX);
11283+ my $index=readfile($netdir.$if."/ifindex", 0);
11284
11285 $indexes{$bridge}{$port}=$index;
11286 $interfaces{$bridge}{$port}=$if;
11287@@ -1063,17 +1063,16 @@ sub tracevlan{
11288 my $pif=$1;
11289 $brifdir=$netdir.$pif."/brport/bridge/brif/";
11290 $port=hex(readfile($brifdir.$pif."/port_no", 0));
11291- $index=readfile($netdir.$pif."/ifindex", STP_PROP_HEX);
11292+ $index=readfile($netdir.$pif."/ifindex", 0);
11293 #$indexes{$bridge}{$port}=$index;
11294 #$interfaces{$bridge}{$port}=$if;
11295 $tagged{$vlan}{$port}=1;
11296 }else{
11297- my $brid=readfile($netdir.$if."/brport/bridge/ifindex",
11298- STP_PROP_HEX);
11299+ my $brid=readfile($netdir.$if."/brport/bridge/ifindex", 0);
11300 $brifdir=$netdir.$if."/brport/bridge/brif/";
11301 $port=hex(readfile($brifdir.$if."/port_no", 0));
11302 $port=$brid*1000+$port; #create a unique port number
11303- $index=readfile($netdir.$if."/ifindex", STP_PROP_HEX);
11304+ $index=readfile($netdir.$if."/ifindex", 0);
11305 $indexes{$bridge}{$port}=$index;
11306 $interfaces{$bridge}{$port}=$if;
11307 $tagged{$vlan}{$port}=0;
11308@@ -1083,8 +1082,7 @@ sub tracevlan{
11309 }
11310 close(DIR);
11311
11312- my $brid=readfile($netdir.$interface."/brport/bridge/ifindex",
11313- STP_PROP_HEX);
11314+ my $brid=readfile($netdir.$interface."/brport/bridge/ifindex", 0);
11315 my $fdb=$netdir.$interface."/brport/bridge/brforward";
11316
11317 my $vbridge=$bridge."_vlan".$vlan;
11318diff --git a/man/Makefile.in b/man/Makefile.in
11319index bfe8279..5627cc0 100644
11320--- a/man/Makefile.in
11321+++ b/man/Makefile.in
11322@@ -26,6 +26,8 @@ MAN1G = $(AGENTXTRAP) snmpbulkget.1 snmpcmd.1 snmpget.1 snmpset.1 snmpwalk.1 \
11323 net-snmp-config.1 mib2c-update.1 tkmib.1 traptoemail.1 \
11324 net-snmp-create-v3-user.1
11325
11326+# If MAN3 is populated again, then remember to re-enable the corresponding
11327+# action line within the 'maninstall' target
11328 MAN3 =
11329 MAN3_API = netsnmp_mib_api.3 netsnmp_config_api.3 snmp_alarm.3 \
11330 netsnmp_session_api.3 netsnmp_sess_api.3 netsnmp_trap_api.3 netsnmp_varbind_api.3 netsnmp_pdu_api.3
11331@@ -241,7 +243,7 @@ maninstall: maninstalldirs $(MAN1) $(MAN1G) $(MAN3) $(MAN5G) $(MAN8) $(MANALIAS
11332 @for i in $(MAN1) ; do $(INSTALL_DATA) $(srcdir)/$$i $(INSTALL_PREFIX)$(man1dir) ; echo "install: installed $$i in $(INSTALL_PREFIX)$(man1dir)" ; done
11333 @$(INSTALL_DATA) $(MAN1G) $(INSTALL_PREFIX)$(man1dir)
11334 @for i in $(MAN1G) ; do echo "install: installed $$i in $(INSTALL_PREFIX)$(man1dir)" ; done
11335- @for i in $(MAN3) ; do $(INSTALL_DATA) $(srcdir)/$$i $(INSTALL_PREFIX)$(man3dir) ; echo "install: installed $$i in $(INSTALL_PREFIX)$(man3dir)" ; done
11336+ #EMPTY LIST#@for i in $(MAN3) ; do $(INSTALL_DATA) $(srcdir)/$$i $(INSTALL_PREFIX)$(man3dir) ; echo "install: installed $$i in $(INSTALL_PREFIX)$(man3dir)" ; done
11337 @$(INSTALL_DATA) $(MAN3G) $(INSTALL_PREFIX)$(man3dir)
11338 @for i in $(MAN3G) ; do echo "install: installed $$i in $(INSTALL_PREFIX)$(man3dir)" ; done
11339 @$(INSTALL_DATA) $(MANALIASES) $(INSTALL_PREFIX)$(man3dir)
11340diff --git a/mibs/IANA-RTPROTO-MIB.txt b/mibs/IANA-RTPROTO-MIB.txt
11341index 6f04143..f50992e 100644
11342--- a/mibs/IANA-RTPROTO-MIB.txt
11343+++ b/mibs/IANA-RTPROTO-MIB.txt
11344@@ -5,7 +5,7 @@ IMPORTS
11345 TEXTUAL-CONVENTION FROM SNMPv2-TC;
11346
11347 ianaRtProtoMIB MODULE-IDENTITY
11348- LAST-UPDATED "200009260000Z" -- September 26, 2000
11349+ LAST-UPDATED "201107220000Z" -- July 22, 2011
11350 ORGANIZATION "IANA"
11351 CONTACT-INFO
11352 " Internet Assigned Numbers Authority
11353@@ -28,6 +28,9 @@ ianaRtProtoMIB MODULE-IDENTITY
11354 will be selected by the IESG Area Director(s) of the Routing
11355 Area."
11356
11357+ REVISION "201107220000Z" -- July 22, 2011
11358+ DESCRIPTION "Added rpl(18) ."
11359+
11360 REVISION "200009260000Z" -- September 26, 2000
11361 DESCRIPTION "Original version, published in coordination
11362 with RFC 2932."
11363@@ -60,7 +63,8 @@ IANAipRouteProtocol ::= TEXTUAL-CONVENTION
11364 bgp (14), -- Border Gateway Protocol
11365 idpr (15), -- InterDomain Policy Routing
11366 ciscoEigrp (16), -- Cisco EIGRP
11367- dvmrp (17) -- DVMRP
11368+ dvmrp (17), -- DVMRP
11369+ rpl (18) -- RPL [RFC-ietf-roll-rpl-19]
11370 }
11371
11372 IANAipMRouteProtocol ::= TEXTUAL-CONVENTION
11373diff --git a/mibs/IANAifType-MIB.txt b/mibs/IANAifType-MIB.txt
11374index 856156a..896adc8 100644
11375--- a/mibs/IANAifType-MIB.txt
11376+++ b/mibs/IANAifType-MIB.txt
11377@@ -5,7 +5,7 @@
11378 TEXTUAL-CONVENTION FROM SNMPv2-TC;
11379
11380 ianaifType MODULE-IDENTITY
11381- LAST-UPDATED "201002110000Z" -- February 11, 2010
11382+ LAST-UPDATED "201110260000Z" -- October 26, 2011
11383 ORGANIZATION "IANA"
11384 CONTACT-INFO " Internet Assigned Numbers Authority
11385
11386@@ -19,6 +19,24 @@
11387 Convention, and thus the enumerated values of
11388 the ifType object defined in MIB-II's ifTable."
11389
11390+ REVISION "201110260000Z" -- October 26, 2011
11391+ DESCRIPTION "Registration of new IANAifType 262."
11392+
11393+ REVISION "201109070000Z" -- September 7, 2011
11394+ DESCRIPTION "Registration of new IANAifTypes 260 and 261."
11395+
11396+ REVISION "201107220000Z" -- July 22, 2011
11397+ DESCRIPTION "Registration of new IANAifType 259."
11398+
11399+ REVISION "201106030000Z" -- June 03, 2011
11400+ DESCRIPTION "Registration of new IANAifType 258."
11401+
11402+ REVISION "201009210000Z" -- September 21, 2010
11403+ DESCRIPTION "Registration of new IANAifTypes 256 and 257."
11404+
11405+ REVISION "201007210000Z" -- July 21, 2010
11406+ DESCRIPTION "Registration of new IANAifType 255."
11407+
11408 REVISION "201002110000Z" -- February 11, 2010
11409 DESCRIPTION "Registration of new IANAifType 254."
11410
11411@@ -334,7 +352,7 @@
11412 ieee80212(55), -- 100BaseVG
11413 fibreChannel(56), -- Fibre Channel
11414 hippiInterface(57), -- HIPPI interfaces
11415- frameRelayInterconnect(58), -- Obsolete use either
11416+ frameRelayInterconnect(58), -- Obsolete, use either
11417 -- frameRelay(32) or
11418 -- frameRelayService(44).
11419 aflane8023(59), -- ATM Emulated LAN for 802.3
11420@@ -541,7 +559,15 @@
11421 vdsl2 (251), -- Very high speed digital subscriber line Version 2 (as per ITU-T Recommendation G.993.2)
11422 capwapDot11Profile (252), -- WLAN Profile Interface
11423 capwapDot11Bss (253), -- WLAN BSS Interface
11424- capwapWtpVirtualRadio (254) -- WTP Virtual Radio Interface
11425+ capwapWtpVirtualRadio (254), -- WTP Virtual Radio Interface
11426+ bits (255), -- bitsport
11427+ docsCableUpstreamRfPort (256), -- DOCSIS CATV Upstream RF Port
11428+ cableDownstreamRfPort (257), -- CATV downstream RF port
11429+ vmwareVirtualNic (258), -- VMware Virtual Network Interface
11430+ ieee802154 (259), -- IEEE 802.15.4 WPAN interface
11431+ otnOdu (260), -- OTN Optical Data Unit
11432+ otnOtu (261), -- OTN Optical channel Transport Unit
11433+ ifVfiType (262) -- VPLS Forwarding Instance Interface Type
11434 }
11435
11436 IANAtunnelType ::= TEXTUAL-CONVENTION
11437diff --git a/mibs/rfclist b/mibs/rfclist
11438index 7f84150..35f301e 100644
11439--- a/mibs/rfclist
11440+++ b/mibs/rfclist
11441@@ -1,4 +1,4 @@
11442-# updated 2011-03-14
11443+# updated 2011-11-16
11444 1155 RFC1155-SMI
11445 1213 RFC1213-MIB
11446 1227 SMUX-MIB
11447@@ -254,6 +254,9 @@
11448 5833 CAPWAP-BASE-MIB
11449 5834 CAPWAP-DOT11-MIB
11450 5907 NTPv4-MIB
11451-5953 SNMP-TLS-TM-MIB
11452 6065 SNMP-VACM-AAA-MIB
11453 6173 IFCP-MGMT-MIB
11454+6240 PW-CEP-STD-MIB
11455+6340 FLOAT-TC-MIB
11456+6353 SNMP-TLS-TM-MIB
11457+6445 MPLS-FRR-GENERAL-STD-MIB:MPLS-FRR-ONE2ONE-STD-MIB:MPLS-FRR-FACILITY-STD-MIB
11458diff --git a/net-snmp-config.in b/net-snmp-config.in
11459index 303cdda..3ba60e3 100644
11460--- a/net-snmp-config.in
11461+++ b/net-snmp-config.in
11462@@ -194,7 +194,7 @@ else
11463 echo $NSC_LIBDIR $NSC_BASE_SNMP_LIBS
11464 ;;
11465 --external-libs)
11466- echo $NSC_LDFLAGS $NSC_LNETSNMPLIBS $NSC_LIBS
11467+ echo $NSC_LDFLAGS $NSC_LNETSNMPLIBS $NSC_LIBS @PERLLDOPTS_FOR_APPS@
11468 ;;
11469 #################################################### agent lib
11470 --base-agent-libs)
11471diff --git a/perl/ASN/ASN.pm b/perl/ASN/ASN.pm
11472index 3961bd5..4195573 100644
11473--- a/perl/ASN/ASN.pm
11474+++ b/perl/ASN/ASN.pm
11475@@ -77,7 +77,7 @@ sub AUTOLOAD {
11476 ($constname = $AUTOLOAD) =~ s/.*:://;
11477 croak "& not defined" if $constname eq 'constant';
11478 my $val;
11479- ($!, $val) = constant($constname, @_ ? $_[0] : 0);
11480+ ($!, $val) = constant($constname);
11481 if ($! != 0) {
11482 if ($! =~ /Invalid/ || $!{EINVAL}) {
11483 $AutoLoader::AUTOLOAD = $AUTOLOAD;
11484diff --git a/perl/ASN/ASN.xs b/perl/ASN/ASN.xs
11485index bbfa69b..e3f6181 100644
11486--- a/perl/ASN/ASN.xs
11487+++ b/perl/ASN/ASN.xs
11488@@ -78,9 +78,11 @@ static int constant_ASN_U(double *value, const char *name, const int len)
11489 case '\0':
11490 TEST_CONSTANT(value, name, ASN_UNSIGNED);
11491 break;
11492+#ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
11493 case '6':
11494 TEST_CONSTANT(value, name, ASN_UNSIGNED64);
11495 break;
11496+#endif
11497 }
11498 return EINVAL;
11499 }
11500@@ -91,9 +93,11 @@ static int constant_ASN_IN(double *value, const char *name, const int len)
11501 case '\0':
11502 TEST_CONSTANT(value, name, ASN_INTEGER);
11503 break;
11504+#ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
11505 case '6':
11506 TEST_CONSTANT(value, name, ASN_INTEGER64);
11507 break;
11508+#endif
11509 }
11510 return EINVAL;
11511 }
11512@@ -123,12 +127,14 @@ static int constant(double *value, const char *const name, const int len)
11513 return constant_ASN_B(value, name, len);
11514 case 'C':
11515 return constant_ASN_C(value, name, len);
11516+#ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
11517 case 'D':
11518 TEST_CONSTANT(value, name, ASN_DOUBLE);
11519 break;
11520 case 'F':
11521 TEST_CONSTANT(value, name, ASN_FLOAT);
11522 break;
11523+#endif
11524 case 'G':
11525 TEST_CONSTANT(value, name, ASN_GAUGE);
11526 break;
11527@@ -155,13 +161,12 @@ MODULE = NetSNMP::ASN PACKAGE = NetSNMP::ASN
11528
11529
11530 void
11531-constant(sv,arg)
11532+constant(sv)
11533 PREINIT:
11534 STRLEN len;
11535 INPUT:
11536 SV * sv
11537 char * s = SvPV(sv, len);
11538- int arg
11539 INIT:
11540 int status;
11541 double value;
11542diff --git a/perl/OID/OID.pm b/perl/OID/OID.pm
11543index 3ab12aa..a9d9369 100644
11544--- a/perl/OID/OID.pm
11545+++ b/perl/OID/OID.pm
11546@@ -153,7 +153,7 @@ sub AUTOLOAD {
11547 ($constname = $AUTOLOAD) =~ s/.*:://;
11548 croak "& not defined" if $constname eq 'constant';
11549 my $val;
11550- ($!, $val) = constant($constname, @_ ? $_[0] : 0);
11551+ ($!, $val) = constant($constname);
11552 if ($! != 0) {
11553 if ($! =~ /Invalid/ || $!{EINVAL}) {
11554 $AutoLoader::AUTOLOAD = $AUTOLOAD;
11555diff --git a/perl/OID/OID.xs b/perl/OID/OID.xs
11556index ff3693e..10485f9 100644
11557--- a/perl/OID/OID.xs
11558+++ b/perl/OID/OID.xs
11559@@ -125,7 +125,7 @@ int flag;
11560 break;
11561
11562 case ASN_BIT_STR:
11563- snprint_bitstring(buf, sizeof(buf), var, NULL, NULL, NULL);
11564+ snprint_bitstring(buf, buf_len, var, NULL, NULL, NULL);
11565 len = strlen(buf);
11566 break;
11567
11568@@ -173,13 +173,12 @@ nso_newptr(initstring)
11569 RETVAL
11570
11571 void
11572-constant(sv,arg)
11573+constant(sv)
11574 PREINIT:
11575 STRLEN len;
11576 INPUT:
11577 SV * sv
11578 char * s = SvPV(sv, len);
11579- int arg
11580 INIT:
11581 int status;
11582 double value;
11583diff --git a/perl/SNMP/SNMP.pm b/perl/SNMP/SNMP.pm
11584index d1b39c3..a7f6faa 100644
11585--- a/perl/SNMP/SNMP.pm
11586+++ b/perl/SNMP/SNMP.pm
11587@@ -135,6 +135,12 @@ $replace_newer = 0; # determine whether or not to tell the parser to replace
11588 # older MIB modules with newer ones when loading MIBs.
11589 # WARNING: This can cause an incorrect hierarchy.
11590
11591+sub register_debug_tokens {
11592+ my $tokens = shift;
11593+
11594+ SNMP::_register_debug_tokens($tokens);
11595+}
11596+
11597 sub getenv {
11598 my $name = shift;
11599
11600@@ -161,10 +167,10 @@ sub setMib {
11601 }
11602
11603 sub initMib {
11604-# eqivalent to calling the snmp library init_mib if Mib is NULL
11605+# equivalent to calling the snmp library init_mib if Mib is NULL
11606 # if Mib is already loaded this function does nothing
11607-# Pass a zero valued argument to get minimal mib tree initialzation
11608-# If non zero agrgument or no argument then full mib initialization
11609+# Pass a zero valued argument to get minimal mib tree initialization
11610+# If non zero argument or no argument then full mib initialization
11611
11612 SNMP::init_snmp("perl");
11613 return;
11614@@ -1529,7 +1535,7 @@ init_snmp properly, which means it will read configuration files and
11615 use those defaults where appropriate automatically parse MIB files,
11616 etc. This will likely affect your perl applications if you have, for
11617 instance, default values set up in your snmp.conf file (as the perl
11618-module will now make use of those defaults). The docmuentation,
11619+module will now make use of those defaults). The documentation,
11620 however, has sadly not been updated yet (aside from this note), nor is
11621 the read_config default usage implementation fully complete.
11622
11623@@ -1540,7 +1546,7 @@ aspects of a connection between the management application and the
11624 managed agent. Internally the class is implemented as a blessed hash
11625 reference. This class supplies 'get', 'getnext', 'set', 'fget', and
11626 'fgetnext' method calls. The methods take a variety of input argument
11627-formats and support both syncronous and asyncronous operation through
11628+formats and support both synchronous and asynchronous operation through
11629 a polymorphic API (i.e., method behaviour varies dependent on args
11630 passed - see below).
11631
11632@@ -1835,7 +1841,7 @@ do SNMP GET, multiple <vars> formats accepted.
11633 for syncronous operation <vars> will be updated
11634 with value(s) and type(s) and will also return
11635 retrieved value(s). If <callback> supplied method
11636-will operate asyncronously
11637+will operate asynchronously
11638
11639 =item $sess->fget(E<lt>varsE<gt> [,E<lt>callbackE<gt>])
11640
11641@@ -1852,7 +1858,7 @@ and <type>
11642
11643 Note: simple string <vars>,(e.g., 'sysDescr.0')
11644 form is not updated. If <callback> supplied method
11645-will operate asyncronously
11646+will operate asynchronously
11647
11648 =item $sess->fgetnext(E<lt>varsE<gt> [,E<lt>callbackE<gt>])
11649
11650@@ -1868,7 +1874,7 @@ format (i.e., well known format) to ensure unambiguous
11651 translation to SNMP MIB data value (see discussion of
11652 canonical value format <vars> description section),
11653 returns snmp_errno. If <callback> supplied method
11654-will operate asyncronously
11655+will operate asynchronously
11656
11657 =item $sess->getbulk(E<lt>non-repeatersE<gt>, E<lt>max-repeatersE<gt>, E<lt>varsE<gt>)
11658
11659@@ -1985,7 +1991,7 @@ collect all the columns defined in the MIB table.
11660 Specifies a GETBULK repeat I<COUNT>. IE, it will request this many
11661 varbinds back per column when using the GETBULK operation. Shortening
11662 this will mean smaller packets which may help going through some
11663-systems. By default, this value is calculated and attepmts to guess
11664+systems. By default, this value is calculated and attempts to guess
11665 at what will fit all the results into 1000 bytes. This calculation is
11666 fairly safe, hopefully, but you can either raise or lower the number
11667 using this option if desired. In lossy networks, you want to make
11668@@ -1997,7 +2003,7 @@ one way to help that.
11669 Force the use of GETNEXT rather than GETBULK. (always true for
11670 SNMPv1, as it doesn't have GETBULK anyway). Some agents are great
11671 implementers of GETBULK and this allows you to force the use of
11672-GETNEXT oprations instead.
11673+GETNEXT operations instead.
11674
11675 =item callback => \&subroutine
11676
11677@@ -2023,7 +2029,7 @@ versions prior to 5.04 and 5.04 and up, the following should work:
11678 $no_mainloop = 1;
11679 }
11680
11681-Deciding on whether to use SNMP::MainLoop is left as an excersize to
11682+Deciding on whether to use SNMP::MainLoop is left as an exercise to
11683 the reader since it depends on whether your code uses other callbacks
11684 as well.
11685
11686@@ -2238,9 +2244,9 @@ will be undef.
11687 to be used with async SNMP::Session
11688 calls. MainLoop must be called after initial async calls
11689 so return packets from the agent will not be processed.
11690-If no args suplied this function enters an infinite loop
11691+If no args supplied this function enters an infinite loop
11692 so program must be exited in a callback or externally
11693-interupted. If <timeout(sic)
11694+interrupted. If <timeout(sic)
11695
11696 =item &SNMP::finish()
11697
11698@@ -2322,7 +2328,7 @@ initialization
11699
11700 =item $SNMP::debugging
11701
11702-default '0', controlls debugging output level
11703+default '0', controls debugging output level
11704 within SNMP module and libsnmp
11705
11706 =over
11707@@ -2346,6 +2352,12 @@ level 2 plus snmp_set_dump_packet(1)
11708 default '0', set [non-]zero to independently set
11709 snmp_set_dump_packet()
11710
11711+=item SNMP::register_debug_tokens()
11712+
11713+Allows to register one or more debug tokens, just like the -D option of snmpd.
11714+Each debug token enables a group of debug statements. An example:
11715+SNMP::register_debug_tokens("tdomain,netsnmp_unix");
11716+
11717 =back
11718
11719 =head1 %SNMP::MIB
11720@@ -2459,7 +2471,7 @@ returns true if the last object in the INDEX is IMPLIED
11721 =item &SNMP::setMib(<file>)
11722
11723 allows dynamic parsing of the mib and explicit
11724-specification of mib file independent of enviroment
11725+specification of mib file independent of environment
11726 variables. called with no args acts like initMib,
11727 loading MIBs indicated by environment variables (see
11728 Net-SNMP mib_api docs). passing non-zero second arg
11729diff --git a/perl/SNMP/SNMP.xs b/perl/SNMP/SNMP.xs
11730index a0cfe69..ff84919 100644
11731--- a/perl/SNMP/SNMP.xs
11732+++ b/perl/SNMP/SNMP.xs
11733@@ -1,4 +1,4 @@
11734-/* -*- C -*-
11735+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*-
11736 SNMP.xs -- Perl 5 interface to the Net-SNMP toolkit
11737
11738 written by G. S. Marzot (marz@users.sourceforge.net)
11739@@ -221,7 +221,15 @@ __snprint_oid(const oid *objid, size_t objidlen) {
11740 #else /* DEBUGGING */
11741 #define DBDCL(x)
11742 #define DBOUT
11743-#define DBPRT(severity, otherargs) /* Ignore */
11744+/* Do nothing but in such a way that the compiler sees "otherargs". */
11745+#define DBPRT(severity, otherargs) \
11746+ do { if (0) printf otherargs; } while(0)
11747+
11748+static char *
11749+__snprint_oid(const oid *objid, size_t objidlen)
11750+{
11751+ return "(debugging is disabled)";
11752+}
11753
11754 #endif /* DEBUGGING */
11755
11756@@ -451,8 +459,7 @@ int flag;
11757 if (flag == USE_ENUMS) {
11758 for(ep = tp->enums; ep; ep = ep->next) {
11759 if (ep->value == *var->val.integer) {
11760- strncpy(buf, ep->label, buf_len);
11761- buf[buf_len-1] = '\0';
11762+ strlcpy(buf, ep->label, buf_len);
11763 len = strlen(buf);
11764 break;
11765 }
11766@@ -929,19 +936,22 @@ oid *doid_arr;
11767 size_t *doid_arr_len;
11768 char * soid_str;
11769 {
11770- char soid_buf[STR_BUF_SIZE];
11771+ char *soid_buf;
11772 char *cp;
11773 char *st;
11774
11775 if (!soid_str || !*soid_str) return SUCCESS;/* successfully added nothing */
11776 if (*soid_str == '.') soid_str++;
11777- strcpy(soid_buf, soid_str);
11778+ soid_buf = strdup(soid_str);
11779+ if (!soid_buf)
11780+ return FAILURE;
11781 cp = strtok_r(soid_buf,".",&st);
11782 while (cp) {
11783 sscanf(cp, "%" NETSNMP_PRIo "u", &(doid_arr[(*doid_arr_len)++]));
11784 /* doid_arr[(*doid_arr_len)++] = atoi(cp); */
11785 cp = strtok_r(NULL,".",&st);
11786 }
11787+ free(soid_buf);
11788 return(SUCCESS);
11789 }
11790
11791@@ -1040,7 +1050,7 @@ OCT:
11792 vars->type = ASN_IPADDRESS;
11793 vars->val.integer = netsnmp_malloc(sizeof(in_addr_t));
11794 if (val)
11795- *(vars->val.integer) = inet_addr(val);
11796+ *((in_addr_t *)vars->val.integer) = inet_addr(val);
11797 else {
11798 ret = FAILURE;
11799 *(vars->val.integer) = 0;
11800@@ -1584,7 +1594,7 @@ _bulkwalk_done(walk_context *context)
11801 ** walks still in progress.
11802 */
11803 DBPRT(1, (DBOUT "Ignoring %s request oid %s\n",
11804- bt_entry->norepeat? "nonrepeater" : "completed",
11805+ bt_entry->norepeat ? "nonrepeater" : "completed",
11806 __snprint_oid(bt_entry->req_oid, bt_entry->req_len)));
11807
11808 /* Ignore this OID in any further packets. */
11809@@ -1894,7 +1904,7 @@ _bulkwalk_recv_pdu(walk_context *context, netsnmp_pdu *pdu)
11810 int i;
11811 AV *varbind;
11812 SV *rv;
11813- DBDCL(SV**sess_ptr_sv=hv_fetch((HV*)SvRV(context->sess_ref),"SessPtr",7,1);)
11814+ SV **sess_ptr_sv = hv_fetch((HV*)SvRV(context->sess_ref), "SessPtr", 7, 1);
11815 SV **err_str_svp = hv_fetch((HV*)SvRV(context->sess_ref), "ErrorStr", 8, 1);
11816 SV **err_num_svp = hv_fetch((HV*)SvRV(context->sess_ref), "ErrorNum", 8, 1);
11817 SV **err_ind_svp = hv_fetch((HV*)SvRV(context->sess_ref), "ErrorInd", 8, 1);
11818@@ -2930,6 +2940,8 @@ snmp_add_mib_dir(mib_dir,force=0)
11819 int result = 0; /* Avoid use of uninitialized variable below. */
11820 int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04));
11821
11822+ DBPRT(999, (DBOUT "force=%d\n", force));
11823+
11824 if (mib_dir && *mib_dir) {
11825 result = add_mibdir(mib_dir);
11826 }
11827@@ -2979,6 +2991,8 @@ snmp_read_mib(mib_file, force=0)
11828 {
11829 int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04));
11830
11831+ DBPRT(999, (DBOUT "force=%d\n", force));
11832+
11833 if ((mib_file == NULL) || (*mib_file == '\0')) {
11834 if (get_tree_head() == NULL) {
11835 if (verbose) warn("snmp_read_mib: initializing MIB\n");
11836@@ -3541,11 +3555,11 @@ snmp_getnext(sess_ref, varlist_ref, perl_callback)
11837 varbind = (AV*) SvRV(*varbind_ref);
11838
11839 /* If the varbind includes the module prefix, capture it for use later */
11840- strncpy(tmp_buf_prefix, __av_elem_pv(varbind, VARBIND_TAG_F, ".0"), STR_BUF_SIZE);
11841+ strlcpy(tmp_buf_prefix, __av_elem_pv(varbind, VARBIND_TAG_F, ".0"), STR_BUF_SIZE);
11842 tmp_prefix_ptr = strstr(tmp_buf_prefix,"::");
11843 if (tmp_prefix_ptr) {
11844 tmp_prefix_ptr = strtok_r(tmp_buf_prefix, "::", &st);
11845- strncpy(str_buf_prefix, tmp_prefix_ptr, STR_BUF_SIZE);
11846+ strlcpy(str_buf_prefix, tmp_prefix_ptr, STR_BUF_SIZE);
11847 }
11848 else {
11849 *str_buf_prefix = '\0';
11850@@ -3657,9 +3671,9 @@ snmp_getnext(sess_ref, varlist_ref, perl_callback)
11851
11852 /* Prepend the module prefix to the next OID if needed */
11853 if (*str_buf_prefix) {
11854- strncat(str_buf_prefix, "::", STR_BUF_SIZE - strlen(str_buf_prefix) - 2);
11855- strncat(str_buf_prefix, str_buf, STR_BUF_SIZE - strlen(str_buf_prefix));
11856- strncpy(str_buf, str_buf_prefix, STR_BUF_SIZE);
11857+ strlcat(str_buf_prefix, "::", STR_BUF_SIZE);
11858+ strlcat(str_buf_prefix, str_buf, STR_BUF_SIZE);
11859+ strlcpy(str_buf, str_buf_prefix, STR_BUF_SIZE);
11860 }
11861
11862 if (__is_leaf(tp)) {
11863@@ -4242,15 +4256,16 @@ snmp_bulkwalk(sess_ref, nonrepeaters, maxrepetitions, varlist_ref,perl_callback)
11864
11865 /* Handle error cases and clean up after ourselves. */
11866 err:
11867- if (context->req_oids && context->nreq_oids) {
11868- bt_entry = context->req_oids;
11869- for (i = 0; i < context->nreq_oids; i++, bt_entry++)
11870- av_clear(bt_entry->vars);
11871- }
11872- if (context->req_oids)
11873- Safefree(context->req_oids);
11874- if (context)
11875+ if (context) {
11876+ if (context->req_oids && context->nreq_oids) {
11877+ bt_entry = context->req_oids;
11878+ for (i = 0; i < context->nreq_oids; i++, bt_entry++)
11879+ av_clear(bt_entry->vars);
11880+ }
11881+ if (context->req_oids)
11882+ Safefree(context->req_oids);
11883 Safefree(context);
11884+ }
11885 if (pdu)
11886 snmp_free_pdu(pdu);
11887
11888@@ -4437,7 +4452,7 @@ snmp_trapV2(sess_ref,uptime,trap_oid,varlist_ref)
11889
11890 New (0, oid_arr, MAX_OID_LEN, oid);
11891
11892- if (oid_arr && SvROK(sess_ref) && SvROK(varlist_ref)) {
11893+ if (oid_arr && SvROK(sess_ref)) {
11894
11895 sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1);
11896 ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv));
11897@@ -4451,8 +4466,13 @@ snmp_trapV2(sess_ref,uptime,trap_oid,varlist_ref)
11898
11899 pdu = snmp_pdu_create(SNMP_MSG_TRAP2);
11900
11901- varlist = (AV*) SvRV(varlist_ref);
11902- varlist_len = av_len(varlist);
11903+ if (SvROK(varlist_ref)) {
11904+ varlist = (AV*) SvRV(varlist_ref);
11905+ varlist_len = av_len(varlist);
11906+ } else {
11907+ varlist = NULL;
11908+ varlist_len = -1;
11909+ }
11910 /************************************************/
11911 res = __add_var_val_str(pdu, sysUpTime, SYS_UPTIME_OID_LEN,
11912 uptime, strlen(uptime), TYPE_TIMETICKS);
11913@@ -4838,10 +4858,10 @@ snmp_translate_obj(var,mode,use_long,auto_init,best_guess,include_module_name)
11914 if (((status=__get_label_iid(str_buf_temp,
11915 &label, &iid, NO_FLAGS)) == SUCCESS)
11916 && label) {
11917- strcpy(str_buf_temp, label);
11918+ strlcpy(str_buf_temp, label, sizeof(str_buf_temp));
11919 if (iid && *iid) {
11920- strcat(str_buf_temp, ".");
11921- strcat(str_buf_temp, iid);
11922+ strlcat(str_buf_temp, ".", sizeof(str_buf_temp));
11923+ strlcat(str_buf_temp, iid, sizeof(str_buf_temp));
11924 }
11925 }
11926 }
11927@@ -4902,6 +4922,15 @@ snmp_set_debugging(val)
11928 }
11929
11930 void
11931+snmp_register_debug_tokens(tokens)
11932+ char *tokens
11933+ CODE:
11934+ {
11935+ debug_register_tokens(tokens);
11936+ snmp_set_do_debugging(1);
11937+ }
11938+
11939+void
11940 snmp_debug_internals(val)
11941 int val
11942 CODE:
11943diff --git a/perl/SNMP/examples/pingmib.pl b/perl/SNMP/examples/pingmib.pl
11944old mode 100644
11945new mode 100755
11946index 22dbe69..e6aa792
11947--- a/perl/SNMP/examples/pingmib.pl
11948+++ b/perl/SNMP/examples/pingmib.pl
11949@@ -1,3 +1,9 @@
11950+#!/usr/bin/env perl
11951+
11952+# Ping a host via the CISCO-PING-MIB. For more information about the
11953+# CISCO-PING-MIB, see also
11954+# http://tools.cisco.com/Support/SNMP/do/BrowseMIB.do?local=en&mibName=CISCO-PING-MIB.
11955+
11956 use strict;
11957 use SNMP;
11958
11959@@ -13,8 +19,9 @@ my $community = shift || 'private';
11960 my $dec = pack("C*",split /\./, $target);
11961 my $oid = ".1.3.6.1.4.1.9.9.16.1.1.1";
11962 my $row = "300";
11963+ my $res;
11964
11965- $sess->set([
11966+ $res = $sess->set([
11967 ["$oid.16", $row, 6, "INTEGER"],
11968 ["$oid.16", $row, 5, "INTEGER"],
11969 ["$oid.15", $row, "MoNDS", "OCTETSTR"],
11970@@ -22,8 +29,11 @@ my $community = shift || 'private';
11971 ["$oid.4", $row, 20, "INTEGER"],
11972 ["$oid.5", $row, 150, "INTEGER"],
11973 ["$oid.3", $row, $dec, "OCTETSTR"]]);
11974+ defined($res) || die "row creation failed";
11975+
11976+ $res = $sess->set([["$oid.16", $row, 1, "INTEGER"]]);
11977+ defined($res) || die "row activation failed";
11978
11979- $sess->set([["$oid.16", $row, 1, "INTEGER"]]);
11980 sleep 30;
11981 my ($sent, $received, $low, $avg, $high, $completed) = $sess->get([
11982 ["$oid.9", $row], ["$oid.10", $row], ["$oid.11", $row],
11983diff --git a/perl/SNMP/t/async.t b/perl/SNMP/t/async.t
11984index b1c86c6..f3fb38d 100644
11985--- a/perl/SNMP/t/async.t
11986+++ b/perl/SNMP/t/async.t
11987@@ -17,7 +17,7 @@ use SNMP;
11988 use vars qw($agent_port $comm $agent_host);
11989
11990 if ($^O =~ /win32/i) {
11991- warn "Win32 detected - skipping async calls\n";
11992+ warn "Win32/Win64 detected - skipping async calls\n";
11993 exit;
11994 }
11995
11996diff --git a/perl/SNMP/t/bulkwalk.t b/perl/SNMP/t/bulkwalk.t
11997index 60f10b5..2d13e7b 100644
11998--- a/perl/SNMP/t/bulkwalk.t
11999+++ b/perl/SNMP/t/bulkwalk.t
12000@@ -326,7 +326,7 @@ $vars = new SNMP::VarList ( ['sysUpTime'], ['ifNumber'], # NON-repeaters
12001 ['ifSpeed'], ['ifDescr']); # Repeated variables.
12002
12003 if ($^O =~ /win32/i) {
12004- warn "Win32 detected - skipping async calls\n";
12005+ warn "Win32/Win64 detected - skipping async calls\n";
12006 }
12007 else {
12008 @list = $s1->bulkwalk(2, 16, $vars, [ \&async_cb1, $vars ] );
12009diff --git a/perl/SNMP/t/notify.t b/perl/SNMP/t/notify.t
12010index 434237f..72600fa 100644
12011--- a/perl/SNMP/t/notify.t
12012+++ b/perl/SNMP/t/notify.t
12013@@ -10,7 +10,7 @@ BEGIN {
12014 $ENV{'MIBDIRS'} = '+' . abs_path("../../mibs");
12015 }
12016 use Test;
12017-BEGIN { $n = 10; plan tests => $n }
12018+BEGIN { $n = 11; plan tests => $n }
12019 use SNMP;
12020 use vars qw($agent_port $comm $comm2 $trap_port $agent_host $sec_name $priv_pass $auth_pass $bad_name);
12021 require 't/startagent.pl';
12022@@ -21,20 +21,20 @@ my $enterprise = '.1.3.6.1.2.1.1.1.0';
12023 my $generic = 'specific';
12024
12025 # V1 trap testing
12026-###################### 1 #############################
12027+######################## 1 ############################
12028 # Fire up a trap session.
12029 my $s1 =
12030 new SNMP::Session (DestHost=>$agent_host,Version=>1,Community=>$comm,RemotePort=>$trap_port);
12031 ok(defined($s1));
12032
12033-########################## 2 ####################################
12034+######################## 2 ############################
12035 # test v1 trap
12036 if (defined($s1)) {
12037 $res = $s1->trap(enterprise => $enterprise, agent=>$agent_host, generic=>$generic,[[sysContact, 0, 'root@localhost'], [sysLocation, 0, 'here']] );
12038 }
12039 ok($res =~ /^0 but true/);
12040
12041-########################### 3 #############################
12042+######################## 3 ############################
12043 # test with wrong varbind
12044 undef $res;
12045 if (defined($s1)) {
12046@@ -45,12 +45,12 @@ ok(!defined($res));
12047 #########################################################
12048
12049 # V2 testing
12050-########################## 4 ############################
12051+######################## 4 ############################
12052 # Fire up a v2 trap session.
12053 my $s2 =
12054 new SNMP::Session (Version=>2, DestHost=>$agent_host,Community=>$comm2,RemotePort=>$trap_port);
12055 ok(defined($s2));
12056-######################### 5 ###########################
12057+######################## 5 ############################
12058 # test v2 trap
12059 undef $res;
12060 if (defined($s2)) {
12061@@ -58,7 +58,7 @@ if (defined($s2)) {
12062 #print("res is $res\n");
12063 }
12064 ok($res =~ /^0 but true/);
12065-########################## 6 ##########################
12066+######################## 6 ############################
12067 # no trapoid and uptime given. Should take defaults...
12068 my $ret;
12069 if (defined($s2)) {
12070@@ -66,27 +66,35 @@ if (defined($s2)) {
12071 #print("res is $ret\n");
12072 }
12073 ok(defined($ret));
12074+######################## 7 ############################
12075+# no varbind list given.
12076+undef $res;
12077+if (defined($s2)) {
12078+ $res = $s2->trap(trapoid=>'coldStart');
12079+ #print("res is $res\n");
12080+}
12081+ok(defined($res) && $res =~ /^0 but true/);
12082
12083 #########################################################
12084
12085 # v3 testing
12086-######################## 7 ############################
12087+######################## 8 ############################
12088 # Fire up a v3 trap session.
12089 my $s3 = new SNMP::Session(Version=>3, DestHost=> $agent_host, RemotePort=>$trap_port, SecName => $sec_name);
12090 ok(defined($s3));
12091
12092-######################## 8 ###########################
12093+######################## 9 ############################
12094 if (defined($s3)) {
12095 $res = $s3->inform(uptime=>111, trapoid=>'coldStart', [[sysContact, 0, 'root@localhost'], [sysLocation, 0, 'here']] );
12096 }
12097 ok($res =~ /^0 but true/);
12098
12099-#################### 9 #####################
12100+######################## 10 ############################
12101 # Fire up a v3 trap session.
12102 $s3 = new SNMP::Session(Version=>3, DestHost=> $agent_host, RemotePort=>$trap_port, SecName => $sec_name, SecLevel => authPriv, AuthPass => $auth_pass, PrivPass => $priv_pass);
12103 ok(defined($s3));
12104
12105-######################## 10 ###########################
12106+######################## 11 ############################
12107 undef $res;
12108 if (defined($s3)) {
12109 $res = $s3->inform(uptime=>111, trapoid=>'coldStart', [[sysContact, 0, 'root@localhost'], [sysLocation, 0, 'here']] );
12110diff --git a/perl/agent/agent.pm b/perl/agent/agent.pm
12111index 7a71a17..78421cb 100644
12112--- a/perl/agent/agent.pm
12113+++ b/perl/agent/agent.pm
12114@@ -98,7 +98,7 @@ sub AUTOLOAD {
12115 ($constname = $AUTOLOAD) =~ s/.*:://;
12116 croak "& not defined" if $constname eq 'constant';
12117 my $val;
12118- ($!, $val) = constant($constname, @_ ? $_[0] : 0);
12119+ ($!, $val) = constant($constname);
12120 if ($! != 0) {
12121 if ($! =~ /Invalid/ || $!{EINVAL}) {
12122 $AutoLoader::AUTOLOAD = $AUTOLOAD;
12123@@ -199,6 +199,12 @@ sub agent_check_and_process {
12124 __agent_check_and_process($blocking || 0);
12125 }
12126
12127+sub uptime {
12128+ my $self = shift;
12129+ $self->maybe_init_lib();
12130+ return _uptime();
12131+}
12132+
12133 bootstrap NetSNMP::agent $VERSION;
12134
12135 # Preloaded methods go here.
12136diff --git a/perl/agent/agent.xs b/perl/agent/agent.xs
12137index ee77d50..c7b5d9a 100644
12138--- a/perl/agent/agent.xs
12139+++ b/perl/agent/agent.xs
12140@@ -215,13 +215,12 @@ handler_wrapper(netsnmp_mib_handler *handler,
12141 MODULE = NetSNMP::agent PACKAGE = NetSNMP::agent
12142
12143 void
12144-constant(sv,arg)
12145+constant(sv)
12146 PREINIT:
12147 STRLEN len;
12148 INPUT:
12149 SV * sv
12150 char * s = SvPV(sv, len);
12151- int arg
12152 INIT:
12153 int status;
12154 double value;
12155@@ -239,6 +238,13 @@ __agent_check_and_process(block = 1)
12156 OUTPUT:
12157 RETVAL
12158
12159+int
12160+_uptime()
12161+ CODE:
12162+ RETVAL = netsnmp_get_agent_uptime();
12163+ OUTPUT:
12164+ RETVAL
12165+
12166 void
12167 init_mib()
12168 CODE:
12169@@ -272,6 +278,8 @@ na_shutdown(me)
12170 SV *me;
12171 CODE:
12172 {
12173+ if (0)
12174+ printf("me = %p\n", me);
12175 snmp_shutdown("perl");
12176 }
12177
12178@@ -284,6 +292,8 @@ na_errlog(me,value)
12179 char * stringptr;
12180 CODE:
12181 {
12182+ if (0)
12183+ printf("me = %p\n", me);
12184 stringptr = SvPV(value, stringlen);
12185 snmp_log(LOG_ERR, "%s", stringptr );
12186 }
12187@@ -340,13 +350,27 @@ nsahr_register(me)
12188 SV *me;
12189 PREINIT:
12190 netsnmp_handler_registration *reginfo;
12191+ handler_cb_data *cb_data = NULL;
12192 CODE:
12193 {
12194 reginfo = (netsnmp_handler_registration *) SvIV(SvRV(me));
12195+ if (reginfo && reginfo->handler && reginfo->handler->myvoid)
12196+ cb_data = (handler_cb_data *) (reginfo->handler->myvoid);
12197 RETVAL = netsnmp_register_handler(reginfo);
12198 if (!RETVAL) {
12199 /* the agent now has a "reference" to this reg pointer */
12200 SvREFCNT_inc(me);
12201+ } else {
12202+ /*
12203+ * The reginfo was freed by netsnmp_register_handler,
12204+ * don't touch it in nsahr_DESTROY!
12205+ */
12206+ sv_setiv(SvRV(me), 0);
12207+ if (cb_data) {
12208+ /* And just free the callback. */
12209+ SvREFCNT_dec(cb_data->perl_cb);
12210+ free(cb_data);
12211+ }
12212 }
12213 }
12214 OUTPUT:
12215diff --git a/perl/agent/default_store/default_store.xs b/perl/agent/default_store/default_store.xs
12216index 815f9fd..bff1485 100644
12217--- a/perl/agent/default_store/default_store.xs
12218+++ b/perl/agent/default_store/default_store.xs
12219@@ -622,7 +622,7 @@ constant(sv)
12220 #endif
12221 STRLEN len;
12222 int type;
12223- IV iv;
12224+ IV iv = 0;
12225 /* NV nv; Uncomment this if you need to return NVs */
12226 /* const char *pv; Uncomment this if you need to return PVs */
12227 INPUT:
12228diff --git a/perl/agent/test.pl b/perl/agent/test.pl
12229index a7ac8f9..88cba56 100644
12230--- a/perl/agent/test.pl
12231+++ b/perl/agent/test.pl
12232@@ -9,7 +9,7 @@
12233 BEGIN { $| = 1;
12234 $ENV{'SNMPCONFPATH'} = 'nopath';
12235 $ENV{'MIBS'} = '';
12236- print "1..5\n";
12237+ print "1..6\n";
12238 }
12239 END {print "not ok 1\n" unless $loaded;}
12240 use NetSNMP::agent (':all');
12241@@ -76,6 +76,12 @@ $regitem = $agent->register("test_reg", ".1.3.6.1.8888", \&testsub);
12242 print it($regitem, 4);
12243 #print STDERR $regitem,":",ref($regitem),"\n";
12244 print it(ref($regitem) eq "NetSNMP::agent::netsnmp_handler_registration", 5);
12245+
12246+my $uptime1 = $agent->uptime();
12247+my $uptime2 = $agent->uptime(666);
12248+my $uptime3 = $agent->uptime(555, 444);
12249+print it($uptime1 <= $uptime2 && $uptime2 <= $uptime3, 6);
12250+
12251 exit;
12252
12253 while(1) {
12254diff --git a/perl/default_store/default_store.xs b/perl/default_store/default_store.xs
12255index e2b8a34..ca252fb 100644
12256--- a/perl/default_store/default_store.xs
12257+++ b/perl/default_store/default_store.xs
12258@@ -1261,7 +1261,7 @@ constant(sv)
12259 #endif
12260 STRLEN len;
12261 int type;
12262- IV iv;
12263+ IV iv = 0;
12264 /* NV nv; Uncomment this if you need to return NVs */
12265 /* const char *pv; Uncomment this if you need to return PVs */
12266 INPUT:
12267diff --git a/python/netsnmp/client_intf.c b/python/netsnmp/client_intf.c
12268index f2abf0b..559a9c0 100644
12269--- a/python/netsnmp/client_intf.c
12270+++ b/python/netsnmp/client_intf.c
12271@@ -1,5 +1,11 @@
12272 #include <Python.h>
12273
12274+#if PY_VERSION_HEX < 0x02050000
12275+typedef int Py_ssize_t;
12276+#define PY_SSIZE_T_MAX INT_MAX
12277+#define PY_SSIZE_T_MIN INT_MIN
12278+#endif
12279+
12280 #include <net-snmp/net-snmp-config.h>
12281 #include <net-snmp/net-snmp-includes.h>
12282 #include <sys/types.h>
12283@@ -67,8 +73,6 @@
12284
12285 typedef netsnmp_session SnmpSession;
12286 typedef struct tree SnmpMibNode;
12287-static void __recalc_timeout (struct timeval*,struct timeval*,
12288- struct timeval*,struct timeval*, int* );
12289 static int __is_numeric_oid (char*);
12290 static int __is_leaf (struct tree*);
12291 static int __translate_appl_type (char*);
12292@@ -80,10 +84,6 @@ static int __sprint_num_objid (char *, oid *, int);
12293 static int __scan_num_objid (char *, oid *, size_t *);
12294 static int __get_type_str (int, char *);
12295 static int __get_label_iid (char *, char **, char **, int);
12296-static int __oid_cmp (oid *, int, oid *, int);
12297-static int __tp_sprint_num_objid (char*,SnmpMibNode *);
12298-static SnmpMibNode * __get_next_mib_node (SnmpMibNode *);
12299-static struct tree * __oid2tp (oid*, int, struct tree *, int*);
12300 static struct tree * __tag2oid (char *, char *, oid *, int *, int *, int);
12301 static int __concat_oid_str (oid *, int *, char *);
12302 static int __add_var_val_str (netsnmp_pdu *, oid *, int, char *,
12303@@ -129,46 +129,6 @@ __libraries_init(char *appname)
12304 NETSNMP_OID_OUTPUT_SUFFIX);
12305 }
12306
12307-static void
12308-__recalc_timeout (tvp, ctvp, ltvp, itvp, block)
12309-struct timeval* tvp;
12310-struct timeval* ctvp;
12311-struct timeval* ltvp;
12312-struct timeval* itvp;
12313-int *block;
12314-{
12315- struct timeval now;
12316-
12317- if (!timerisset(itvp)) return; /* interval zero means loop forever */
12318- *block = 0;
12319- gettimeofday(&now,(struct timezone *)0);
12320-
12321- if (ctvp->tv_sec < 0) { /* first time or callback just fired */
12322- timersub(&now,ltvp,ctvp);
12323- timersub(ctvp,itvp,ctvp);
12324- timersub(itvp,ctvp,ctvp);
12325- timeradd(ltvp,itvp,ltvp);
12326- } else {
12327- timersub(&now,ltvp,ctvp);
12328- timersub(itvp,ctvp,ctvp);
12329- }
12330-
12331- /* flag is set for callback but still hasnt fired so set to something
12332- * small and we will service packets first if there are any ready
12333- * (also guard against negative timeout - should never happen?)
12334- */
12335- if (!timerisset(ctvp) || ctvp->tv_sec < 0 || ctvp->tv_usec < 0) {
12336- ctvp->tv_sec = 0;
12337- ctvp->tv_usec = 10;
12338- }
12339-
12340- /* if snmp timeout > callback timeout or no more requests to process */
12341- if (timercmp(tvp, ctvp, >) || !timerisset(tvp)) {
12342- *tvp = *ctvp; /* use the smaller non-zero timeout */
12343- timerclear(ctvp); /* used as a flag to let callback fire on timeout */
12344- }
12345-}
12346-
12347 static int
12348 __is_numeric_oid (oidstr)
12349 char* oidstr;
12350@@ -189,21 +149,6 @@ struct tree* tp;
12351 (tp->parent && __get_type_str(tp->parent->type,buf) )));
12352 }
12353
12354-static SnmpMibNode*
12355-__get_next_mib_node (tp)
12356-SnmpMibNode* tp;
12357-{
12358- /* printf("tp = %lX, parent = %lX, peer = %lX, child = %lX\n",
12359- tp, tp->parent, tp->next_peer, tp->child_list); */
12360- if (tp->child_list) return(tp->child_list);
12361- if (tp->next_peer) return(tp->next_peer);
12362- if (!tp->parent) return(NULL);
12363- for (tp = tp->parent; !tp->next_peer; tp = tp->parent) {
12364- if (!tp->parent) return(NULL);
12365- }
12366- return(tp->next_peer);
12367-}
12368-
12369 static int
12370 __translate_appl_type(typestr)
12371 char* typestr;
12372@@ -261,50 +206,36 @@ int type;
12373 switch (type) {
12374 case ASN_INTEGER:
12375 return(TYPE_INTEGER);
12376- break;
12377 case ASN_OCTET_STR:
12378 return(TYPE_OCTETSTR);
12379- break;
12380 case ASN_OPAQUE:
12381 return(TYPE_OPAQUE);
12382- break;
12383 case ASN_OBJECT_ID:
12384 return(TYPE_OBJID);
12385- break;
12386 case ASN_TIMETICKS:
12387 return(TYPE_TIMETICKS);
12388- break;
12389 case ASN_GAUGE:
12390 return(TYPE_GAUGE);
12391- break;
12392 case ASN_COUNTER:
12393 return(TYPE_COUNTER);
12394- break;
12395 case ASN_IPADDRESS:
12396 return(TYPE_IPADDR);
12397- break;
12398 case ASN_BIT_STR:
12399 return(TYPE_BITSTRING);
12400- break;
12401 case ASN_NULL:
12402 return(TYPE_NULL);
12403- break;
12404 /* no translation for these exception type values */
12405 case SNMP_ENDOFMIBVIEW:
12406 case SNMP_NOSUCHOBJECT:
12407 case SNMP_NOSUCHINSTANCE:
12408 return(type);
12409- break;
12410 case ASN_UINTEGER:
12411 return(TYPE_UINTEGER);
12412- break;
12413 case ASN_COUNTER64:
12414 return(TYPE_COUNTER64);
12415- break;
12416 default:
12417- return(TYPE_OTHER);
12418 fprintf(stderr, "translate_asn_type: unhandled asn type (%d)\n",type);
12419- break;
12420+ return(TYPE_OTHER);
12421 }
12422 }
12423
12424@@ -335,8 +266,7 @@ int flag;
12425 if (flag == USE_ENUMS) {
12426 for(ep = tp->enums; ep; ep = ep->next) {
12427 if (ep->value == *var->val.integer) {
12428- strncpy(buf, ep->label, buf_len);
12429- buf[buf_len -1] = 0;
12430+ strlcpy(buf, ep->label, buf_len);
12431 len = STRLEN(buf);
12432 break;
12433 }
12434@@ -445,21 +375,6 @@ int len;
12435 }
12436
12437 static int
12438-__tp_sprint_num_objid (buf, tp)
12439-char *buf;
12440-SnmpMibNode *tp;
12441-{
12442- oid newname[MAX_OID_LEN], *op;
12443- /* code taken from get_node in snmp_client.c */
12444- for (op = newname + MAX_OID_LEN - 1; op >= newname; op--) {
12445- *op = tp->subid;
12446- tp = tp->parent;
12447- if (tp == NULL) break;
12448- }
12449- return __sprint_num_objid(buf, op, newname + MAX_OID_LEN - op);
12450-}
12451-
12452-static int
12453 __scan_num_objid (buf, objid, len)
12454 char *buf;
12455 oid *objid;
12456@@ -674,24 +589,6 @@ int flag;
12457 return(SUCCESS);
12458 }
12459
12460-
12461-static int
12462-__oid_cmp(oida_arr, oida_arr_len, oidb_arr, oidb_arr_len)
12463-oid *oida_arr;
12464-int oida_arr_len;
12465-oid *oidb_arr;
12466-int oidb_arr_len;
12467-{
12468- for (;oida_arr_len && oidb_arr_len;
12469- oida_arr++, oida_arr_len--, oidb_arr++, oidb_arr_len--) {
12470- if (*oida_arr == *oidb_arr) continue;
12471- return(*oida_arr > *oidb_arr ? 1 : -1);
12472- }
12473- if (oida_arr_len == oidb_arr_len) return(0);
12474- return(oida_arr_len > oidb_arr_len ? 1 : -1);
12475-}
12476-
12477-
12478 /* Convert a tag (string) to an OID array */
12479 /* Tag can be either a symbolic name, or an OID string */
12480 static struct tree *
12481@@ -708,9 +605,6 @@ int best_guess;
12482 oid newname[MAX_OID_LEN], *op;
12483 size_t newname_len = 0;
12484
12485- char str_buf[STR_BUF_SIZE];
12486- str_buf[0] = '\0';
12487-
12488 if (type) *type = TYPE_UNKNOWN;
12489 if (oid_arr_len) *oid_arr_len = 0;
12490 if (!tag) goto done;
12491@@ -796,43 +690,10 @@ int best_guess;
12492 }
12493 }
12494 done:
12495- if (iid && *iid) __concat_oid_str(oid_arr, oid_arr_len, iid);
12496+ if (iid && *iid && oid_arr_len)
12497+ __concat_oid_str(oid_arr, oid_arr_len, iid);
12498 return(rtp);
12499 }
12500-/* searches down the mib tree for the given oid
12501- returns the last found tp and its index in lastind
12502- */
12503-static struct tree *
12504-__oid2tp (oidp, len, subtree, lastind)
12505-oid* oidp;
12506-int len;
12507-struct tree * subtree;
12508-int* lastind;
12509-{
12510- struct tree *return_tree = NULL;
12511-
12512-
12513- for (; subtree; subtree = subtree->next_peer) {
12514- if (*oidp == subtree->subid){
12515- goto found;
12516- }
12517- }
12518- *lastind=0;
12519- return NULL;
12520-
12521-found:
12522- if (len > 1){
12523- return_tree =
12524- __oid2tp(oidp + 1, len - 1, subtree->child_list, lastind);
12525- (*lastind)++;
12526- } else {
12527- *lastind=1;
12528- }
12529- if (return_tree)
12530- return return_tree;
12531- else
12532- return subtree;
12533-}
12534
12535 /* function: __concat_oid_str
12536 *
12537@@ -848,19 +709,22 @@ oid *doid_arr;
12538 int *doid_arr_len;
12539 char * soid_str;
12540 {
12541- char soid_buf[STR_BUF_SIZE];
12542+ char *soid_buf;
12543 char *cp;
12544 char *st;
12545
12546 if (!soid_str || !*soid_str) return SUCCESS;/* successfully added nothing */
12547 if (*soid_str == '.') soid_str++;
12548- strcpy(soid_buf, soid_str);
12549+ soid_buf = strdup(soid_str);
12550+ if (!soid_buf)
12551+ return FAILURE;
12552 cp = strtok_r(soid_buf,".",&st);
12553 while (cp) {
12554 sscanf(cp, "%lu", &(doid_arr[(*doid_arr_len)++]));
12555 /* doid_arr[(*doid_arr_len)++] = atoi(cp); */
12556 cp = strtok_r(NULL,".",&st);
12557 }
12558+ free(soid_buf);
12559 return(SUCCESS);
12560 }
12561
12562@@ -1004,7 +868,7 @@ char *err_str;
12563 int *err_num;
12564 int *err_ind;
12565 {
12566- int status;
12567+ int status = 0;
12568 long command = pdu->command;
12569 char *tmp_err_str;
12570
12571@@ -1017,7 +881,7 @@ int *err_ind;
12572 if (ss == NULL) {
12573 *err_num = 0;
12574 *err_ind = SNMPERR_BAD_SESSION;
12575- strncpy(err_str, snmp_api_errstring(*err_ind), STR_BUF_SIZE - 1);
12576+ strlcpy(err_str, snmp_api_errstring(*err_ind), STR_BUF_SIZE);
12577 goto done;
12578 }
12579
12580@@ -1025,7 +889,7 @@ int *err_ind;
12581 if (tmp_err_str == NULL) {
12582 *err_num = errno;
12583 *err_ind = SNMPERR_MALLOC;
12584- strncpy(err_str, snmp_api_errstring(*err_ind), STR_BUF_SIZE - 1);
12585+ strlcpy(err_str, snmp_api_errstring(*err_ind), STR_BUF_SIZE);
12586 goto done;
12587 }
12588
12589@@ -1070,8 +934,8 @@ retry:
12590 /* in SNMPv2c, SNMPv2u, SNMPv2*, and SNMPv3 PDUs */
12591 case SNMP_ERR_INCONSISTENTNAME:
12592 default:
12593- strncpy(err_str, (char*)snmp_errstring((*response)->errstat),
12594- STR_BUF_SIZE - 1);
12595+ strlcpy(err_str, (char*)snmp_errstring((*response)->errstat),
12596+ STR_BUF_SIZE);
12597 *err_num = (int)(*response)->errstat;
12598 *err_ind = (*response)->errindex;
12599 status = (*response)->errstat;
12600@@ -1082,8 +946,7 @@ retry:
12601 case STAT_TIMEOUT:
12602 case STAT_ERROR:
12603 snmp_sess_error(ss, err_num, err_ind, &tmp_err_str);
12604- strncpy(err_str, tmp_err_str, STR_BUF_SIZE - 1);
12605- err_str[STR_BUF_SIZE - 1] = '\0';
12606+ strlcpy(err_str, tmp_err_str, STR_BUF_SIZE);
12607 break;
12608
12609 default:
12610@@ -1368,8 +1231,9 @@ netsnmp_create_session_v3(PyObject *self, PyObject *args)
12611 USM_AUTH_PROTO_SHA_LEN);
12612 session.securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN;
12613 } else if (!strcmp(auth_proto, "DEFAULT")) {
12614- session.securityAuthProto =
12615- get_default_authtype(&session.securityAuthProtoLen);
12616+ const oid* a = get_default_authtype(&session.securityAuthProtoLen);
12617+ session.securityAuthProto
12618+ = snmp_duplicate_objid(a, session.securityAuthProtoLen);
12619 } else {
12620 if (verbose)
12621 printf("error:snmp_new_v3_session:Unsupported authentication protocol(%s)\n", auth_proto);
12622@@ -1403,8 +1267,9 @@ netsnmp_create_session_v3(PyObject *self, PyObject *args)
12623 USM_PRIV_PROTO_AES_LEN);
12624 session.securityPrivProtoLen = USM_PRIV_PROTO_AES_LEN;
12625 } else if (!strcmp(priv_proto, "DEFAULT")) {
12626- session.securityPrivProto =
12627- get_default_privtype(&session.securityPrivProtoLen);
12628+ const oid *p = get_default_privtype(&session.securityPrivProtoLen);
12629+ session.securityPrivProto
12630+ = snmp_duplicate_objid(p, session.securityPrivProtoLen);
12631 } else {
12632 if (verbose)
12633 printf("error:snmp_new_v3_session:Unsupported privacy protocol(%s)\n", priv_proto);
12634@@ -1448,7 +1313,6 @@ netsnmp_create_session_tunneled(PyObject *self, PyObject *args)
12635 int timeout;
12636 char * sec_name;
12637 int sec_level;
12638- char * sec_eng_id;
12639 char * context_eng_id;
12640 char * context;
12641 char * our_identity;
12642@@ -1525,7 +1389,11 @@ netsnmp_create_session_tunneled(PyObject *self, PyObject *args)
12643
12644 if (!ss)
12645 return NULL;
12646- return Py_BuildValue("i", (int)ss);
12647+ /*
12648+ * Note: on a 64-bit system the statement below discards the upper 32 bits of
12649+ * "ss", which is most likely a bug.
12650+ */
12651+ return Py_BuildValue("i", (int)(uintptr_t)ss);
12652 }
12653
12654 static PyObject *
12655@@ -1563,7 +1431,6 @@ netsnmp_get(PyObject *self, PyObject *args)
12656 int oid_arr_len = MAX_OID_LEN;
12657 int type;
12658 char type_str[MAX_TYPE_NAME_LEN];
12659- int status;
12660 u_char str_buf[STR_BUF_SIZE], *str_bufp = str_buf;
12661 size_t str_buf_len = sizeof(str_buf);
12662 size_t out_len = 0;
12663@@ -1646,8 +1513,8 @@ netsnmp_get(PyObject *self, PyObject *args)
12664 }
12665 }
12666
12667- status = __send_sync_pdu(ss, pdu, &response, retry_nosuch,
12668- err_str, &err_num, &err_ind);
12669+ __send_sync_pdu(ss, pdu, &response, retry_nosuch, err_str, &err_num,
12670+ &err_ind);
12671 __py_netsnmp_update_session_errors(session, err_str, err_num, err_ind);
12672
12673 /*
12674@@ -1698,8 +1565,8 @@ netsnmp_get(PyObject *self, PyObject *args)
12675 &out_len, 0, &buf_over,
12676 vars->name,vars->name_length);
12677 if (_debug_level)
12678- printf("netsnmp_get:str_bufp:%s:%d:%d\n",
12679- str_bufp,str_buf_len,out_len);
12680+ printf("netsnmp_get:str_bufp:%s:%d:%d\n", str_bufp,
12681+ (int)str_buf_len, (int)out_len);
12682
12683 str_buf[sizeof(str_buf)-1] = '\0';
12684
12685@@ -1715,20 +1582,19 @@ netsnmp_get(PyObject *self, PyObject *args)
12686
12687 if (_debug_level) printf("netsnmp_get:str_buf:%s\n",str_buf);
12688
12689- __get_label_iid(str_buf, &tag, &iid, getlabel_flag);
12690+ __get_label_iid((char *) str_buf, &tag, &iid, getlabel_flag);
12691
12692 py_netsnmp_attr_set_string(varbind, "tag", tag, STRLEN(tag));
12693 py_netsnmp_attr_set_string(varbind, "iid", iid, STRLEN(iid));
12694
12695 __get_type_str(type, type_str);
12696
12697- py_netsnmp_attr_set_string(varbind, "type", type_str,
12698- STRLEN(type_str));
12699+ py_netsnmp_attr_set_string(varbind, "type", type_str, strlen(type_str));
12700
12701- len = __snprint_value(str_buf,sizeof(str_buf),
12702- vars,tp,type,sprintval_flag);
12703+ len = __snprint_value((char *) str_buf, sizeof(str_buf),
12704+ vars, tp, type, sprintval_flag);
12705 str_buf[len] = '\0';
12706- py_netsnmp_attr_set_string(varbind, "val", str_buf, len);
12707+ py_netsnmp_attr_set_string(varbind, "val", (char *) str_buf, len);
12708
12709 /* save in return tuple as well */
12710 PyTuple_SetItem(val_tuple, varlist_ind,
12711@@ -1772,13 +1638,12 @@ netsnmp_getnext(PyObject *self, PyObject *args)
12712 int oid_arr_len = MAX_OID_LEN;
12713 int type;
12714 char type_str[MAX_TYPE_NAME_LEN];
12715- int status;
12716 u_char str_buf[STR_BUF_SIZE], *str_bufp = str_buf;
12717 size_t str_buf_len = sizeof(str_buf);
12718 size_t out_len = 0;
12719 int buf_over = 0;
12720 char *tag;
12721- char *iid;
12722+ char *iid = NULL;
12723 int getlabel_flag = NO_FLAGS;
12724 int sprintval_flag = USE_BASIC;
12725 int verbose = py_netsnmp_verbose();
12726@@ -1862,8 +1727,8 @@ netsnmp_getnext(PyObject *self, PyObject *args)
12727 }
12728 }
12729
12730- status = __send_sync_pdu(ss, pdu, &response, retry_nosuch,
12731- err_str, &err_num, &err_ind);
12732+ __send_sync_pdu(ss, pdu, &response, retry_nosuch, err_str, &err_num,
12733+ &err_ind);
12734 __py_netsnmp_update_session_errors(session, err_str, err_num, err_ind);
12735
12736 /*
12737@@ -1924,7 +1789,7 @@ netsnmp_getnext(PyObject *self, PyObject *args)
12738 type = __translate_asn_type(vars->type);
12739 }
12740
12741- __get_label_iid(str_buf, &tag, &iid, getlabel_flag);
12742+ __get_label_iid((char *) str_buf, &tag, &iid, getlabel_flag);
12743
12744 if (_debug_level)
12745 printf("netsnmp_getnext: filling response: %s:%s\n", tag, iid);
12746@@ -1935,13 +1800,13 @@ netsnmp_getnext(PyObject *self, PyObject *args)
12747 __get_type_str(type, type_str);
12748
12749 py_netsnmp_attr_set_string(varbind, "type", type_str,
12750- STRLEN(type_str));
12751+ strlen(type_str));
12752
12753- len = __snprint_value(str_buf,sizeof(str_buf),
12754- vars,tp,type,sprintval_flag);
12755+ len = __snprint_value((char *) str_buf, sizeof(str_buf),
12756+ vars, tp, type, sprintval_flag);
12757 str_buf[len] = '\0';
12758
12759- py_netsnmp_attr_set_string(varbind, "val", str_buf, len);
12760+ py_netsnmp_attr_set_string(varbind, "val", (char *) str_buf, len);
12761
12762 /* save in return tuple as well */
12763 PyTuple_SetItem(val_tuple, varlist_ind,
12764@@ -1984,10 +1849,10 @@ netsnmp_walk(PyObject *self, PyObject *args)
12765 netsnmp_variable_list *vars, *oldvars;
12766 struct tree *tp;
12767 int len;
12768- oid **oid_arr;
12769- int *oid_arr_len;
12770- oid **oid_arr_broken_check;
12771- int *oid_arr_broken_check_len;
12772+ oid **oid_arr = NULL;
12773+ int *oid_arr_len = NULL;
12774+ oid **oid_arr_broken_check = NULL;
12775+ int *oid_arr_broken_check_len = NULL;
12776 int type;
12777 char type_str[MAX_TYPE_NAME_LEN];
12778 int status;
12779@@ -1996,7 +1861,7 @@ netsnmp_walk(PyObject *self, PyObject *args)
12780 size_t out_len = 0;
12781 int buf_over = 0;
12782 char *tag;
12783- char *iid;
12784+ char *iid = NULL;
12785 int getlabel_flag = NO_FLAGS;
12786 int sprintval_flag = USE_BASIC;
12787 int verbose = py_netsnmp_verbose();
12788@@ -2102,7 +1967,8 @@ netsnmp_walk(PyObject *self, PyObject *args)
12789 varlist_ind++;
12790 }
12791
12792- Py_DECREF(varlist_iter);
12793+ if (varlist_iter)
12794+ Py_DECREF(varlist_iter);
12795
12796 if (PyErr_Occurred()) {
12797 /* propagate error */
12798@@ -2246,7 +2112,7 @@ netsnmp_walk(PyObject *self, PyObject *args)
12799 type = __translate_asn_type(vars->type);
12800 }
12801
12802- __get_label_iid(str_buf, &tag, &iid, getlabel_flag);
12803+ __get_label_iid((char *) str_buf, &tag, &iid, getlabel_flag);
12804
12805 if (_debug_level) printf("netsnmp_walk: filling response: %s:%s\n", tag, iid);
12806
12807@@ -2256,13 +2122,14 @@ netsnmp_walk(PyObject *self, PyObject *args)
12808 __get_type_str(type, type_str);
12809
12810 py_netsnmp_attr_set_string(varbind, "type", type_str,
12811- STRLEN(type_str));
12812+ strlen(type_str));
12813
12814- len = __snprint_value(str_buf,sizeof(str_buf),
12815+ len = __snprint_value((char *) str_buf,sizeof(str_buf),
12816 vars,tp,type,sprintval_flag);
12817 str_buf[len] = '\0';
12818
12819- py_netsnmp_attr_set_string(varbind, "val", str_buf, len);
12820+ py_netsnmp_attr_set_string(varbind, "val", (char *) str_buf,
12821+ len);
12822
12823 /* push the varbind onto the return varbinds */
12824 PyList_Append(varbinds, varbind);
12825@@ -2345,7 +2212,6 @@ netsnmp_getbulk(PyObject *self, PyObject *args)
12826 int oid_arr_len = MAX_OID_LEN;
12827 int type;
12828 char type_str[MAX_TYPE_NAME_LEN];
12829- int status;
12830 u_char str_buf[STR_BUF_SIZE], *str_bufp = str_buf;
12831 size_t str_buf_len = sizeof(str_buf);
12832 size_t out_len = 0;
12833@@ -2434,8 +2300,8 @@ netsnmp_getbulk(PyObject *self, PyObject *args)
12834 goto done;
12835 }
12836
12837- status = __send_sync_pdu(ss, pdu, &response, retry_nosuch,
12838- err_str, &err_num, &err_ind);
12839+ __send_sync_pdu(ss, pdu, &response, retry_nosuch, err_str, &err_num,
12840+ &err_ind);
12841 __py_netsnmp_update_session_errors(session, err_str, err_num, err_ind);
12842
12843 /*
12844@@ -2505,7 +2371,7 @@ netsnmp_getbulk(PyObject *self, PyObject *args)
12845 type = __translate_asn_type(vars->type);
12846 }
12847
12848- __get_label_iid(str_buf, &tag, &iid, getlabel_flag);
12849+ __get_label_iid((char *) str_buf, &tag, &iid, getlabel_flag);
12850
12851 py_netsnmp_attr_set_string(varbind, "tag", tag, STRLEN(tag));
12852 py_netsnmp_attr_set_string(varbind, "iid", iid, STRLEN(iid));
12853@@ -2513,13 +2379,13 @@ netsnmp_getbulk(PyObject *self, PyObject *args)
12854 __get_type_str(type, type_str);
12855
12856 py_netsnmp_attr_set_string(varbind, "type", type_str,
12857- STRLEN(type_str));
12858+ strlen(type_str));
12859
12860- len = __snprint_value(str_buf,sizeof(str_buf),
12861- vars,tp,type,sprintval_flag);
12862+ len = __snprint_value((char *) str_buf, sizeof(str_buf),
12863+ vars, tp, type, sprintval_flag);
12864 str_buf[len] = '\0';
12865
12866- py_netsnmp_attr_set_string(varbind, "val", str_buf, len);
12867+ py_netsnmp_attr_set_string(varbind, "val", (char *) str_buf, len);
12868
12869 /* push varbind onto varbinds */
12870 PyList_Append(varbinds, varbind);
12871@@ -2556,7 +2422,8 @@ netsnmp_getbulk(PyObject *self, PyObject *args)
12872 /* propagate error */
12873 if (verbose)
12874 printf("error: getbulk response processing: unknown python error");
12875- Py_DECREF(val_tuple);
12876+ if (val_tuple)
12877+ Py_DECREF(val_tuple);
12878 val_tuple = NULL;
12879 }
12880 }
12881@@ -2663,14 +2530,15 @@ netsnmp_set(PyObject *self, PyObject *args)
12882 if (type==TYPE_INTEGER && use_enums && tp && tp->enums) {
12883 for(ep = tp->enums; ep; ep = ep->next) {
12884 if (val && !strcmp(ep->label, val)) {
12885- strcpy(tmp_val_str, ep->value);
12886+ snprintf((char *) tmp_val_str, sizeof(tmp_val_str), "%d",
12887+ ep->value);
12888 break;
12889 }
12890 }
12891 }
12892 len = (int)tmplen;
12893 status = __add_var_val_str(pdu, oid_arr, oid_arr_len,
12894- tmp_val_str, len, type);
12895+ (char *) tmp_val_str, len, type);
12896
12897 if (verbose && status == FAILURE)
12898 printf("error: set: adding variable/value to PDU");
12899diff --git a/snmplib/Makefile.in b/snmplib/Makefile.in
12900index 48beb38..506b8d4 100644
12901--- a/snmplib/Makefile.in
12902+++ b/snmplib/Makefile.in
12903@@ -243,7 +243,3 @@ libsnmp.$(LIB_EXTENSION)$(LIB_VERSION): $(TOBJS)
12904 parse: mib.o parse.c
12905 $(CC) $(CFLAGS) -DTEST parse.c -o $@ \
12906 `$(top_srcdir)/net-snmp-config --libs`
12907-
12908-test_binary_array: test_binary_array.c
12909- $(CC) $(CFLAGS) test_binary_array.c -o $@ \
12910- `$(top_srcdir)/net-snmp-config --libs`
12911diff --git a/snmplib/asn1.c b/snmplib/asn1.c
12912index 030fa63..e4da6be 100644
12913--- a/snmplib/asn1.c
12914+++ b/snmplib/asn1.c
12915@@ -1371,7 +1371,7 @@ asn_parse_objid(u_char * data,
12916 }
12917 }
12918 #if defined(EIGHTBIT_SUBIDS) || (SIZEOF_LONG != 4)
12919- if (subidentifier > (u_long) MAX_SUBID) {
12920+ if (subidentifier > MAX_SUBID) {
12921 ERROR_MSG("subidentifier too large");
12922 return NULL;
12923 }
12924@@ -1540,13 +1540,8 @@ asn_build_objid(u_char * data,
12925 */
12926 for (i = 1, objid_val = first_objid_val, op = objid + 2;
12927 i < (int) objidlength; i++) {
12928- if (i != 1) {
12929- objid_val = *op++;
12930-#if SIZEOF_LONG != 4
12931- if (objid_val > 0xffffffff) /* already logged warning above */
12932- objid_val &= 0xffffffff;
12933-#endif
12934- }
12935+ if (i != 1)
12936+ objid_val = (uint32_t)(*op++); /* already logged warning above */
12937 switch (objid_size[i]) {
12938 case 1:
12939 *data++ = (u_char) objid_val;
12940diff --git a/snmplib/callback.c b/snmplib/callback.c
12941index 16026e9..dfe537a 100644
12942--- a/snmplib/callback.c
12943+++ b/snmplib/callback.c
12944@@ -249,7 +249,7 @@ snmp_register_callback(int major, int minor, SNMPCallback * new_callback,
12945 * @param minor Minor callback event type.
12946 * @param new_callback Callback function being registered.
12947 * @param arg Argument that will be passed to the callback function.
12948- * @priority Handler invocation priority. When multiple handlers have
12949+ * @param priority Handler invocation priority. When multiple handlers have
12950 * been registered for the same (major, minor) callback event type, handlers
12951 * with the numerically lowest priority will be invoked first. Handlers with
12952 * identical priority are invoked in the order they have been registered.
12953diff --git a/snmplib/cert_util.c b/snmplib/cert_util.c
12954index 6d9efe5..246a6c9 100644
12955--- a/snmplib/cert_util.c
12956+++ b/snmplib/cert_util.c
12957@@ -751,7 +751,6 @@ _certindex_add( const char *dirname, int i )
12958 if (SE_OK != rc) {
12959 snmp_log(LOG_ERR, "adding certindex dirname failed; "
12960 "%d (%s) not added\n", i, dirname);
12961- free(dirname_copy);
12962 return -1;
12963 }
12964
12965@@ -791,7 +790,7 @@ _certindexes_load( void )
12966 * Create a list of which directory each file refers to
12967 */
12968 while ((file = readdir( dir ))) {
12969- if ( !isdigit(file->d_name[0]))
12970+ if ( !isdigit(0xFF & file->d_name[0]))
12971 continue;
12972 i = atoi( file->d_name );
12973
12974@@ -801,7 +800,6 @@ _certindexes_load( void )
12975 fp = fopen( filename, "r" );
12976 if ( !fp ) {
12977 DEBUGMSGT(("cert:index:load", "error opening index (%d)\n", i));
12978- fclose(fp);
12979 continue;
12980 }
12981 cp = fgets( line, sizeof(line), fp );
12982@@ -1179,12 +1177,6 @@ _find_partner(netsnmp_cert *cert, netsnmp_key *key)
12983 return;
12984 }
12985
12986- snprintf(filename, sizeof(filename), "%s", key->info.filename);
12987- pos = strrchr(filename, '.');
12988- if (NULL == pos)
12989- return;
12990- *pos = 0;
12991-
12992 if(key) {
12993 if (key->cert) {
12994 DEBUGMSGT(("cert:partner", "key already has partner\n"));
12995@@ -1192,6 +1184,11 @@ _find_partner(netsnmp_cert *cert, netsnmp_key *key)
12996 }
12997 DEBUGMSGT(("9:cert:partner", "%s looking for partner near %s\n",
12998 key->info.filename, key->info.dir));
12999+ snprintf(filename, sizeof(filename), "%s", key->info.filename);
13000+ pos = strrchr(filename, '.');
13001+ if (NULL == pos)
13002+ return;
13003+ *pos = 0;
13004
13005 matching = _cert_find_subset_fn( filename, key->info.dir );
13006 if (!matching)
13007@@ -1220,6 +1217,11 @@ _find_partner(netsnmp_cert *cert, netsnmp_key *key)
13008 }
13009 DEBUGMSGT(("9:cert:partner", "%s looking for partner\n",
13010 cert->info.filename));
13011+ snprintf(filename, sizeof(filename), "%s", cert->info.filename);
13012+ pos = strrchr(filename, '.');
13013+ if (NULL == pos)
13014+ return;
13015+ *pos = 0;
13016
13017 matching = _key_find_subset(filename);
13018 if (!matching)
13019@@ -1714,7 +1716,7 @@ netsnmp_fp_lowercase_and_strip_colon(char *fp)
13020 break;
13021 }
13022 else
13023- *pos = isalpha(*pos) ? tolower(*pos) : *pos;
13024+ *pos = isalpha(0xFF & *pos) ? tolower(0xFF & *pos) : *pos;
13025 }
13026 if (!*pos)
13027 return;
13028@@ -1723,7 +1725,7 @@ netsnmp_fp_lowercase_and_strip_colon(char *fp)
13029 for (++pos; *pos; ++pos) {
13030 if (':' == *pos)
13031 continue;
13032- *dest++ = isalpha(*pos) ? tolower(*pos) : *pos;
13033+ *dest++ = isalpha(0xFF & *pos) ? tolower(0xFF & *pos) : *pos;
13034 }
13035 *dest = *pos; /* nul termination */
13036 }
13037@@ -2011,7 +2013,8 @@ netsnmp_cert_trust(SSL_CTX *ctx, netsnmp_cert *thiscert)
13038 {
13039 X509_STORE *certstore;
13040 X509 *cert;
13041-
13042+ char *fingerprint;
13043+
13044 /* ensure all needed pieces are present */
13045 netsnmp_assert_or_msgreturn(NULL != thiscert, "NULL certificate passed in",
13046 SNMPERR_GENERR);
13047@@ -2033,10 +2036,11 @@ netsnmp_cert_trust(SSL_CTX *ctx, netsnmp_cert *thiscert)
13048 SNMPERR_GENERR);
13049
13050 /* Put the certificate into the store */
13051+ fingerprint = netsnmp_openssl_cert_get_fingerprint(cert, -1);
13052 DEBUGMSGTL(("cert:trust",
13053 "putting trusted cert %p = %s in certstore %p\n", cert,
13054- netsnmp_openssl_cert_get_fingerprint(cert, -1),
13055- certstore));
13056+ fingerprint, certstore));
13057+ SNMP_FREE(fingerprint);
13058 X509_STORE_add_cert(certstore, cert);
13059
13060 return SNMPERR_SUCCESS;
13061@@ -2132,7 +2136,7 @@ _cert_find_fp(const char *fingerprint)
13062 if (NULL == fingerprint)
13063 return NULL;
13064
13065- strncpy(fp, fingerprint, sizeof(fp));
13066+ strlcpy(fp, fingerprint, sizeof(fp));
13067 netsnmp_fp_lowercase_and_strip_colon(fp);
13068
13069 /** clear search key */
13070@@ -2222,7 +2226,7 @@ _reduce_subset_dir(netsnmp_void_array *matching, const char *directory)
13071 *
13072 * so we want to backup up on directory for compares..
13073 */
13074- strncpy(dir,directory,sizeof(dir));
13075+ strlcpy(dir, directory, sizeof(dir));
13076 pos = strrchr(dir, '/');
13077 if (NULL == pos) {
13078 DEBUGMSGTL(("cert:subset:dir", "no '/' in directory %s\n", directory));
13079@@ -2690,7 +2694,7 @@ netsnmp_certToTSN_parse_common(char **line)
13080 tmp = buf;
13081 *line = read_config_read_octet_string(*line, (u_char **)&tmp, &len);
13082 tmp[len] = 0;
13083- if (!isdigit(tmp[0])) {
13084+ if (!isdigit(0xFF & tmp[0])) {
13085 netsnmp_config_error("could not parse priority");
13086 return NULL;
13087 }
13088@@ -3050,8 +3054,8 @@ netsnmp_tlstmParams_add(snmpTlstmParams *stp)
13089 stp->name));
13090
13091 if (CONTAINER_INSERT(_tlstmParams, stp) != 0) {
13092- netsnmp_tlstmParams_free(stp);
13093 snmp_log(LOG_ERR, "error inserting tlstmParams %s", stp->name);
13094+ netsnmp_tlstmParams_free(stp);
13095 return -1;
13096 }
13097
13098@@ -3260,8 +3264,8 @@ netsnmp_tlstmAddr_add(snmpTlstmAddr *entry)
13099 DEBUGMSGTL(("tlstmAddr:add", "adding entry 0x%lx %s %s\n",
13100 (u_long)entry, entry->name, entry->fingerprint));
13101 if (CONTAINER_INSERT(_tlstmAddr, entry) != 0) {
13102- netsnmp_tlstmAddr_free(entry);
13103 snmp_log(LOG_ERR, "could not insert addr %s", entry->name);
13104+ netsnmp_tlstmAddr_free(entry);
13105 return -1;
13106 }
13107
13108@@ -3314,10 +3318,7 @@ _parse_addr(const char *token, char *line)
13109 if (id_len)
13110 entry->identity = strdup(id);
13111
13112- if (netsnmp_tlstmAddr_add(entry) != 0)
13113- netsnmp_tlstmAddr_free(entry);
13114-
13115- return;
13116+ netsnmp_tlstmAddr_add(entry);
13117 }
13118
13119 static char *
13120diff --git a/snmplib/container_binary_array.c b/snmplib/container_binary_array.c
13121index 41f1d24..249a3a9 100644
13122--- a/snmplib/container_binary_array.c
13123+++ b/snmplib/container_binary_array.c
13124@@ -487,7 +487,7 @@ binary_search_for_start(netsnmp_index *val, netsnmp_container *c)
13125 void **
13126 netsnmp_binary_array_get_subset(netsnmp_container *c, void *key, int *len)
13127 {
13128- binary_array_table *t = (binary_array_table*)c->container_data;
13129+ binary_array_table *t;
13130 void **subset;
13131 int start, end;
13132 size_t i;
13133diff --git a/snmplib/data_list.c b/snmplib/data_list.c
13134index 15f2de2..505d4fc 100644
13135--- a/snmplib/data_list.c
13136+++ b/snmplib/data_list.c
13137@@ -240,9 +240,14 @@ netsnmp_register_save_list(netsnmp_data_list **datalist,
13138 const char *type, const char *token,
13139 Netsnmp_Save_List_Data *data_list_save_ptr,
13140 Netsnmp_Read_List_Data *data_list_read_ptr,
13141- Netsnmp_Free_List_Data *data_list_free_ptr) {
13142- netsnmp_data_list_saveinfo *info =
13143- SNMP_MALLOC_TYPEDEF(netsnmp_data_list_saveinfo);
13144+ Netsnmp_Free_List_Data *data_list_free_ptr)
13145+{
13146+ netsnmp_data_list_saveinfo *info;
13147+
13148+ if (!data_list_save_ptr && !data_list_read_ptr)
13149+ return;
13150+
13151+ info = SNMP_MALLOC_TYPEDEF(netsnmp_data_list_saveinfo);
13152
13153 if (!info) {
13154 snmp_log(LOG_ERR, "couldn't malloc a netsnmp_data_list_saveinfo typedef");
13155diff --git a/snmplib/dir_utils.c b/snmplib/dir_utils.c
13156index 89bba6b..cbb6d00 100644
13157--- a/snmplib/dir_utils.c
13158+++ b/snmplib/dir_utils.c
13159@@ -122,7 +122,7 @@ netsnmp_directory_container_read_some(netsnmp_container *user_container,
13160 dirname_len = 0;
13161 else {
13162 dirname_len = strlen(dirname);
13163- strncpy(path, dirname, sizeof(path));
13164+ strlcpy(path, dirname, sizeof(path));
13165 if ((dirname_len + 2) > sizeof(path)) {
13166 /** not enough room for files */
13167 closedir(dir);
13168@@ -131,7 +131,7 @@ netsnmp_directory_container_read_some(netsnmp_container *user_container,
13169 return NULL;
13170 }
13171 path[dirname_len] = '/';
13172- path[++dirname_len] = 0;
13173+ path[++dirname_len] = '\0';
13174 }
13175
13176 /** iterate over dir */
13177@@ -146,7 +146,7 @@ netsnmp_directory_container_read_some(netsnmp_container *user_container,
13178 ((file->d_name[1] == '.') && ((file->d_name[2] == 0)))))
13179 continue;
13180
13181- strncpy(&path[dirname_len], file->d_name, sizeof(path) - dirname_len);
13182+ strlcpy(&path[dirname_len], file->d_name, sizeof(path) - dirname_len);
13183 if (NULL != filter) {
13184 if (flags & NETSNMP_DIR_NSFILE_STATS) {
13185 /** use local vars for now */
13186diff --git a/snmplib/int64.c b/snmplib/int64.c
13187index 5db2375..2c71b17 100644
13188--- a/snmplib/int64.c
13189+++ b/snmplib/int64.c
13190@@ -1,9 +1,10 @@
13191-/** file: test.c - test of 64-bit integer stuff
13192-*
13193-*
13194-* 21-jan-1998: David Perkins <dperkins@dsperkins.com>
13195-*
13196-*/
13197+/**
13198+ * @file int64.c
13199+ *
13200+ * @brief Functions for 64-bit integer computations.
13201+ *
13202+ * 21-jan-1998: David Perkins <dperkins@dsperkins.com>
13203+ */
13204
13205 #include <net-snmp/net-snmp-config.h>
13206 #include <sys/types.h>
13207@@ -24,17 +25,13 @@
13208
13209 #include <net-snmp/net-snmp-features.h>
13210
13211-#define TRUE 1
13212-#define FALSE 0
13213-
13214-/** divBy10 - divide an unsigned 64-bit integer by 10
13215-*
13216-* call with:
13217-* u64 - number to be divided
13218-* pu64Q - location to store quotient
13219-* puR - location to store remainder
13220-*
13221-*/
13222+/**
13223+ * Divide an unsigned 64-bit integer by 10.
13224+ *
13225+ * @param[in] u64 Number to be divided.
13226+ * @param[out] pu64Q Quotient.
13227+ * @param[out] puR Remainder.
13228+ */
13229 void
13230 divBy10(U64 u64, U64 * pu64Q, unsigned int *puR)
13231 {
13232@@ -42,7 +39,6 @@ divBy10(U64 u64, U64 * pu64Q, unsigned int *puR)
13233 unsigned long ulQ;
13234 unsigned long ulR;
13235
13236-
13237 /*
13238 * top 16 bits
13239 */
13240@@ -78,18 +74,14 @@ divBy10(U64 u64, U64 * pu64Q, unsigned int *puR)
13241 pu64Q->low = pu64Q->low | ulQ;
13242
13243 *puR = (unsigned int) (ulR);
13244+}
13245
13246-
13247-} /* divBy10 */
13248-
13249-
13250-/** multBy10 - multiply an unsigned 64-bit integer by 10
13251-*
13252-* call with:
13253-* u64 - number to be multiplied
13254-* pu64P - location to store product
13255-*
13256-*/
13257+/**
13258+ * Multiply an unsigned 64-bit integer by 10.
13259+ *
13260+ * @param[in] u64 Number to be multiplied.
13261+ * @param[out] pu64P Product.
13262+ */
13263 void
13264 multBy10(U64 u64, U64 * pu64P)
13265 {
13266@@ -97,7 +89,6 @@ multBy10(U64 u64, U64 * pu64P)
13267 unsigned long ulP;
13268 unsigned long ulK;
13269
13270-
13271 /*
13272 * lower 16 bits
13273 */
13274@@ -129,159 +120,122 @@ multBy10(U64 u64, U64 * pu64P)
13275 ulP = (ulT * 10) + ulK;
13276 ulK = ulP >> 16;
13277 pu64P->high = (ulP & 0x0ffff) << 16 | pu64P->high;
13278+}
13279
13280-
13281-} /* multBy10 */
13282-
13283-
13284-/** incrByU16 - add an unsigned 16-bit int to an unsigned 64-bit integer
13285-*
13286-* call with:
13287-* pu64 - number to be incremented
13288-* u16 - amount to add
13289-*
13290-*/
13291+/**
13292+ * Add an unsigned 16-bit int to an unsigned 64-bit integer.
13293+ *
13294+ * @param[in,out] pu64 Number to be incremented.
13295+ * @param[in] u16 Amount to add.
13296+ *
13297+ */
13298 void
13299 incrByU16(U64 * pu64, unsigned int u16)
13300 {
13301- unsigned long ulT1;
13302- unsigned long ulT2;
13303- unsigned long ulR;
13304- unsigned long ulK;
13305-
13306-
13307- /*
13308- * lower 16 bits
13309- */
13310- ulT1 = pu64->low;
13311- ulT2 = ulT1 & 0x0ffff;
13312- ulR = ulT2 + u16;
13313- ulK = ulR >> 16;
13314- if (ulK == 0) {
13315- pu64->low = ulT1 + u16;
13316- return;
13317- }
13318-
13319- /*
13320- * next 16 bits
13321- */
13322- ulT2 = (ulT1 >> 16) & 0x0ffff;
13323- ulR = ulT2 + 1;
13324- ulK = ulR >> 16;
13325- if (ulK == 0) {
13326- pu64->low = ulT1 + u16;
13327- return;
13328- }
13329-
13330- /*
13331- * next 32 - ignore any overflow
13332- */
13333- pu64->low = (ulT1 + u16) & 0x0FFFFFFFFL;
13334- pu64->high++;
13335-#if SIZEOF_LONG != 4
13336- pu64->high &= 0xffffffff;
13337-#endif
13338-} /* incrByV16 */
13339+ incrByU32(pu64, u16);
13340+}
13341
13342+/**
13343+ * Add an unsigned 32-bit int to an unsigned 64-bit integer.
13344+ *
13345+ * @param[in,out] pu64 Number to be incremented.
13346+ * @param[in] u32 Amount to add.
13347+ *
13348+ */
13349 void
13350 incrByU32(U64 * pu64, unsigned int u32)
13351 {
13352- unsigned int tmp;
13353+ uint32_t tmp;
13354+
13355 tmp = pu64->low;
13356- pu64->low += u32;
13357-#if SIZEOF_LONG != 4
13358- pu64->low &= 0xffffffff;
13359-#endif
13360- if (pu64->low < tmp) {
13361- pu64->high++;
13362-#if SIZEOF_LONG != 4
13363- pu64->high &= 0xffffffff;
13364-#endif
13365- }
13366+ pu64->low = (uint32_t)(tmp + u32);
13367+ if (pu64->low < tmp)
13368+ pu64->high = (uint32_t)(pu64->high + 1);
13369 }
13370
13371 /**
13372- * pu64out = pu64one - pu64two
13373+ * Subtract two 64-bit numbers.
13374+ *
13375+ * @param[in] pu64one Number to start from.
13376+ * @param[in] pu64two Amount to subtract.
13377+ * @param[out] pu64out pu64one - pu64two.
13378 */
13379 void
13380 u64Subtract(const U64 * pu64one, const U64 * pu64two, U64 * pu64out)
13381 {
13382- if (pu64one->low < pu64two->low) {
13383- pu64out->low = 0xffffffff - pu64two->low + pu64one->low + 1;
13384- pu64out->high = pu64one->high - pu64two->high - 1;
13385- } else {
13386- pu64out->low = pu64one->low - pu64two->low;
13387- pu64out->high = pu64one->high - pu64two->high;
13388- }
13389+ int carry;
13390+
13391+ carry = pu64one->low < pu64two->low;
13392+ pu64out->low = (uint32_t)(pu64one->low - pu64two->low);
13393+ pu64out->high = (uint32_t)(pu64one->high - pu64two->high - carry);
13394 }
13395
13396 /**
13397- * pu64out += pu64one
13398+ * Add two 64-bit numbers.
13399+ *
13400+ * @param[in] pu64one Amount to add.
13401+ * @param[in,out] pu64out pu64out += pu64one.
13402 */
13403 void
13404 u64Incr(U64 * pu64out, const U64 * pu64one)
13405 {
13406- pu64out->high += pu64one->high;
13407-#if SIZEOF_LONG != 4
13408- pu64out->high &= 0xffffffff;
13409-#endif
13410+ pu64out->high = (uint32_t)(pu64out->high + pu64one->high);
13411 incrByU32(pu64out, pu64one->low);
13412 }
13413
13414 /**
13415- * pu64out += (pu64one - pu64two)
13416+ * Add the difference of two 64-bit numbers to a 64-bit counter.
13417+ *
13418+ * @param[in] pu64one
13419+ * @param[in] pu64two
13420+ * @param[out] pu64out pu64out += (pu64one - pu64two)
13421 */
13422 void
13423 u64UpdateCounter(U64 * pu64out, const U64 * pu64one, const U64 * pu64two)
13424 {
13425 U64 tmp;
13426+
13427 u64Subtract(pu64one, pu64two, &tmp);
13428 u64Incr(pu64out, &tmp);
13429 }
13430
13431-/**
13432- * pu64one = pu64two
13433- */
13434 netsnmp_feature_child_of(u64copy, netsnmp_unused)
13435 #ifndef NETSNMP_FEATURE_REMOVE_U64COPY
13436+/**
13437+ * Copy a 64-bit number.
13438+ *
13439+ * @param[in] pu64two Number to be copied.
13440+ * @param[out] pu64one Where to store the copy - *pu64one = *pu64two.
13441+ */
13442 void
13443 u64Copy(U64 * pu64one, const U64 * pu64two)
13444 {
13445- pu64one->high = pu64two->high;
13446- pu64one->low = pu64two->low;
13447+ *pu64one = *pu64two;
13448 }
13449 #endif /* NETSNMP_FEATURE_REMOVE_U64COPY */
13450
13451-/** zeroU64 - set an unsigned 64-bit number to zero
13452-*
13453-* call with:
13454-* pu64 - number to be zero'ed
13455-*
13456-*/
13457+/**
13458+ * Set an unsigned 64-bit number to zero.
13459+ *
13460+ * @param[in] pu64 Number to be zeroed.
13461+ */
13462 void
13463 zeroU64(U64 * pu64)
13464 {
13465 pu64->low = 0;
13466 pu64->high = 0;
13467-} /* zeroU64 */
13468-
13469+}
13470
13471-/** isZeroU64 - check if an unsigned 64-bit number is
13472-*
13473-* call with:
13474-* pu64 - number to be zero'ed
13475-*
13476-*/
13477+/**
13478+ * Check if an unsigned 64-bit number is zero.
13479+ *
13480+ * @param[in] pu64 Number to be checked.
13481+ */
13482 int
13483 isZeroU64(const U64 * pu64)
13484 {
13485-
13486- if ((pu64->low == 0) && (pu64->high == 0))
13487- return (TRUE);
13488- else
13489- return (FALSE);
13490-
13491-} /* isZeroU64 */
13492+ return pu64->low == 0 && pu64->high == 0;
13493+}
13494
13495 /**
13496 * check the old and new values of a counter64 for 32bit wrapping
13497@@ -292,7 +246,7 @@ isZeroU64(const U64 * pu64)
13498 * @param old_val
13499 * @param new_val
13500 *
13501- *@Note:
13502+ * @note
13503 * The old and new values must be be from within a time period
13504 * which would only allow the 32bit portion of the counter to
13505 * wrap once. i.e. if the 32bit portion of the counter could
13506@@ -331,16 +285,11 @@ netsnmp_c64_check_for_32bit_wrap(struct counter64 *old_val,
13507 */
13508 if (new_val->high == old_val->high) {
13509 DEBUGMSGTL(("c64:check_wrap", "32 bit wrap\n"));
13510- if (adjust) {
13511- ++new_val->high;
13512-#if SIZEOF_LONG != 4
13513- new_val->high &= 0xffffffff;
13514-#endif
13515- }
13516+ if (adjust)
13517+ new_val->high = (uint32_t)(new_val->high + 1);
13518 return 32;
13519 }
13520- else if ((new_val->high == (old_val->high + 1)) ||
13521- ((0 == new_val->high) && (0xffffffff == old_val->high))) {
13522+ else if (new_val->high == (uint32_t)(old_val->high + 1)) {
13523 DEBUGMSGTL(("c64:check_wrap", "64 bit wrap\n"));
13524 return 64;
13525 }
13526@@ -357,7 +306,7 @@ netsnmp_c64_check_for_32bit_wrap(struct counter64 *old_val,
13527 * @param need_wrap_check: pointer to integer indicating if wrap check is needed
13528 * flag may be cleared if 64 bit counter is detected
13529 *
13530- *@Note:
13531+ * @note
13532 * The old_prev_val and new_val values must be be from within a time
13533 * period which would only allow the 32bit portion of the counter to
13534 * wrap once. i.e. if the 32bit portion of the counter could
13535@@ -438,9 +387,11 @@ netsnmp_c64_check32_and_update(struct counter64 *prev_val, struct counter64 *new
13536 return 0;
13537 }
13538
13539+/** Convert an unsigned 64-bit number to ASCII. */
13540 void
13541-printU64(char *buf, /* char [I64CHARSZ+1]; */
13542- const U64 * pu64) {
13543+printU64(char *buf, /* char [I64CHARSZ+1]; */
13544+ const U64 * pu64)
13545+{
13546 U64 u64a;
13547 U64 u64b;
13548
13549@@ -448,57 +399,37 @@ printU64(char *buf, /* char [I64CHARSZ+1]; */
13550 unsigned int u;
13551 int j;
13552
13553- u64a.high = pu64->high;
13554- u64a.low = pu64->low;
13555+ u64a = *pu64;
13556 aRes[I64CHARSZ] = 0;
13557 for (j = 0; j < I64CHARSZ; j++) {
13558 divBy10(u64a, &u64b, &u);
13559 aRes[(I64CHARSZ - 1) - j] = (char) ('0' + u);
13560- u64a.high = u64b.high;
13561- u64a.low = u64b.low;
13562+ u64a = u64b;
13563 if (isZeroU64(&u64a))
13564 break;
13565 }
13566 strcpy(buf, &aRes[(I64CHARSZ - 1) - j]);
13567 }
13568
13569+/** Convert a signed 64-bit number to ASCII. */
13570 void
13571-printI64(char *buf, /* char [I64CHARSZ+1]; */
13572- const U64 * pu64) {
13573+printI64(char *buf, /* char [I64CHARSZ+1]; */
13574+ const U64 * pu64)
13575+{
13576 U64 u64a;
13577- U64 u64b;
13578-
13579- char aRes[I64CHARSZ + 1];
13580- unsigned int u;
13581- int j, sign = 0;
13582
13583 if (pu64->high & 0x80000000) {
13584- u64a.high = ~pu64->high;
13585- u64a.low = ~pu64->low;
13586- sign = 1;
13587+ u64a.high = (uint32_t) ~pu64->high;
13588+ u64a.low = (uint32_t) ~pu64->low;
13589 incrByU32(&u64a, 1); /* bit invert and incr by 1 to print 2s complement */
13590+ buf[0] = '-';
13591+ printU64(buf + 1, &u64a);
13592 } else {
13593- u64a.high = pu64->high;
13594- u64a.low = pu64->low;
13595- }
13596-
13597- aRes[I64CHARSZ] = 0;
13598- for (j = 0; j < I64CHARSZ; j++) {
13599- divBy10(u64a, &u64b, &u);
13600- aRes[(I64CHARSZ - 1) - j] = (char) ('0' + u);
13601- u64a.high = u64b.high;
13602- u64a.low = u64b.low;
13603- if (isZeroU64(&u64a))
13604- break;
13605- }
13606- if (sign == 1) {
13607- aRes[(I64CHARSZ - 1) - j - 1] = '-';
13608- strcpy(buf, &aRes[(I64CHARSZ - 1) - j - 1]);
13609- return;
13610+ printU64(buf, pu64);
13611 }
13612- strcpy(buf, &aRes[(I64CHARSZ - 1) - j]);
13613 }
13614
13615+/** Convert a signed 64-bit integer from ASCII to U64. */
13616 int
13617 read64(U64 * i64, const char *str)
13618 {
13619@@ -517,75 +448,14 @@ read64(U64 * i64, const char *str)
13620 ok = 1;
13621 u = *str - '0';
13622 multBy10(*i64, &i64p);
13623- memcpy(i64, &i64p, sizeof(i64p));
13624+ *i64 = i64p;
13625 incrByU16(i64, u);
13626 str++;
13627 }
13628 if (sign) {
13629- i64->high = ~i64->high;
13630- i64->low = ~i64->low;
13631+ i64->high = (uint32_t) ~i64->high;
13632+ i64->low = (uint32_t) ~i64->low;
13633 incrByU16(i64, 1);
13634 }
13635 return ok;
13636 }
13637-
13638-
13639-
13640-
13641-#ifdef TESTING
13642-void
13643-main(int argc, char *argv[])
13644-{
13645- int i;
13646- int j;
13647- int l;
13648- unsigned int u;
13649- U64 u64a;
13650- U64 u64b;
13651-#define MXSZ 20
13652- char aRes[MXSZ + 1];
13653-
13654-
13655- if (argc < 2) {
13656- printf("This program takes numbers from the command line\n"
13657- "and prints them out.\n" "Usage: test <unsignedInt>...\n");
13658- exit(1);
13659- }
13660-
13661- aRes[MXSZ] = 0;
13662-
13663- for (i = 1; i < argc; i++) {
13664- l = strlen(argv[i]);
13665- zeroU64(&u64a);
13666- for (j = 0; j < l; j++) {
13667- if (!isdigit(argv[i][j])) {
13668- printf("Argument is not a number \"%s\"\n", argv[i]);
13669- exit(1);
13670- }
13671- u = argv[i][j] - '0';
13672- multBy10(u64a, &u64b);
13673- u64a = u64b;
13674- incrByU16(&u64a, u);
13675- }
13676-
13677- printf("number \"%s\" in hex is '%08x%08x'h\n",
13678- argv[i], u64a.high, u64a.low);
13679-
13680- printf("number is \"%s\"\n", printU64(&u64a));
13681- for (j = 0; j < MXSZ; j++) {
13682- divBy10(u64a, &u64b, &u);
13683- aRes[(MXSZ - 1) - j] = (char) ('0' + u);
13684- u64a = u64b;
13685- if (isZeroU64(&u64a))
13686- break;
13687- }
13688-
13689- printf("number is \"%s\"\n", &aRes[(MXSZ - 1) - j]);
13690- }
13691- exit(0);
13692-} /* main */
13693-#endif /* TESTING */
13694-
13695-/*
13696- * file: test.c
13697- */
13698diff --git a/snmplib/keytools.c b/snmplib/keytools.c
13699index 810a063..0faa0de 100644
13700--- a/snmplib/keytools.c
13701+++ b/snmplib/keytools.c
13702@@ -118,13 +118,11 @@ generate_Ku(const oid * hashtype, u_int hashtype_len,
13703 u_char buf[USM_LENGTH_KU_HASHBLOCK], *bufp;
13704
13705 #ifdef NETSNMP_USE_OPENSSL
13706- EVP_MD_CTX *ctx = (EVP_MD_CTX *)malloc(sizeof(EVP_MD_CTX));
13707- unsigned int tmp_len;
13708+ EVP_MD_CTX *ctx = NULL;
13709 #elif NETSNMP_USE_INTERNAL_CRYPTO
13710 SHA_CTX csha1;
13711 MD5_CTX cmd5;
13712 char cryptotype = 0;
13713- unsigned int tmp_len;
13714 #define TYPE_MD5 1
13715 #define TYPE_SHA1 2
13716 #else
13717@@ -151,6 +149,12 @@ generate_Ku(const oid * hashtype, u_int hashtype_len,
13718 */
13719 #ifdef NETSNMP_USE_OPENSSL
13720
13721+#ifdef HAVE_EVP_MD_CTX_CREATE
13722+ ctx = EVP_MD_CTX_create();
13723+#else
13724+ ctx = malloc(sizeof(*ctx));
13725+ EVP_MD_CTX_init(ctx);
13726+#endif
13727 #ifndef NETSNMP_DISABLE_MD5
13728 if (ISTRANSFORM(hashtype, HMACMD5Auth))
13729 EVP_DigestInit(ctx, EVP_md5());
13730@@ -158,10 +162,8 @@ generate_Ku(const oid * hashtype, u_int hashtype_len,
13731 #endif
13732 if (ISTRANSFORM(hashtype, HMACSHA1Auth))
13733 EVP_DigestInit(ctx, EVP_sha1());
13734- else {
13735- free(ctx);
13736- return (SNMPERR_GENERR);
13737- }
13738+ else
13739+ QUITFUN(SNMPERR_GENERR, generate_Ku_quit);
13740 #elif NETSNMP_USE_INTERNAL_CRYPTO
13741 #ifndef NETSNMP_DISABLE_MD5
13742 if (ISTRANSFORM(hashtype, HMACMD5Auth)) {
13743@@ -205,14 +207,17 @@ generate_Ku(const oid * hashtype, u_int hashtype_len,
13744 }
13745
13746 #ifdef NETSNMP_USE_OPENSSL
13747+ {
13748+ unsigned int tmp_len;
13749+
13750 tmp_len = *kulen;
13751 EVP_DigestFinal(ctx, (unsigned char *) Ku, &tmp_len);
13752 *kulen = tmp_len;
13753 /*
13754 * what about free()
13755 */
13756+ }
13757 #elif NETSNMP_USE_INTERNAL_CRYPTO
13758- tmp_len = *kulen;
13759 if (TYPE_SHA1 == cryptotype) {
13760 SHA1_Final(Ku, &csha1);
13761 } else {
13762@@ -248,7 +253,14 @@ generate_Ku(const oid * hashtype, u_int hashtype_len,
13763 generate_Ku_quit:
13764 memset(buf, 0, sizeof(buf));
13765 #ifdef NETSNMP_USE_OPENSSL
13766- free(ctx);
13767+ if (ctx) {
13768+#ifdef HAVE_EVP_MD_CTX_DESTROY
13769+ EVP_MD_CTX_destroy(ctx);
13770+#else
13771+ EVP_MD_CTX_cleanup(ctx);
13772+ free(ctx);
13773+#endif
13774+ }
13775 #endif
13776 return rval;
13777
13778@@ -638,7 +650,8 @@ decode_keychange(const oid * hashtype, u_int hashtype_len,
13779
13780 decode_keychange_quit:
13781 if (rval != SNMPERR_SUCCESS) {
13782- memset(newkey, 0, properlength);
13783+ if (newkey)
13784+ memset(newkey, 0, properlength);
13785 }
13786 memset(tmp_buf, 0, SNMP_MAXBUF);
13787 SNMP_FREE(tmpbuf);
13788diff --git a/snmplib/large_fd_set.c b/snmplib/large_fd_set.c
13789index 1176a5b..32f57b3 100644
13790--- a/snmplib/large_fd_set.c
13791+++ b/snmplib/large_fd_set.c
13792@@ -19,7 +19,7 @@
13793 #include <net-snmp/library/large_fd_set.h>
13794
13795
13796-#if ! defined(cygwin) && defined(HAVE_WINSOCK_H)
13797+#if !defined(cygwin) && defined(HAVE_WINSOCK_H)
13798
13799 void
13800 netsnmp_large_fd_setfd(SOCKET fd, netsnmp_large_fd_set * fdset)
13801@@ -39,7 +39,7 @@ netsnmp_large_fd_setfd(SOCKET fd, netsnmp_large_fd_set * fdset)
13802 if (i == fdset->lfs_set.fd_count
13803 && fdset->lfs_set.fd_count < fdset->lfs_setsize) {
13804 fdset->lfs_set.fd_count++;
13805- fdset->lfs_set.fd_array[i] = (fd);
13806+ fdset->lfs_set.fd_array[i] = fd;
13807 }
13808 }
13809
13810@@ -51,7 +51,7 @@ netsnmp_large_fd_clr(SOCKET fd, netsnmp_large_fd_set * fdset)
13811 netsnmp_assert(fd != INVALID_SOCKET);
13812
13813 for (i = 0; i < fdset->lfs_set.fd_count; i++) {
13814- if (fdset->lfs_set.fd_array[i] == (fd)) {
13815+ if (fdset->lfs_set.fd_array[i] == fd) {
13816 while (i < fdset->lfs_set.fd_count - 1) {
13817 fdset->lfs_set.fd_array[i] =
13818 fdset->lfs_set.fd_array[i + 1];
13819@@ -95,7 +95,7 @@ netsnmp_large_fd_clr(int fd, netsnmp_large_fd_set * fdset)
13820 {
13821 netsnmp_assert(fd >= 0);
13822
13823- if (fd < (int)fdset->lfs_setsize)
13824+ if ((unsigned)fd < fdset->lfs_setsize)
13825 FD_CLR(fd, fdset->lfs_setptr);
13826 }
13827
13828@@ -104,7 +104,7 @@ netsnmp_large_fd_is_set(int fd, netsnmp_large_fd_set * fdset)
13829 {
13830 netsnmp_assert(fd >= 0);
13831
13832- return fd < (int)fdset->lfs_setsize && FD_ISSET(fd, fdset->lfs_setptr);
13833+ return (unsigned)fd < fdset->lfs_setsize && FD_ISSET(fd, fdset->lfs_setptr);
13834 }
13835
13836 #endif
13837@@ -114,6 +114,9 @@ netsnmp_large_fd_set_init(netsnmp_large_fd_set * fdset, int setsize)
13838 {
13839 fdset->lfs_setsize = 0;
13840 fdset->lfs_setptr = NULL;
13841+#if !defined(cygwin) && defined(HAVE_WINSOCK_H)
13842+ fdset->lfs_set.fd_count = 0;
13843+#endif
13844 netsnmp_large_fd_set_resize(fdset, setsize);
13845 }
13846
13847@@ -135,25 +138,32 @@ netsnmp_large_fd_set_select(int numfds, netsnmp_large_fd_set *readfds,
13848 /* Array representation: no resizing is necessary. */
13849 #endif
13850
13851- return select(numfds, readfds->lfs_setptr, writefds->lfs_setptr,
13852- exceptfds->lfs_setptr, timeout);
13853+ return select(numfds,
13854+ readfds ? readfds->lfs_setptr : NULL,
13855+ writefds ? writefds->lfs_setptr : NULL,
13856+ exceptfds ? exceptfds->lfs_setptr : NULL,
13857+ timeout);
13858 }
13859
13860-void
13861+int
13862 netsnmp_large_fd_set_resize(netsnmp_large_fd_set * fdset, int setsize)
13863 {
13864 int fd_set_bytes;
13865
13866 if (fdset->lfs_setsize == setsize)
13867- return;
13868+ goto success;
13869
13870 if (setsize > FD_SETSIZE) {
13871 fd_set_bytes = NETSNMP_FD_SET_BYTES(setsize);
13872- if (fdset->lfs_setsize > FD_SETSIZE)
13873- fdset->lfs_setptr = (fd_set *)realloc(fdset->lfs_setptr, fd_set_bytes);
13874- else {
13875- fdset->lfs_setptr = (fd_set *)malloc(fd_set_bytes);
13876- *fdset->lfs_setptr = fdset->lfs_set;
13877+ if (fdset->lfs_setsize > FD_SETSIZE) {
13878+ fdset->lfs_setptr = realloc(fdset->lfs_setptr, fd_set_bytes);
13879+ if (!fdset->lfs_setptr)
13880+ goto out_of_mem;
13881+ } else {
13882+ fdset->lfs_setptr = malloc(fd_set_bytes);
13883+ if (!fdset->lfs_setptr)
13884+ goto out_of_mem;
13885+ *fdset->lfs_setptr = fdset->lfs_set;
13886 }
13887 } else {
13888 if (fdset->lfs_setsize > FD_SETSIZE) {
13889@@ -163,20 +173,33 @@ netsnmp_large_fd_set_resize(netsnmp_large_fd_set * fdset, int setsize)
13890 fdset->lfs_setptr = &fdset->lfs_set;
13891 }
13892
13893-#if ! (! defined(cygwin) && defined(HAVE_WINSOCK_H))
13894+#if defined(cygwin) || !defined(HAVE_WINSOCK_H)
13895 {
13896 int i;
13897
13898- /*
13899- * Unix: clear the file descriptors defined in the resized *fdset
13900- * but that were not defined in the original *fdset.
13901- */
13902- for (i = fdset->lfs_setsize; i < setsize; i++)
13903- FD_CLR(i, fdset->lfs_setptr);
13904+ /*
13905+ * Unix: when enlarging, clear the file descriptors defined in the
13906+ * resized *fdset but that were not defined in the original *fdset.
13907+ */
13908+ for (i = fdset->lfs_setsize; i < setsize; i++)
13909+ FD_CLR(i, fdset->lfs_setptr);
13910 }
13911 #endif
13912
13913 fdset->lfs_setsize = setsize;
13914+#if !defined(cygwin) && defined(HAVE_WINSOCK_H)
13915+ if (setsize < fdset->lfs_set.fd_count)
13916+ fdset->lfs_set.fd_count = setsize;
13917+#endif
13918+success:
13919+ return 1;
13920+
13921+out_of_mem:
13922+ fdset->lfs_setsize = 0;
13923+#if !defined(cygwin) && defined(HAVE_WINSOCK_H)
13924+ fdset->lfs_set.fd_count = 0;
13925+#endif
13926+ return 0;
13927 }
13928
13929 void
13930@@ -207,13 +230,13 @@ netsnmp_copy_large_fd_set_to_fd_set(fd_set * dst,
13931
13932 *dst = *src->lfs_setptr;
13933
13934-#if ! (! defined(cygwin) && defined(HAVE_WINSOCK_H))
13935+#if !(!defined(cygwin) && defined(HAVE_WINSOCK_H))
13936 {
13937 int i;
13938
13939- /* Unix: clear any file descriptors defined in *dst but not in *src. */
13940- for (i = src->lfs_setsize; i < FD_SETSIZE; ++i)
13941- FD_CLR(i, dst);
13942+ /* Unix: clear any file descriptors defined in *dst but not in *src. */
13943+ for (i = src->lfs_setsize; i < FD_SETSIZE; ++i)
13944+ FD_CLR(i, dst);
13945 }
13946 #endif
13947
13948diff --git a/snmplib/mib.c b/snmplib/mib.c
13949index 7c8af9c..549d206 100644
13950--- a/snmplib/mib.c
13951+++ b/snmplib/mib.c
13952@@ -462,7 +462,7 @@ sprint_realloc_octet_string(u_char ** buf, size_t * buf_len,
13953 const char *saved_hint = hint;
13954 int hex = 0, x = 0;
13955 u_char *cp;
13956- int output_format, len_needed;
13957+ int output_format, cnt;
13958
13959 if ((var->type != ASN_OCTET_STR) &&
13960 (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {
13961@@ -571,18 +571,11 @@ sprint_realloc_octet_string(u_char ** buf, size_t * buf_len,
13962 break;
13963 case 't': /* new in rfc 3411 */
13964 case 'a':
13965- /* A string hint gives the max size - we may not need this much */
13966- len_needed = SNMP_MIN( width, ecp-cp );
13967- while ((*out_len + len_needed + 1) >= *buf_len) {
13968- if (!(allow_realloc && snmp_realloc(buf, buf_len))) {
13969- return 0;
13970- }
13971- }
13972- for (x = 0; x < width && cp < ecp; x++) {
13973- *(*buf + *out_len) = *cp++;
13974- (*out_len)++;
13975- }
13976- *(*buf + *out_len) = '\0';
13977+ cnt = SNMP_MIN(width, ecp - cp);
13978+ if (!sprint_realloc_asciistring(buf, buf_len, out_len,
13979+ allow_realloc, cp, cnt))
13980+ return 0;
13981+ cp += cnt;
13982 break;
13983 default:
13984 *out_len = saved_out_len;
13985@@ -2800,6 +2793,8 @@ netsnmp_mibindex_load( void )
13986 get_persistent_directory(), i );
13987 tmpbuf[sizeof(tmpbuf)-1] = 0;
13988 fp = fopen( tmpbuf, "r" );
13989+ if (!fp)
13990+ continue;
13991 cp = fgets( tmpbuf2, sizeof(tmpbuf2), fp );
13992 if ( !cp ) {
13993 DEBUGMSGTL(("mibindex", "Empty MIB index (%d)\n", i));
13994@@ -3057,14 +3052,11 @@ read_objid(const char *input, oid * output, size_t * out_len)
13995 * get past leading '.', append '.' to Prefix.
13996 */
13997 if (*Prefix == '.')
13998- strncpy(buf, Prefix + 1, sizeof(buf)-1);
13999+ strlcpy(buf, Prefix + 1, sizeof(buf));
14000 else
14001- strncpy(buf, Prefix, sizeof(buf)-1);
14002- buf[ sizeof(buf)-1 ] = 0;
14003- strcat(buf, ".");
14004- buf[ sizeof(buf)-1 ] = 0;
14005- strncat(buf, input, sizeof(buf)-strlen(buf));
14006- buf[ sizeof(buf)-1 ] = 0;
14007+ strlcpy(buf, Prefix, sizeof(buf));
14008+ strlcat(buf, ".", sizeof(buf));
14009+ strlcat(buf, input, sizeof(buf));
14010 input = buf;
14011 }
14012 #endif /* NETSNMP_DISABLE_MIB_LOADING */
14013@@ -5106,8 +5098,7 @@ print_tree_node(u_char ** buf, size_t * buf_len,
14014 else
14015 if (!snmp_cstrcat(buf, buf_len, out_len, allow_realloc, ", "))
14016 return 0;
14017- snprintf(str, sizeof(str), "%s", vp->vblabel);
14018- str[ sizeof(str)-1 ] = 0;
14019+ strlcpy(str, vp->vblabel, sizeof(str));
14020 len = strlen(str);
14021 if (pos + len + 2 > width) {
14022 if (!snmp_cstrcat(buf, buf_len, out_len, allow_realloc,
14023@@ -5720,8 +5711,7 @@ get_node(const char *name, oid * objid, size_t * objidlen)
14024 module = (char *) malloc((size_t) (cp - name + 1));
14025 if (!module)
14026 return SNMPERR_GENERR;
14027- memcpy(module, name, (size_t) (cp - name));
14028- module[cp - name] = 0;
14029+ sprintf(module, "%.*s", (int) (cp - name), name);
14030 cp++; /* cp now point to the subidentifier */
14031 if (*cp == ':')
14032 cp++;
14033diff --git a/snmplib/oid_stash.c b/snmplib/oid_stash.c
14034index 02c53a9..8a79897 100644
14035--- a/snmplib/oid_stash.c
14036+++ b/snmplib/oid_stash.c
14037@@ -305,6 +305,8 @@ netsnmp_oid_stash_get_data(netsnmp_oid_stash_node *root,
14038 }
14039 #endif /* NETSNMP_FEATURE_REMOVE_OID_STASH_GET_DATA */
14040
14041+netsnmp_feature_child_of(oid_stash_store_all, oid_stash_all)
14042+#ifndef NETSNMP_FEATURE_REMOVE_OID_STASH_STORE_ALL
14043 /** a wrapper around netsnmp_oid_stash_store for use with a snmp_alarm.
14044 * when calling snmp_alarm, you can list this as a callback. The
14045 * clientarg should be a pointer to a netsnmp_oid_stash_save_info
14046@@ -316,8 +318,6 @@ netsnmp_oid_stash_get_data(netsnmp_oid_stash_node *root,
14047 * @param serverarg
14048 * @param clientarg A pointer to a netsnmp_oid_stash_save_info structure.
14049 */
14050-netsnmp_feature_child_of(oid_stash_store_all, oid_stash_all)
14051-#ifndef NETSNMP_FEATURE_REMOVE_OID_STASH_STORE_ALL
14052 int
14053 netsnmp_oid_stash_store_all(int majorID, int minorID,
14054 void *serverarg, void *clientarg) {
14055diff --git a/snmplib/openssl/openssl_cfb128.c b/snmplib/openssl/openssl_cfb128.c
14056index 7e78905..5e0bc1e 100644
14057--- a/snmplib/openssl/openssl_cfb128.c
14058+++ b/snmplib/openssl/openssl_cfb128.c
14059@@ -98,7 +98,7 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
14060 (*block)(ivec, ivec, key);
14061 for (n=0; n<16; n+=sizeof(size_t)) {
14062 *(size_t*)(out+n) =
14063- *(size_t*)(ivec+n) ^= *(size_t*)(in+n);
14064+ *(size_t*)(ivec+n) ^= *(const size_t*)(in+n);
14065 }
14066 len -= 16;
14067 out += 16;
14068@@ -142,8 +142,8 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
14069 while (len>=16) {
14070 (*block)(ivec, ivec, key);
14071 for (n=0; n<16; n+=sizeof(size_t)) {
14072- size_t t = *(size_t*)(in+n);
14073- *(size_t*)(out+n) = *(size_t*)(ivec+n) ^ t;
14074+ size_t t = *(const size_t*)(in+n);
14075+ *(size_t*)(out+n) = *(const size_t*)(ivec+n) ^ t;
14076 *(size_t*)(ivec+n) = t;
14077 }
14078 len -= 16;
14079diff --git a/snmplib/parse.c b/snmplib/parse.c
14080index bfe5cad..1114586 100644
14081--- a/snmplib/parse.c
14082+++ b/snmplib/parse.c
14083@@ -2021,11 +2021,19 @@ parse_objectid(FILE * fp, char *name)
14084 * The name for this node is the label for this entry
14085 */
14086 np->label = strdup(name);
14087+ if (np->label == NULL) {
14088+ SNMP_FREE(np->parent);
14089+ SNMP_FREE(np);
14090+ return (NULL);
14091+ }
14092 } else {
14093 if (!nop->label) {
14094 nop->label = (char *) malloc(20 + ANON_LEN);
14095- if (nop->label == NULL)
14096+ if (nop->label == NULL) {
14097+ SNMP_FREE(np->parent);
14098+ SNMP_FREE(np);
14099 return (NULL);
14100+ }
14101 sprintf(nop->label, "%s%d", ANON, anonymous++);
14102 }
14103 np->label = strdup(nop->label);
14104@@ -2694,29 +2702,12 @@ parse_objecttype(FILE * fp, char *name)
14105 break;
14106 else if (type == LEFTBRACKET)
14107 level++;
14108- if (type == QUOTESTRING) {
14109- if (strlen(defbuf)+2 < sizeof(defbuf)) {
14110- defbuf[ strlen(defbuf)+2 ] = 0;
14111- defbuf[ strlen(defbuf)+1 ] = '"';
14112- defbuf[ strlen(defbuf) ] = '\\';
14113- }
14114- defbuf[ sizeof(defbuf)-1 ] = 0;
14115- }
14116- strncat(defbuf, quoted_string_buffer,
14117- sizeof(defbuf)-strlen(defbuf)-1);
14118- defbuf[ sizeof(defbuf)-1 ] = 0;
14119- if (type == QUOTESTRING) {
14120- if (strlen(defbuf)+2 < sizeof(defbuf)) {
14121- defbuf[ strlen(defbuf)+2 ] = 0;
14122- defbuf[ strlen(defbuf)+1 ] = '"';
14123- defbuf[ strlen(defbuf) ] = '\\';
14124- }
14125- defbuf[ sizeof(defbuf)-1 ] = 0;
14126- }
14127- if (strlen(defbuf)+1 < sizeof(defbuf)) {
14128- defbuf[ strlen(defbuf)+1 ] = 0;
14129- defbuf[ strlen(defbuf) ] = ' ';
14130- }
14131+ if (type == QUOTESTRING)
14132+ strlcat(defbuf, "\\\"", sizeof(defbuf));
14133+ strlcat(defbuf, quoted_string_buffer, sizeof(defbuf));
14134+ if (type == QUOTESTRING)
14135+ strlcat(defbuf, "\\\"", sizeof(defbuf));
14136+ strlcat(defbuf, " ", sizeof(defbuf));
14137 }
14138
14139 if (type != RIGHTBRACKET) {
14140@@ -3910,6 +3901,9 @@ read_module_internal(const char *name)
14141 snmp_log_perror(mp->file);
14142 return rval;
14143 }
14144+#ifdef HAVE_FLOCKFILE
14145+ flockfile(fp);
14146+#endif
14147 mp->no_imports = 0; /* Note that we've read the file */
14148 File = mp->file;
14149 mibLine = 1;
14150@@ -3918,6 +3912,9 @@ read_module_internal(const char *name)
14151 * Parse the file
14152 */
14153 np = parse(fp, NULL);
14154+#ifdef HAVE_FUNLOCKFILE
14155+ funlockfile(fp);
14156+#endif
14157 fclose(fp);
14158 File = oldFile;
14159 mibLine = oldLine;
14160@@ -4400,8 +4397,7 @@ parse(FILE * fp, struct node *root)
14161 case ENDOFFILE:
14162 continue;
14163 default:
14164- strncpy(name, token, sizeof(name));
14165- name[sizeof(name)-1] = '\0';
14166+ strlcpy(name, token, sizeof(name));
14167 type = get_token(fp, token, MAXTOKEN);
14168 nnp = NULL;
14169 if (type == MACRO) {
14170@@ -4419,8 +4415,7 @@ parse(FILE * fp, struct node *root)
14171 print_error(name, "is a reserved word", lasttype);
14172 continue; /* see if we can parse the rest of the file */
14173 }
14174- strncpy(name, token, sizeof(name));
14175- name[sizeof(name)-1] = '\0';
14176+ strlcpy(name, token, sizeof(name));
14177 type = get_token(fp, token, MAXTOKEN);
14178 nnp = NULL;
14179
14180@@ -4610,6 +4605,21 @@ is_labelchar(int ich)
14181 return 0;
14182 }
14183
14184+/**
14185+ * Read a single character from a file. Assumes that the caller has invoked
14186+ * flockfile(). Uses fgetc_unlocked() instead of getc() since the former is
14187+ * implemented as an inline function in glibc. See also bug 3447196
14188+ * (http://sourceforge.net/tracker/?func=detail&aid=3447196&group_id=12694&atid=112694).
14189+ */
14190+static int netsnmp_getc(FILE *stream)
14191+{
14192+#ifdef HAVE_FGETC_UNLOCKED
14193+ return fgetc_unlocked(stream);
14194+#else
14195+ return getc(stream);
14196+#endif
14197+}
14198+
14199 /*
14200 * Parses a token from the file. The type of the token parsed is returned,
14201 * and the text is placed in the string pointed to by token.
14202@@ -4629,7 +4639,7 @@ get_token(FILE * fp, char *token, int maxtlen)
14203 * skip all white space
14204 */
14205 do {
14206- ch = getc(fp);
14207+ ch = netsnmp_getc(fp);
14208 if (ch == '\n')
14209 mibLine++;
14210 }
14211@@ -4643,7 +4653,7 @@ get_token(FILE * fp, char *token, int maxtlen)
14212 return parseQuoteString(fp, token, maxtlen);
14213 case '\'': /* binary or hex constant */
14214 seenSymbols = bdigits;
14215- while ((ch = getc(fp)) != EOF && ch != '\'') {
14216+ while ((ch = netsnmp_getc(fp)) != EOF && ch != '\'') {
14217 switch (seenSymbols) {
14218 case bdigits:
14219 if (ch == '0' || ch == '1')
14220@@ -4662,7 +4672,7 @@ get_token(FILE * fp, char *token, int maxtlen)
14221 if (ch == '\'') {
14222 unsigned long val = 0;
14223 char *run = token + 1;
14224- ch = getc(fp);
14225+ ch = netsnmp_getc(fp);
14226 switch (ch) {
14227 case EOF:
14228 return ENDOFFILE;
14229@@ -4721,25 +4731,25 @@ get_token(FILE * fp, char *token, int maxtlen)
14230 case '|':
14231 return BAR;
14232 case '.':
14233- ch_next = getc(fp);
14234+ ch_next = netsnmp_getc(fp);
14235 if (ch_next == '.')
14236 return RANGE;
14237 ungetc(ch_next, fp);
14238 return LABEL;
14239 case ':':
14240- ch_next = getc(fp);
14241+ ch_next = netsnmp_getc(fp);
14242 if (ch_next != ':') {
14243 ungetc(ch_next, fp);
14244 return LABEL;
14245 }
14246- ch_next = getc(fp);
14247+ ch_next = netsnmp_getc(fp);
14248 if (ch_next != '=') {
14249 ungetc(ch_next, fp);
14250 return LABEL;
14251 }
14252 return EQUALS;
14253 case '-':
14254- ch_next = getc(fp);
14255+ ch_next = netsnmp_getc(fp);
14256 if (ch_next == '-') {
14257 if (netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID,
14258 NETSNMP_DS_LIB_MIB_COMMENT_TERM)) {
14259@@ -4747,7 +4757,7 @@ get_token(FILE * fp, char *token, int maxtlen)
14260 * Treat the rest of this line as a comment.
14261 */
14262 while ((ch_next != EOF) && (ch_next != '\n'))
14263- ch_next = getc(fp);
14264+ ch_next = netsnmp_getc(fp);
14265 } else {
14266 /*
14267 * Treat the rest of the line or until another '--' as a comment
14268@@ -4756,11 +4766,11 @@ get_token(FILE * fp, char *token, int maxtlen)
14269 * (this is the "technically" correct way to parse comments)
14270 */
14271 ch = ' ';
14272- ch_next = getc(fp);
14273+ ch_next = netsnmp_getc(fp);
14274 while (ch_next != EOF && ch_next != '\n' &&
14275 (ch != '-' || ch_next != '-')) {
14276 ch = ch_next;
14277- ch_next = getc(fp);
14278+ ch_next = netsnmp_getc(fp);
14279 }
14280 }
14281 if (ch_next == EOF)
14282@@ -4770,6 +4780,7 @@ get_token(FILE * fp, char *token, int maxtlen)
14283 return get_token(fp, token, maxtlen);
14284 }
14285 ungetc(ch_next, fp);
14286+ /* fallthrough */
14287 default:
14288 /*
14289 * Accumulate characters until end of token is found. Then attempt to
14290@@ -4780,7 +4791,7 @@ get_token(FILE * fp, char *token, int maxtlen)
14291 return LABEL;
14292 hash += tolower(ch);
14293 more:
14294- while (is_labelchar(ch_next = getc(fp))) {
14295+ while (is_labelchar(ch_next = netsnmp_getc(fp))) {
14296 hash += tolower(ch_next);
14297 if (cp - token < maxtlen - 1)
14298 *cp++ = ch_next;
14299@@ -4799,7 +4810,7 @@ get_token(FILE * fp, char *token, int maxtlen)
14300 if (tp) {
14301 if (tp->token != CONTINUE)
14302 return (tp->token);
14303- while (isspace((ch_next = getc(fp))))
14304+ while (isspace((ch_next = netsnmp_getc(fp))))
14305 if (ch_next == '\n')
14306 mibLine++;
14307 if (ch_next == EOF)
14308@@ -4846,7 +4857,10 @@ add_mibfile(const char* tmpstr, const char* d_name, FILE *ip )
14309 tmpstr));
14310 mibLine = 1;
14311 File = tmpstr;
14312- get_token(fp, token, MAXTOKEN);
14313+ if (get_token(fp, token, MAXTOKEN) != LABEL) {
14314+ fclose(fp);
14315+ return 1;
14316+ }
14317 /*
14318 * simple test for this being a MIB
14319 */
14320@@ -4984,7 +4998,11 @@ read_mib(const char *filename)
14321 mibLine = 1;
14322 File = filename;
14323 DEBUGMSGTL(("parse-mibs", "Parsing file: %s...\n", filename));
14324- get_token(fp, token, MAXTOKEN);
14325+ if (get_token(fp, token, MAXTOKEN) != LABEL) {
14326+ snmp_log(LOG_ERR, "Failed to parse MIB file %s\n", filename);
14327+ fclose(fp);
14328+ return NULL;
14329+ }
14330 fclose(fp);
14331 new_module(token, filename);
14332 (void) netsnmp_read_module(token);
14333@@ -5055,7 +5073,7 @@ parseQuoteString(FILE * fp, char *token, int maxtlen)
14334 int too_long = 0;
14335 char *token_start = token;
14336
14337- for (ch = getc(fp); ch != EOF; ch = getc(fp)) {
14338+ for (ch = netsnmp_getc(fp); ch != EOF; ch = netsnmp_getc(fp)) {
14339 if (ch == '\r')
14340 continue;
14341 if (ch == '\n') {
14342diff --git a/snmplib/read_config.c b/snmplib/read_config.c
14343index 5c5268b..2443230 100644
14344--- a/snmplib/read_config.c
14345+++ b/snmplib/read_config.c
14346@@ -180,8 +180,8 @@ internal_register_config_handler(const char *type_param,
14347 struct config_line *ltmp2 = NULL;
14348 char buf[STRINGMAX];
14349 char *cptr = buf;
14350- strncpy(buf, type, STRINGMAX - 1);
14351- buf[STRINGMAX - 1] = '\0';
14352+
14353+ strlcpy(buf, type, STRINGMAX);
14354 while (cptr) {
14355 char* c = cptr;
14356 cptr = strchr(cptr, ':');
14357@@ -366,8 +366,8 @@ unregister_config_handler(const char *type_param, const char *token)
14358 if (strchr(type, ':')) {
14359 char buf[STRINGMAX];
14360 char *cptr = buf;
14361- strncpy(buf, type, STRINGMAX - 1);
14362- buf[STRINGMAX - 1] = '\0';
14363+
14364+ strlcpy(buf, type, STRINGMAX);
14365 while (cptr) {
14366 char* c = cptr;
14367 cptr = strchr(cptr, ':');
14368@@ -582,10 +582,13 @@ snmp_config_when(char *line, int when)
14369 return SNMPERR_GENERR;
14370 }
14371
14372- strncpy(buf, line, STRINGMAX);
14373- buf[STRINGMAX - 1] = '\0';
14374+ strlcpy(buf, line, STRINGMAX);
14375 cptr = strtok_r(buf, SNMP_CONFIG_DELIMETERS, &st);
14376- if (cptr && cptr[0] == '[') {
14377+ if (!cptr) {
14378+ netsnmp_config_warn("Wrong format: %s", line);
14379+ return SNMPERR_GENERR;
14380+ }
14381+ if (cptr[0] == '[') {
14382 if (cptr[strlen(cptr) - 1] != ']') {
14383 netsnmp_config_error("no matching ']' for type %s.", cptr + 1);
14384 return SNMPERR_GENERR;
14385@@ -887,15 +890,15 @@ read_config(const char *filename,
14386 continue;
14387 }
14388 if ( cptr[0] == '/' ) {
14389- strncpy(fname, cptr, SNMP_MAXPATH);
14390- fname[SNMP_MAXPATH-1]='\0';
14391+ strlcpy(fname, cptr, SNMP_MAXPATH);
14392 } else {
14393- strncpy(fname, filename, SNMP_MAXPATH);
14394- fname[SNMP_MAXPATH-1]='\0';
14395+ strlcpy(fname, filename, SNMP_MAXPATH);
14396 cp = strrchr(fname, '/');
14397- *(++cp) = '\0';
14398- strncat(fname, cptr, SNMP_MAXPATH-strlen(fname));
14399- fname[SNMP_MAXPATH-1]='\0';
14400+ if (!cp)
14401+ fname[0] = '\0';
14402+ else
14403+ *(++cp) = '\0';
14404+ strlcat(fname, cptr, SNMP_MAXPATH);
14405 }
14406 prev_filename = curfilename;
14407 prev_linecount = linecount;
14408@@ -2320,210 +2323,3 @@ read_config_store_data_prefix(char prefix, int type, char *storeto,
14409 }
14410
14411 /** @} */
14412-
14413-#ifdef READ_CONFIG_UNIT_TEST
14414-
14415-#define NETSNMP_USE_ASSERT 1
14416-#include <net-snmp/libary/snmp_assert.h>
14417-
14418-int
14419-read64(U64 * i64, const char *str)
14420-{
14421- netsnmp_assert(0);
14422-}
14423-
14424-int
14425-snmp_get_do_debugging(void)
14426-{
14427- return 0;
14428-}
14429-
14430-int
14431-debug_is_token_registered(const char *token)
14432-{
14433- netsnmp_assert(0);
14434-}
14435-
14436-void
14437-debugmsg(const char *token, const char *format, ...)
14438-{
14439- netsnmp_assert(0);
14440-}
14441-
14442-void
14443-debugmsgtoken(const char *token, const char *format, ...)
14444-{
14445- netsnmp_assert(0);
14446-}
14447-
14448-int
14449-snmp_log(int priority, const char *format, ...)
14450-{
14451-#if 0
14452- va_list ap;
14453-
14454- va_start(ap, format);
14455- vprintf(format, ap);
14456- va_end(ap);
14457-#endif
14458- return 0;
14459-}
14460-
14461-void
14462-snmp_log_perror(const char *s)
14463-{
14464- netsnmp_assert(0);
14465-}
14466-
14467-int
14468-snmp_vlog(int priority, const char *format, va_list ap)
14469-{
14470- netsnmp_assert(0);
14471-}
14472-
14473-int
14474-netsnmp_ds_set_boolean(int storeid, int which, int value)
14475-{
14476- netsnmp_assert(0);
14477-}
14478-
14479-int
14480-netsnmp_ds_get_boolean(int storeid, int which)
14481-{
14482- netsnmp_assert(0);
14483-}
14484-
14485-int
14486-netsnmp_ds_set_string(int storeid, int which, const char *value)
14487-{
14488- netsnmp_assert(0);
14489-}
14490-
14491-char *
14492-netsnmp_ds_get_string(int storeid, int which)
14493-{
14494- netsnmp_assert(0);
14495-}
14496-
14497-char *
14498-netsnmp_getenv(const char *name)
14499-{
14500- netsnmp_assert(0);
14501-}
14502-
14503-int
14504-snmp_call_callbacks(int major, int minor, void *caller_arg)
14505-{
14506- netsnmp_assert(0);
14507-}
14508-
14509-int
14510-mkdirhier(const char *pathname, mode_t mode, int skiplast)
14511-{
14512- netsnmp_assert(0);
14513-}
14514-
14515-int
14516-read_objid(const char *input, oid * output, size_t * out_len)
14517-{
14518- netsnmp_assert(0);
14519-}
14520-
14521-struct read_config_testcase {
14522- /*
14523- * inputs
14524- */
14525- const char *(*pf) (const char * readfrom, u_char ** str,
14526- size_t * len);
14527- const char *readfrom;
14528- size_t obuf_len;
14529-
14530- /*
14531- * expected outputs
14532- */
14533- size_t expected_offset;
14534- const u_char *expected_output;
14535- size_t expected_len;
14536-};
14537-
14538-static const u_char obuf1[] = { 1, 0, 2 };
14539-static const u_char obuf2[] = { 'a', 'b', 'c', 0 };
14540-static const u_char obuf3[] = { 1, 3, 2 };
14541-
14542-static const struct read_config_testcase test_input[] = {
14543- { &read_config_read_octet_string_const, "", 1, -1, NULL, 0 },
14544- { &read_config_read_octet_string_const, "0x0", 1, -1, NULL, 1 },
14545- { &read_config_read_octet_string_const, "0x0 0", 1, -1, NULL, 1 },
14546-
14547- { &read_config_read_octet_string_const, "0x010002", 1, -1, NULL, 0 },
14548- { &read_config_read_octet_string_const, "0x010002", 2, -1, NULL, 0 },
14549- { &read_config_read_octet_string_const, "0x010002", 3, -1, obuf1, 0 },
14550- { &read_config_read_octet_string_const, "0x010002", 4, -1, obuf1, 3 },
14551- { &read_config_read_octet_string_const, "0x010002 0", 4, 9, obuf1, 3 },
14552- { &read_config_read_octet_string_const, "0x010002", 0, -1, obuf1, 3 },
14553-
14554- { &read_config_read_octet_string_const, "abc", 1, -1, NULL, 0 },
14555- { &read_config_read_octet_string_const, "abc z", 1, 4, NULL, 0 },
14556- { &read_config_read_octet_string_const, "abc", 2, -1, NULL, 1 },
14557- { &read_config_read_octet_string_const, "abc", 3, -1, obuf2, 2 },
14558- { &read_config_read_octet_string_const, "abc", 4, -1, obuf2, 3 },
14559- { &read_config_read_octet_string_const, "abc z", 4, 4, obuf2, 3 },
14560- { &read_config_read_octet_string_const, "abc", 0, -1, obuf2, 3 },
14561-};
14562-
14563-int
14564-main(int argc, char **argv)
14565-{
14566- int failure_count = 0;
14567- unsigned int i, j;
14568-
14569- printf("Start of unit test.\n");
14570- for (i = 0; i < sizeof(test_input) / sizeof(test_input[0]); i++) {
14571- const struct read_config_testcase *const p = &test_input[i];
14572- size_t len = p->obuf_len;
14573- u_char *str = len > 0 ? malloc(len) : NULL;
14574- const char *result;
14575- size_t offset;
14576-
14577- printf("Test %d ...\n", i);
14578- fflush(stdout);
14579- result = (p->pf) (p->readfrom, &str, &len);
14580- offset = result ? result - p->readfrom : -1;
14581- if (offset != p->expected_offset) {
14582- failure_count++;
14583- printf("test %d: expected offset %zd, got offset %" NETSNMP_PRIz "d\n",
14584- i, p->expected_offset, offset);
14585- } else if (len != p->expected_len) {
14586- failure_count++;
14587- printf("test %d: expected length %d, got length %d\n",
14588- i, p->expected_len, len);
14589- } else if (len >= 0 && p->expected_output
14590- && memcmp(str, p->expected_output, len) != 0
14591- && p->expected_output[len] == 0) {
14592- failure_count++;
14593- printf("test %d: output buffer mismatch\n", i);
14594- printf("Expected: ");
14595- for (j = 0; j < p->expected_len; ++j)
14596- printf("%02x ", p->expected_output[j]);
14597- printf("\nActual: ");
14598- for (j = 0; j < len; ++j)
14599- printf("%02x ", str[j]);
14600- printf("\n");
14601- }
14602-
14603- if (str)
14604- free(str);
14605- }
14606- if (failure_count == 0)
14607- printf("All %d tests passed.\n", i);
14608- return 0;
14609-}
14610-#endif /* READ_CONFIG_UNIT_TEST */
14611-
14612-/*
14613- * Local variables:
14614- * c-basic-offset: 4
14615- * indent-tabs-mode: nil
14616- * compile-command: "gcc -Wall -Werror -DREAD_CONFIG_UNIT_TEST=1 -O1 -I../include -g -o read_config-unit-test read_config.c && ./read_config-unit-test && valgrind --leak-check=full ./read_config-unit-test"
14617- * End:
14618- */
14619diff --git a/snmplib/scapi.c b/snmplib/scapi.c
14620index a397344..fdd33ff 100644
14621--- a/snmplib/scapi.c
14622+++ b/snmplib/scapi.c
14623@@ -116,12 +116,12 @@ netsnmp_feature_child_of(usm_scapi, usm_support)
14624
14625 #ifdef NETSNMP_USE_INTERNAL_CRYPTO
14626 static
14627-int SHA1_hmac(u_char * data, size_t len, u_char * mac, size_t maclen,
14628- u_char * secret, size_t secretlen);
14629+int SHA1_hmac(const u_char * data, size_t len, u_char * mac, size_t maclen,
14630+ const u_char * secret, size_t secretlen);
14631
14632 static
14633-int MD5_hmac(u_char * data, size_t len, u_char * mac, size_t maclen,
14634- u_char * secret, size_t secretlen);
14635+int MD5_hmac(const u_char * data, size_t len, u_char * mac, size_t maclen,
14636+ const u_char * secret, size_t secretlen);
14637 #endif
14638
14639 /*
14640@@ -454,7 +454,7 @@ sc_hash(const oid * hashtype, size_t hashtypelen, const u_char * buf,
14641
14642 #ifdef NETSNMP_USE_OPENSSL
14643 const EVP_MD *hashfn;
14644- EVP_MD_CTX ctx, *cptr;
14645+ EVP_MD_CTX *cptr;
14646 #endif
14647 #ifdef NETSNMP_USE_INTERNAL_CRYPTO
14648 MD5_CTX cmd5;
14649@@ -485,42 +485,32 @@ sc_hash(const oid * hashtype, size_t hashtypelen, const u_char * buf,
14650 }
14651
14652 /** initialize the pointer */
14653- memset(&ctx, 0, sizeof(ctx));
14654- cptr = &ctx;
14655+#ifdef HAVE_EVP_MD_CTX_CREATE
14656+ cptr = EVP_MD_CTX_create();
14657+#else
14658+ cptr = malloc(sizeof(*cptr));
14659 #if defined(OLD_DES)
14660- EVP_DigestInit(cptr, hashfn);
14661-#else /* !OLD_DES */
14662- /* this is needed if the runtime library is different than the compiled
14663- library since the openssl versions are very different. */
14664- if (SSLeay() < 0x907000) {
14665- /* the old version of the struct was bigger and thus more
14666- memory is needed. should be 152, but we use 256 for safety. */
14667- cptr = (EVP_MD_CTX *)malloc(256);
14668- EVP_DigestInit(cptr, hashfn);
14669- } else {
14670- EVP_MD_CTX_init(cptr);
14671- EVP_DigestInit(cptr, hashfn);
14672- }
14673+ memset(cptr, 0, sizeof(*cptr));
14674+#else
14675+ EVP_MD_CTX_init(cptr);
14676+#endif
14677 #endif
14678+ EVP_DigestInit(cptr, hashfn);
14679
14680 /** pass the data */
14681 EVP_DigestUpdate(cptr, buf, buf_len);
14682
14683 /** do the final pass */
14684-#if defined(OLD_DES)
14685 EVP_DigestFinal(cptr, MAC, &tmp_len);
14686 *MAC_len = tmp_len;
14687-#else /* !OLD_DES */
14688- if (SSLeay() < 0x907000) {
14689- EVP_DigestFinal(cptr, MAC, &tmp_len);
14690- *MAC_len = tmp_len;
14691- free(cptr);
14692- } else {
14693- EVP_DigestFinal_ex(cptr, MAC, &tmp_len);
14694- *MAC_len = tmp_len;
14695- EVP_MD_CTX_cleanup(cptr);
14696- }
14697-#endif /* OLD_DES */
14698+#ifdef HAVE_EVP_MD_CTX_DESTROY
14699+ EVP_MD_CTX_destroy(cptr);
14700+#else
14701+#if !defined(OLD_DES)
14702+ EVP_MD_CTX_cleanup(cptr);
14703+#endif
14704+ free(cptr);
14705+#endif
14706 return (rval);
14707
14708 #elif NETSNMP_USE_INTERNAL_CRYPTO
14709@@ -1171,8 +1161,8 @@ sc_decrypt(const oid * privtype, size_t privtypelen,
14710 * of data, and prepended with a secret in the standard fashion
14711 */
14712 static int
14713-MD5_hmac(u_char * data, size_t len, u_char * mac, size_t maclen,
14714- u_char * secret, size_t secretlen)
14715+MD5_hmac(const u_char * data, size_t len, u_char * mac, size_t maclen,
14716+ const u_char * secret, size_t secretlen)
14717 {
14718 #define MD5_HASHKEYLEN 64
14719 #define MD5_SECRETKEYLEN 16
14720@@ -1183,7 +1173,8 @@ MD5_hmac(u_char * data, size_t len, u_char * mac, size_t maclen,
14721 u_char extendedAuthKey[MD5_HASHKEYLEN];
14722 u_char buf[MD5_HASHKEYLEN];
14723 size_t i;
14724- u_char *cp, *newdata = NULL;
14725+ const u_char *cp;
14726+ u_char *newdata = NULL;
14727 int rc = 0;
14728
14729 /*
14730@@ -1268,8 +1259,8 @@ MD5_hmac(u_char * data, size_t len, u_char * mac, size_t maclen,
14731 }
14732
14733 static int
14734-SHA1_hmac(u_char * data, size_t len, u_char * mac, size_t maclen,
14735- u_char * secret, size_t secretlen)
14736+SHA1_hmac(const u_char * data, size_t len, u_char * mac, size_t maclen,
14737+ const u_char * secret, size_t secretlen)
14738 {
14739 #define SHA1_HASHKEYLEN 64
14740 #define SHA1_SECRETKEYLEN 20
14741@@ -1280,7 +1271,8 @@ SHA1_hmac(u_char * data, size_t len, u_char * mac, size_t maclen,
14742 u_char extendedAuthKey[SHA1_HASHKEYLEN];
14743 u_char buf[SHA1_HASHKEYLEN];
14744 size_t i;
14745- u_char *cp, *newdata = NULL;
14746+ const u_char *cp;
14747+ u_char *newdata = NULL;
14748 int rc = 0;
14749
14750 /*
14751diff --git a/snmplib/snmp-tc.c b/snmplib/snmp-tc.c
14752index 3b73da2..891c3a0 100644
14753--- a/snmplib/snmp-tc.c
14754+++ b/snmplib/snmp-tc.c
14755@@ -163,7 +163,7 @@ date_n_time(const time_t * when, size_t * length)
14756 string[7] = 0;
14757 *length = 8;
14758
14759-#ifndef cygwin
14760+#if defined(HAVE_STRUCT_TM_TM_GMTOFF) || defined(HAVE_TIMEZONE_VARIABLE)
14761 /*
14762 * Timezone offset
14763 */
14764diff --git a/snmplib/snmp_alarm.c b/snmplib/snmp_alarm.c
14765index adfa93d..dc498cc 100644
14766--- a/snmplib/snmp_alarm.c
14767+++ b/snmplib/snmp_alarm.c
14768@@ -82,23 +82,22 @@ init_snmp_alarm(void)
14769 void
14770 sa_update_entry(struct snmp_alarm *a)
14771 {
14772- if (a->t_last.tv_sec == 0 && a->t_last.tv_usec == 0) {
14773+ if (!timerisset(&a->t_last)) {
14774 struct timeval t_now;
14775 /*
14776 * Never been called yet, call time `t' from now.
14777 */
14778 gettimeofday(&t_now, NULL);
14779
14780- a->t_last.tv_sec = t_now.tv_sec;
14781- a->t_last.tv_usec = t_now.tv_usec;
14782+ a->t_last = t_now;
14783
14784 NETSNMP_TIMERADD(&t_now, &a->t, &a->t_next);
14785- } else if (a->t_next.tv_sec == 0 && a->t_next.tv_usec == 0) {
14786+ } else if (!timerisset(&a->t_next)) {
14787 /*
14788 * We've been called but not reset for the next call.
14789 */
14790 if (a->flags & SA_REPEAT) {
14791- if (a->t.tv_sec == 0 && a->t.tv_usec == 0) {
14792+ if (!timerisset(&a->t)) {
14793 DEBUGMSGTL(("snmp_alarm",
14794 "update_entry: illegal interval specified\n"));
14795 snmp_alarm_unregister(a->clientreg);
14796@@ -144,7 +143,7 @@ snmp_alarm_unregister(unsigned int clientreg)
14797 DEBUGMSGTL(("snmp_alarm", "unregistered alarm %d\n",
14798 sa_ptr->clientreg));
14799 /*
14800- * Note: do not free the clientarg, its the clients responsibility
14801+ * Note: do not free the clientarg, it's the client's responsibility
14802 */
14803 free(sa_ptr);
14804 } else {
14805@@ -185,22 +184,13 @@ sa_find_next(void)
14806 for (a = thealarms; a != NULL; a = a->next) {
14807 if (!(a->flags & SA_FIRED)) {
14808 /* check for time delta skew */
14809- if ((a->t_next.tv_sec - t_now.tv_sec) > a->t.tv_sec)
14810- {
14811+ if ((a->t_next.tv_sec - t_now.tv_sec) > a->t.tv_sec) {
14812 DEBUGMSGTL(("time_skew", "Time delta too big (%ld seconds), should be %ld seconds - fixing\n",
14813 (long)(a->t_next.tv_sec - t_now.tv_sec), (long)a->t.tv_sec));
14814- a->t_next.tv_sec = t_now.tv_sec + a->t.tv_sec;
14815- a->t_next.tv_usec = t_now.tv_usec + a->t.tv_usec;
14816- }
14817- if (lowest == NULL) {
14818- lowest = a;
14819- } else if (a->t_next.tv_sec == lowest->t_next.tv_sec) {
14820- if (a->t_next.tv_usec < lowest->t_next.tv_usec) {
14821- lowest = a;
14822- }
14823- } else if (a->t_next.tv_sec < lowest->t_next.tv_sec) {
14824- lowest = a;
14825- }
14826+ NETSNMP_TIMERADD(&t_now, &a->t, &a->t_next);
14827+ }
14828+ if (lowest == NULL || timercmp(&a->t_next, &lowest->t_next, <))
14829+ lowest = a;
14830 }
14831 }
14832 return lowest;
14833@@ -247,10 +237,8 @@ run_alarms(void)
14834 DEBUGMSGTL(("snmp_alarm", "alarm %d completed\n", clientreg));
14835
14836 if ((a = sa_find_specific(clientreg)) != NULL) {
14837- a->t_last.tv_sec = t_now.tv_sec;
14838- a->t_last.tv_usec = t_now.tv_usec;
14839- a->t_next.tv_sec = 0;
14840- a->t_next.tv_usec = 0;
14841+ a->t_last = t_now;
14842+ timerclear(&a->t_next);
14843 a->flags &= ~SA_FIRED;
14844 sa_update_entry(a);
14845 } else {
14846@@ -274,39 +262,56 @@ alarm_handler(int a)
14847
14848
14849
14850+/**
14851+ * Look up the time at which the next alarm will fire.
14852+ *
14853+ * @param[out] alarm_tm Time at which the next alarm will fire.
14854+ * @param[in] now Earliest time that should be written into *alarm_tm.
14855+ *
14856+ * @return Zero if no alarms are scheduled; non-zero 'clientreg' value
14857+ * identifying the first alarm that will fire if one or more alarms are
14858+ * scheduled.
14859+ */
14860 int
14861-get_next_alarm_delay_time(struct timeval *delta)
14862+netsnmp_get_next_alarm_time(struct timeval *alarm_tm, const struct timeval *now)
14863 {
14864 struct snmp_alarm *sa_ptr;
14865- struct timeval t_now;
14866
14867 sa_ptr = sa_find_next();
14868
14869 if (sa_ptr) {
14870- gettimeofday(&t_now, NULL);
14871-
14872- if (timercmp(&t_now, &sa_ptr->t_next, >)) {
14873- /*
14874- * Time has already passed. Return the smallest possible amount of
14875- * time.
14876- */
14877- delta->tv_sec = 0;
14878- delta->tv_usec = 1;
14879- return sa_ptr->clientreg;
14880- } else {
14881- /*
14882- * Time is still in the future.
14883- */
14884- NETSNMP_TIMERSUB(&sa_ptr->t_next, &t_now, delta);
14885-
14886- return sa_ptr->clientreg;
14887- }
14888+ netsnmp_assert(alarm_tm);
14889+ netsnmp_assert(timerisset(&sa_ptr->t_next));
14890+ if (timercmp(&sa_ptr->t_next, now, >))
14891+ *alarm_tm = sa_ptr->t_next;
14892+ else
14893+ *alarm_tm = *now;
14894+ return sa_ptr->clientreg;
14895+ } else {
14896+ return 0;
14897 }
14898+}
14899
14900- /*
14901- * Nothing Left.
14902- */
14903- return 0;
14904+/**
14905+ * Get the time until the next alarm will fire.
14906+ *
14907+ * @param[out] delta Time until the next alarm.
14908+ *
14909+ * @return Zero if no alarms are scheduled; non-zero 'clientreg' value
14910+ * identifying the first alarm that will fire if one or more alarms are
14911+ * scheduled.
14912+ */
14913+int
14914+get_next_alarm_delay_time(struct timeval *delta)
14915+{
14916+ struct timeval t_now, alarm_tm;
14917+ int res;
14918+
14919+ gettimeofday(&t_now, NULL);
14920+ res = netsnmp_get_next_alarm_time(&alarm_tm, &t_now);
14921+ if (res)
14922+ NETSNMP_TIMERSUB(&alarm_tm, &t_now, delta);
14923+ return res;
14924 }
14925
14926
14927@@ -328,10 +333,8 @@ set_an_alarm(void)
14928 # ifdef HAVE_SETITIMER
14929 struct itimerval it;
14930
14931- it.it_value.tv_sec = delta.tv_sec;
14932- it.it_value.tv_usec = delta.tv_usec;
14933- it.it_interval.tv_sec = 0;
14934- it.it_interval.tv_usec = 0;
14935+ it.it_value = delta;
14936+ timerclear(&it.it_interval);
14937
14938 signal(SIGALRM, alarm_handler);
14939 setitimer(ITIMER_REAL, &it, NULL);
14940@@ -452,8 +455,7 @@ snmp_alarm_register_hr(struct timeval t, unsigned int flags,
14941 return 0;
14942 }
14943
14944- (*s)->t.tv_sec = t.tv_sec;
14945- (*s)->t.tv_usec = t.tv_usec;
14946+ (*s)->t = t;
14947 (*s)->flags = flags;
14948 (*s)->clientarg = cd;
14949 (*s)->thecallback = cb;
14950diff --git a/snmplib/snmp_api.c b/snmplib/snmp_api.c
14951index df0dc1c..4fca5bf 100644
14952--- a/snmplib/snmp_api.c
14953+++ b/snmplib/snmp_api.c
14954@@ -506,8 +506,7 @@ void
14955 snmp_set_detail(const char *detail_string)
14956 {
14957 if (detail_string != NULL) {
14958- strncpy((char *) snmp_detail, detail_string, sizeof(snmp_detail));
14959- snmp_detail[sizeof(snmp_detail) - 1] = '\0';
14960+ strlcpy((char *) snmp_detail, detail_string, sizeof(snmp_detail));
14961 snmp_detail_f = 1;
14962 }
14963 }
14964@@ -523,20 +522,22 @@ snmp_api_errstring(int snmp_errnumber)
14965 {
14966 const char *msg = "";
14967 static char msg_buf[SPRINT_MAX_LEN];
14968+
14969 if (snmp_errnumber >= SNMPERR_MAX && snmp_errnumber <= SNMPERR_GENERR) {
14970 msg = api_errors[-snmp_errnumber];
14971 } else if (snmp_errnumber != SNMPERR_SUCCESS) {
14972 msg = NULL;
14973 }
14974- if (!msg)
14975+ if (!msg) {
14976 snprintf(msg_buf, sizeof(msg_buf), "Unknown error: %d", snmp_errnumber);
14977- else if (snmp_detail_f) {
14978+ msg_buf[sizeof(msg_buf)-1] = '\0';
14979+ } else if (snmp_detail_f) {
14980 snprintf(msg_buf, sizeof(msg_buf), "%s (%s)", msg, snmp_detail);
14981+ msg_buf[sizeof(msg_buf)-1] = '\0';
14982 snmp_detail_f = 0;
14983 } else {
14984- strncpy(msg_buf, msg, sizeof(msg_buf));
14985+ strlcpy(msg_buf, msg, sizeof(msg_buf));
14986 }
14987- msg_buf[sizeof(msg_buf)-1] = '\0';
14988
14989 return (msg_buf);
14990 }
14991@@ -566,15 +567,17 @@ snmp_error(netsnmp_session * psess,
14992 if (snmp_detail_f) {
14993 snprintf(buf, sizeof(buf), "%s (%s)", api_errors[-snmp_errnumber],
14994 snmp_detail);
14995+ buf[sizeof(buf)-1] = '\0';
14996 snmp_detail_f = 0;
14997 }
14998 else
14999- strncpy(buf, api_errors[-snmp_errnumber], sizeof(buf));
15000+ strlcpy(buf, api_errors[-snmp_errnumber], sizeof(buf));
15001 } else {
15002- if (snmp_errnumber)
15003+ if (snmp_errnumber) {
15004 snprintf(buf, sizeof(buf), "Unknown Error %d", snmp_errnumber);
15005+ buf[sizeof(buf)-1] = '\0';
15006+ }
15007 }
15008- buf[sizeof(buf)-1] = '\0';
15009
15010 /*
15011 * append a useful system errno interpretation.
15012@@ -704,6 +707,8 @@ _init_snmp(void)
15013
15014 netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID,
15015 NETSNMP_DS_LIB_HEX_OUTPUT_LENGTH, 16);
15016+ netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_RETRIES,
15017+ DEFAULT_RETRIES);
15018
15019 #ifdef NETSNMP_USE_REVERSE_ASNENCODING
15020 netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
15021@@ -1280,6 +1285,7 @@ snmpv3_probe_contextEngineID_rfc5343(void *slp, netsnmp_session *session) {
15022 if (memdup(&pdu->contextEngineID, probeEngineID, probeEngineID_len) !=
15023 SNMPERR_SUCCESS) {
15024 snmp_log(LOG_ERR, "failed to clone memory for rfc5343 probe\n");
15025+ snmp_free_pdu(pdu);
15026 return SNMP_ERR_GENERR;
15027 }
15028 pdu->contextEngineIDLen = probeEngineID_len;
15029@@ -1390,7 +1396,7 @@ snmpv3_engineID_probe(struct session_list *slp,
15030 }
15031
15032 /* see if there was any hooks to call after the engineID probing */
15033- if (sptr->post_probe_engineid) {
15034+ if (sptr && sptr->post_probe_engineid) {
15035 status = (*sptr->post_probe_engineid)(slp, in_session);
15036 if (status != SNMPERR_SUCCESS)
15037 return 0;
15038@@ -5341,8 +5347,8 @@ _sess_process_packet(void *sessp, netsnmp_session * sp,
15039 if (sp->securityEngineID == NULL) {
15040 /*
15041 * TODO FIX: recover after message callback *?
15042- * return -1;
15043- */
15044+ */
15045+ return -1;
15046 }
15047 memcpy(sp->securityEngineID, pdu->securityEngineID,
15048 pdu->securityEngineIDLen);
15049@@ -5354,8 +5360,8 @@ _sess_process_packet(void *sessp, netsnmp_session * sp,
15050 if (sp->contextEngineID == NULL) {
15051 /*
15052 * TODO FIX: recover after message callback *?
15053- * return -1;
15054 */
15055+ return -1;
15056 }
15057 memcpy(sp->contextEngineID,
15058 pdu->securityEngineID,
15059@@ -5868,7 +5874,7 @@ snmp_sess_read2(void *sessp, netsnmp_large_fd_set * fdset)
15060 }
15061
15062
15063-/*
15064+/**
15065 * Returns info about what snmp requires from a select statement.
15066 * numfds is the number of fds in the list that are significant.
15067 * All file descriptors opened for SNMP are OR'd into the fdset.
15068@@ -5889,54 +5895,43 @@ snmp_sess_read2(void *sessp, netsnmp_large_fd_set * fdset)
15069 *
15070 * snmp_select_info returns the number of open sockets. (i.e. The number of
15071 * sessions open)
15072+ *
15073+ * @see See also snmp_sess_select_info2_flags().
15074 */
15075-
15076 int
15077-snmp_select_info(int *numfds,
15078- fd_set * fdset, struct timeval *timeout, int *block)
15079- /*
15080- * input: set to 1 if input timeout value is undefined
15081- * set to 0 if input timeout value is defined
15082- * output: set to 1 if output timeout value is undefined
15083- * set to 0 if output rimeout vlaue id defined
15084- */
15085+snmp_select_info(int *numfds, fd_set *fdset, struct timeval *timeout,
15086+ int *block)
15087 {
15088- return snmp_sess_select_info((void *) 0, numfds, fdset, timeout,
15089- block);
15090+ return snmp_sess_select_info(NULL, numfds, fdset, timeout, block);
15091 }
15092
15093+/**
15094+ * @see See also snmp_sess_select_info2_flags().
15095+ */
15096 int
15097-snmp_select_info2(int *numfds,
15098- netsnmp_large_fd_set * fdset,
15099+snmp_select_info2(int *numfds, netsnmp_large_fd_set *fdset,
15100 struct timeval *timeout, int *block)
15101- /*
15102- * input: set to 1 if input timeout value is undefined
15103- * set to 0 if input timeout value is defined
15104- * output: set to 1 if output timeout value is undefined
15105- * set to 0 if output rimeout vlaue id defined
15106- */
15107 {
15108- return snmp_sess_select_info2((void *) 0, numfds, fdset, timeout,
15109- block);
15110+ return snmp_sess_select_info2(NULL, numfds, fdset, timeout, block);
15111 }
15112
15113-/*
15114- * Same as snmp_select_info, but works just one session.
15115+/**
15116+ * @see See also snmp_sess_select_info2_flags().
15117 */
15118 int
15119-snmp_sess_select_info(void *sessp,
15120- int *numfds,
15121- fd_set * fdset, struct timeval *timeout, int *block)
15122+snmp_sess_select_info(void *sessp, int *numfds, fd_set *fdset,
15123+ struct timeval *timeout, int *block)
15124 {
15125 return snmp_sess_select_info_flags(sessp, numfds, fdset, timeout, block,
15126 NETSNMP_SELECT_NOFLAGS);
15127 }
15128
15129+/**
15130+ * @see See also snmp_sess_select_info2_flags().
15131+ */
15132 int
15133-snmp_sess_select_info_flags(void *sessp,
15134- int *numfds,
15135- fd_set * fdset, struct timeval *timeout, int *block,
15136- int flags)
15137+snmp_sess_select_info_flags(void *sessp, int *numfds, fd_set *fdset,
15138+ struct timeval *timeout, int *block, int flags)
15139 {
15140 int rc;
15141 netsnmp_large_fd_set lfdset;
15142@@ -5954,47 +5949,67 @@ snmp_sess_select_info_flags(void *sessp,
15143 return rc;
15144 }
15145
15146+/**
15147+ * @see See also snmp_sess_select_info2_flags().
15148+ */
15149 int
15150-snmp_sess_select_info2(void *sessp,
15151- int *numfds,
15152- netsnmp_large_fd_set * fdset,
15153+snmp_sess_select_info2(void *sessp, int *numfds, netsnmp_large_fd_set *fdset,
15154 struct timeval *timeout, int *block)
15155 {
15156 return snmp_sess_select_info2_flags(sessp, numfds, fdset, timeout, block,
15157 NETSNMP_SELECT_NOFLAGS);
15158 }
15159
15160+/**
15161+ * Compute/update the arguments to be passed to select().
15162+ *
15163+ * @param[in] sessp Which sessions to process: either a pointer to a
15164+ * specific session or NULL which means to process all sessions.
15165+ * @param[in,out] numfds On POSIX systems one more than the the largest file
15166+ * descriptor that is present in *fdset. On systems that use Winsock (MinGW
15167+ * and MSVC), do not use the value written into *numfds.
15168+ * @param[in,out] fdset A large file descriptor set to which all file
15169+ * descriptors will be added that are associated with one of the examined
15170+ * sessions.
15171+ * @param[in,out] timeout On input, if *block = 1, the maximum time the caller
15172+ * will block while waiting for Net-SNMP activity. On output, if this function
15173+ * has set *block to 0, the maximum time the caller is allowed to wait before
15174+ * invoking the Net-SNMP processing functions (snmp_read(), snmp_timeout()
15175+ * and run_alarms()). If this function has set *block to 1, *timeout won't
15176+ * have been modified and no alarms are active.
15177+ * @param[in,out] block On input, whether the caller prefers to block forever
15178+ * when no alarms are active. On output, 0 means that no alarms are active
15179+ * nor that there is a timeout pending for any of the processed sessions.
15180+ * @param[in] flags Either 0 or NETSNMP_SELECT_NOALARMS.
15181+ *
15182+ * @return Number of sessions processed by this function.
15183+ *
15184+ * @see See also agent_check_and_process() for an example of how to use this
15185+ * function.
15186+ */
15187 int
15188-snmp_sess_select_info2_flags(void *sessp,
15189- int *numfds,
15190- netsnmp_large_fd_set * fdset,
15191- struct timeval *timeout, int *block, int flags)
15192+snmp_sess_select_info2_flags(void *sessp, int *numfds,
15193+ netsnmp_large_fd_set * fdset,
15194+ struct timeval *timeout, int *block, int flags)
15195 {
15196- struct session_list *slptest = (struct session_list *) sessp;
15197 struct session_list *slp, *next = NULL;
15198 netsnmp_request_list *rp;
15199- struct timeval now, earliest, delta;
15200+ struct timeval now, earliest, alarm_tm;
15201 int active = 0, requests = 0;
15202 int next_alarm = 0;
15203
15204 timerclear(&earliest);
15205
15206 /*
15207- * For each request outstanding, add its socket to the fdset,
15208+ * For each session examined, add its socket to the fdset,
15209 * and if it is the earliest timeout to expire, mark it as lowest.
15210 * If a single session is specified, do just for that session.
15211 */
15212
15213- if (sessp) {
15214- slp = slptest;
15215- } else {
15216- slp = Sessions;
15217- }
15218-
15219 DEBUGMSGTL(("sess_select", "for %s session%s: ",
15220 sessp ? "single" : "all", sessp ? "" : "s"));
15221
15222- for (; slp; slp = next) {
15223+ for (slp = sessp ? sessp : Sessions; slp; slp = next) {
15224 next = slp->next;
15225
15226 if (slp->transport == NULL) {
15227@@ -6032,8 +6047,9 @@ snmp_sess_select_info2_flags(void *sessp,
15228 */
15229 requests++;
15230 for (rp = slp->internal->requests; rp; rp = rp->next_request) {
15231- if ((!timerisset(&earliest)
15232- || (timercmp(&rp->expire, &earliest, <)))) {
15233+ if (!timerisset(&earliest)
15234+ || (timerisset(&rp->expire)
15235+ && timercmp(&rp->expire, &earliest, <))) {
15236 earliest = rp->expire;
15237 DEBUGMSG(("verbose:sess_select","(to in %d.%06d sec) ",
15238 (int)earliest.tv_sec, (int)earliest.tv_usec));
15239@@ -6051,12 +6067,15 @@ snmp_sess_select_info2_flags(void *sessp,
15240 }
15241 DEBUGMSG(("sess_select", "\n"));
15242
15243+ gettimeofday(&now, NULL);
15244+
15245 if (netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID,
15246 NETSNMP_DS_LIB_ALARM_DONT_USE_SIG) &&
15247 !(flags & NETSNMP_SELECT_NOALARMS)) {
15248- next_alarm = get_next_alarm_delay_time(&delta);
15249- DEBUGMSGT(("sess_select","next alarm %d.%06d sec\n",
15250- (int)delta.tv_sec, (int)delta.tv_usec));
15251+ next_alarm = netsnmp_get_next_alarm_time(&alarm_tm, &now);
15252+ if (next_alarm)
15253+ DEBUGMSGT(("sess_select","next alarm at %ld.%06ld sec\n",
15254+ (long)alarm_tm.tv_sec, (long)alarm_tm.tv_usec));
15255 }
15256 if (next_alarm == 0 && requests == 0) {
15257 /*
15258@@ -6067,51 +6086,18 @@ snmp_sess_select_info2_flags(void *sessp,
15259 return active;
15260 }
15261
15262- /*
15263- * * Now find out how much time until the earliest timeout. This
15264- * * transforms earliest from an absolute time into a delta time, the
15265- * * time left until the select should timeout.
15266- */
15267- gettimeofday(&now, (struct timezone *) 0);
15268- /*
15269- * Now = now;
15270- */
15271+ if (next_alarm &&
15272+ (!timerisset(&earliest) || timercmp(&alarm_tm, &earliest, <)))
15273+ earliest = alarm_tm;
15274
15275- if (next_alarm) {
15276- delta.tv_sec += now.tv_sec;
15277- delta.tv_usec += now.tv_usec;
15278- while (delta.tv_usec >= 1000000) {
15279- delta.tv_usec -= 1000000;
15280- delta.tv_sec += 1;
15281- }
15282- if (!timerisset(&earliest) ||
15283- ((earliest.tv_sec > delta.tv_sec) ||
15284- ((earliest.tv_sec == delta.tv_sec) &&
15285- (earliest.tv_usec > delta.tv_usec)))) {
15286- earliest.tv_sec = delta.tv_sec;
15287- earliest.tv_usec = delta.tv_usec;
15288- }
15289- }
15290-
15291- if (earliest.tv_sec < now.tv_sec) {
15292- DEBUGMSGT(("verbose:sess_select","timer overdue\n"));
15293- earliest.tv_sec = 0;
15294- earliest.tv_usec = 0;
15295- } else if (earliest.tv_sec == now.tv_sec) {
15296- earliest.tv_sec = 0;
15297- earliest.tv_usec = (earliest.tv_usec - now.tv_usec);
15298- if (earliest.tv_usec < 0) {
15299- earliest.tv_usec = 100;
15300- }
15301- DEBUGMSGT(("verbose:sess_select","timer due *real* soon. %d usec\n",
15302- (int)earliest.tv_usec));
15303+ NETSNMP_TIMERSUB(&earliest, &now, &earliest);
15304+ if (earliest.tv_sec < 0) {
15305+ time_t overdue_ms = -(earliest.tv_sec * 1000 + earliest.tv_usec / 1000);
15306+ if (overdue_ms >= 10)
15307+ DEBUGMSGT(("verbose:sess_select","timer overdue by %ld ms\n",
15308+ overdue_ms));
15309+ timerclear(&earliest);
15310 } else {
15311- earliest.tv_sec = (earliest.tv_sec - now.tv_sec);
15312- earliest.tv_usec = (earliest.tv_usec - now.tv_usec);
15313- if (earliest.tv_usec < 0) {
15314- earliest.tv_sec--;
15315- earliest.tv_usec = (1000000L + earliest.tv_usec);
15316- }
15317 DEBUGMSGT(("verbose:sess_select","timer due in %d.%06d sec\n",
15318 (int)earliest.tv_sec, (int)earliest.tv_usec));
15319 }
15320diff --git a/snmplib/snmp_client.c b/snmplib/snmp_client.c
15321index ae57613..c1aa9c4 100644
15322--- a/snmplib/snmp_client.c
15323+++ b/snmplib/snmp_client.c
15324@@ -804,6 +804,11 @@ snmp_set_var_value(netsnmp_variable_list * vars,
15325 vars->val.string = NULL;
15326 vars->val_len = 0;
15327
15328+ if (value == NULL && len > 0) {
15329+ snmp_log(LOG_ERR, "bad size for NULL value\n");
15330+ return 1;
15331+ }
15332+
15333 /*
15334 * use built-in storage for smaller values
15335 */
15336@@ -823,84 +828,82 @@ snmp_set_var_value(netsnmp_variable_list * vars,
15337 case ASN_UNSIGNED:
15338 case ASN_TIMETICKS:
15339 case ASN_COUNTER:
15340- if (value) {
15341- if (vars->val_len == sizeof(int)) {
15342- if (ASN_INTEGER == vars->type) {
15343- const int *val_int
15344- = (const int *) value;
15345- *(vars->val.integer) = (long) *val_int;
15346- } else {
15347- const u_int *val_uint
15348- = (const u_int *) value;
15349- *(vars->val.integer) = (unsigned long) *val_uint;
15350- }
15351+ case ASN_UINTEGER:
15352+ if (vars->val_len == sizeof(int)) {
15353+ if (ASN_INTEGER == vars->type) {
15354+ const int *val_int
15355+ = (const int *) value;
15356+ *(vars->val.integer) = (long) *val_int;
15357+ } else {
15358+ const u_int *val_uint
15359+ = (const u_int *) value;
15360+ *(vars->val.integer) = (unsigned long) *val_uint;
15361 }
15362+ }
15363 #if SIZEOF_LONG != SIZEOF_INT
15364- else if (vars->val_len == sizeof(long)){
15365- const u_long *val_ulong
15366- = (const u_long *) value;
15367- *(vars->val.integer) = *val_ulong;
15368- if (*(vars->val.integer) > 0xffffffff) {
15369- snmp_log(LOG_ERR,"truncating integer value > 32 bits\n");
15370- *(vars->val.integer) &= 0xffffffff;
15371- }
15372+ else if (vars->val_len == sizeof(long)){
15373+ const u_long *val_ulong
15374+ = (const u_long *) value;
15375+ *(vars->val.integer) = *val_ulong;
15376+ if (*(vars->val.integer) > 0xffffffff) {
15377+ snmp_log(LOG_ERR,"truncating integer value > 32 bits\n");
15378+ *(vars->val.integer) &= 0xffffffff;
15379 }
15380+ }
15381 #endif
15382 #if defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG != SIZEOF_LONG_LONG)
15383 #if !defined(SIZEOF_INTMAX_T) || (SIZEOF_LONG_LONG != SIZEOF_INTMAX_T)
15384- else if (vars->val_len == sizeof(long long)){
15385- const unsigned long long *val_ullong
15386- = (const unsigned long long *) value;
15387- *(vars->val.integer) = (long) *val_ullong;
15388- if (*(vars->val.integer) > 0xffffffff) {
15389- snmp_log(LOG_ERR,"truncating integer value > 32 bits\n");
15390- *(vars->val.integer) &= 0xffffffff;
15391- }
15392+ else if (vars->val_len == sizeof(long long)){
15393+ const unsigned long long *val_ullong
15394+ = (const unsigned long long *) value;
15395+ *(vars->val.integer) = (long) *val_ullong;
15396+ if (*(vars->val.integer) > 0xffffffff) {
15397+ snmp_log(LOG_ERR,"truncating integer value > 32 bits\n");
15398+ *(vars->val.integer) &= 0xffffffff;
15399 }
15400+ }
15401 #endif
15402 #endif
15403 #if defined(SIZEOF_INTMAX_T) && (SIZEOF_LONG != SIZEOF_INTMAX_T)
15404- else if (vars->val_len == sizeof(intmax_t)){
15405- const uintmax_t *val_uintmax_t
15406- = (const uintmax_t *) value;
15407- *(vars->val.integer) = (long) *val_uintmax_t;
15408- if (*(vars->val.integer) > 0xffffffff) {
15409- snmp_log(LOG_ERR,"truncating integer value > 32 bits\n");
15410- *(vars->val.integer) &= 0xffffffff;
15411- }
15412+ else if (vars->val_len == sizeof(intmax_t)){
15413+ const uintmax_t *val_uintmax_t
15414+ = (const uintmax_t *) value;
15415+ *(vars->val.integer) = (long) *val_uintmax_t;
15416+ if (*(vars->val.integer) > 0xffffffff) {
15417+ snmp_log(LOG_ERR,"truncating integer value > 32 bits\n");
15418+ *(vars->val.integer) &= 0xffffffff;
15419 }
15420+ }
15421 #endif
15422 #if SIZEOF_SHORT != SIZEOF_INT
15423- else if (vars->val_len == sizeof(short)) {
15424- if (ASN_INTEGER == vars->type) {
15425- const short *val_short
15426- = (const short *) value;
15427- *(vars->val.integer) = (long) *val_short;
15428- } else {
15429- const u_short *val_ushort
15430- = (const u_short *) value;
15431- *(vars->val.integer) = (unsigned long) *val_ushort;
15432- }
15433+ else if (vars->val_len == sizeof(short)) {
15434+ if (ASN_INTEGER == vars->type) {
15435+ const short *val_short
15436+ = (const short *) value;
15437+ *(vars->val.integer) = (long) *val_short;
15438+ } else {
15439+ const u_short *val_ushort
15440+ = (const u_short *) value;
15441+ *(vars->val.integer) = (unsigned long) *val_ushort;
15442 }
15443+ }
15444 #endif
15445- else if (vars->val_len == sizeof(char)) {
15446- if (ASN_INTEGER == vars->type) {
15447- const char *val_char
15448- = (const char *) value;
15449- *(vars->val.integer) = (long) *val_char;
15450- } else {
15451+ else if (vars->val_len == sizeof(char)) {
15452+ if (ASN_INTEGER == vars->type) {
15453+ const char *val_char
15454+ = (const char *) value;
15455+ *(vars->val.integer) = (long) *val_char;
15456+ } else {
15457 const u_char *val_uchar
15458- = (const u_char *) value;
15459- *(vars->val.integer) = (unsigned long) *val_uchar;
15460- }
15461- }
15462- else {
15463- snmp_log(LOG_ERR,"bad size for integer-like type (%d)\n",
15464- (int)vars->val_len);
15465- return (1);
15466+ = (const u_char *) value;
15467+ *(vars->val.integer) = (unsigned long) *val_uchar;
15468 }
15469- } else
15470- *(vars->val.integer) = 0;
15471+ }
15472+ else {
15473+ snmp_log(LOG_ERR,"bad size for integer-like type (%d)\n",
15474+ (int)vars->val_len);
15475+ return (1);
15476+ }
15477 vars->val_len = sizeof(long);
15478 break;
15479
15480diff --git a/snmplib/snmp_enum.c b/snmplib/snmp_enum.c
15481index cac0ed3..8a6bd38 100644
15482--- a/snmplib/snmp_enum.c
15483+++ b/snmplib/snmp_enum.c
15484@@ -156,12 +156,12 @@ se_read_conf(const char *word, char *cptr)
15485
15486 void
15487 se_store_enum_list(struct snmp_enum_list *new_list,
15488- const char *token, char *type)
15489+ const char *token, const char *type)
15490 {
15491 struct snmp_enum_list *listp = new_list;
15492 char line[2048];
15493 char buf[512];
15494- int len = 0;
15495+ int len;
15496
15497 snprintf(line, sizeof(line), "enum %s", token);
15498 while (listp) {
15499@@ -175,26 +175,19 @@ se_store_enum_list(struct snmp_enum_list *new_list,
15500 if ((int)strlen(buf) > len) {
15501 read_config_store(type, line);
15502 snprintf(line, sizeof(line), "enum %s", token);
15503- len = sizeof(line);
15504+ len = sizeof(line) - strlen(line);
15505 }
15506
15507 strncat(line, buf, len);
15508 listp = listp->next;
15509 }
15510
15511- /*
15512- * If there's anything left, then save that.
15513- * But don't bother saving an empty 'overflow' line.
15514- */
15515- if (len != sizeof(line))
15516- read_config_store(type, line);
15517-
15518- return;
15519+ read_config_store(type, line);
15520 }
15521
15522 #ifndef NETSNMP_FEATURE_REMOVE_SNMP_ENUM_STORE_LIST
15523 void
15524-se_store_list(unsigned int major, unsigned int minor, char *type)
15525+se_store_list(unsigned int major, unsigned int minor, const char *type)
15526 {
15527 char token[32];
15528
15529@@ -297,8 +290,10 @@ se_add_pair_to_list(struct snmp_enum_list **list, char *label, int value)
15530 (*list) = SNMP_MALLOC_STRUCT(snmp_enum_list);
15531 lastnode = (*list);
15532 }
15533- if (!lastnode)
15534+ if (!lastnode) {
15535+ free(label);
15536 return (SE_NOMEM);
15537+ }
15538 lastnode->label = label;
15539 lastnode->value = value;
15540 lastnode->next = NULL;
15541@@ -445,7 +440,7 @@ se_clear_list(struct snmp_enum_list **list)
15542
15543 #ifndef NETSNMP_FEATURE_REMOVE_SNMP_ENUM_STORE_SLIST
15544 void
15545-se_store_slist(const char *listname, char *type)
15546+se_store_slist(const char *listname, const char *type)
15547 {
15548 struct snmp_enum_list *list = se_find_slist(listname);
15549 se_store_enum_list(list, listname, type);
15550diff --git a/snmplib/snmp_logging.c b/snmplib/snmp_logging.c
15551index 37d5948..a2cd55a 100644
15552--- a/snmplib/snmp_logging.c
15553+++ b/snmplib/snmp_logging.c
15554@@ -535,7 +535,7 @@ char *
15555 snmp_log_syslogname(const char *pstr)
15556 {
15557 if (pstr)
15558- strncpy (syslogname, pstr, sizeof(syslogname));
15559+ strlcpy (syslogname, pstr, sizeof(syslogname));
15560
15561 return syslogname;
15562 }
15563diff --git a/snmplib/snmp_openssl.c b/snmplib/snmp_openssl.c
15564index da5c114..3b0eaa8 100644
15565--- a/snmplib/snmp_openssl.c
15566+++ b/snmplib/snmp_openssl.c
15567@@ -737,7 +737,7 @@ _cert_get_san_type(X509 *ocert, int mapType)
15568 if (lower)
15569 for ( ; *lower; ++lower )
15570 if (isascii(*lower))
15571- *lower = tolower(*lower);
15572+ *lower = tolower(0xFF & *lower);
15573 DEBUGMSGT(("openssl:cert:extension:san", "#%d type %d: %s\n", i,
15574 oname ? oname->type : -1, buf ? buf : "NULL"));
15575
15576diff --git a/snmplib/snmp_parse_args.c b/snmplib/snmp_parse_args.c
15577index e47542e..c73b84c 100644
15578--- a/snmplib/snmp_parse_args.c
15579+++ b/snmplib/snmp_parse_args.c
15580@@ -209,8 +209,13 @@ netsnmp_parse_args(int argc,
15581 */
15582 snmp_sess_init(session);
15583 strcpy(Opts, "Y:VhHm:M:O:I:P:D:dv:r:t:c:Z:e:E:n:u:l:x:X:a:A:p:T:-:3:s:S:L:");
15584- if (localOpts)
15585+ if (localOpts) {
15586+ if (strlen(localOpts) + strlen(Opts) >= sizeof(Opts)) {
15587+ snmp_log(LOG_ERR, "Too many localOpts in snmp_parse_args()\n");
15588+ return -1;
15589+ }
15590 strcat(Opts, localOpts);
15591+ }
15592
15593 /*
15594 * get the options
15595@@ -364,10 +369,8 @@ netsnmp_parse_args(int argc,
15596 }
15597
15598 /* set the config */
15599- strncpy(leftside, tmpopt, sizeof(leftside));
15600- leftside[sizeof(leftside)-1] = '0';
15601- strncpy(rightside, tmpcp, sizeof(rightside));
15602- rightside[sizeof(rightside)-1] = '0';
15603+ strlcpy(leftside, tmpopt, sizeof(leftside));
15604+ strlcpy(rightside, tmpcp, sizeof(rightside));
15605
15606 CONTAINER_INSERT(session->transport_configuration,
15607 netsnmp_transport_create_config(leftside,
15608diff --git a/snmplib/snmp_service.c b/snmplib/snmp_service.c
15609index 90af5e4..ce7e8be 100644
15610--- a/snmplib/snmp_service.c
15611+++ b/snmplib/snmp_service.c
15612@@ -227,6 +227,15 @@ struct netsnmp_lookup_target {
15613
15614 static struct netsnmp_lookup_target* targets = NULL;
15615
15616+/**
15617+ * Add an (application, domain, target) triplet to the targets list if target
15618+ * != NULL. Remove an entry if target == NULL and the userTarget pointer for
15619+ * the entry found is also NULL. Keep at most one target per (application,
15620+ * domain) pair.
15621+ *
15622+ * @return 1 if an entry for (application, domain) was already present in the
15623+ * targets list or 0 if such an entry was not yet present in the targets list.
15624+ */
15625 int
15626 netsnmp_register_default_target(const char* application, const char* domain,
15627 const char* target)
15628@@ -271,6 +280,9 @@ netsnmp_register_default_target(const char* application, const char* domain,
15629 return res;
15630 }
15631
15632+/**
15633+ * Clear the targets list.
15634+ */
15635 void
15636 netsnmp_clear_default_target(void)
15637 {
15638diff --git a/snmplib/snmp_transport.c b/snmplib/snmp_transport.c
15639index ae2b3ee..85a4f35 100644
15640--- a/snmplib/snmp_transport.c
15641+++ b/snmplib/snmp_transport.c
15642@@ -127,11 +127,10 @@ netsnmp_transport_copy(netsnmp_transport *t)
15643 return NULL;
15644 }
15645
15646- n = (netsnmp_transport *) malloc(sizeof(netsnmp_transport));
15647+ n = SNMP_MALLOC_TYPEDEF(netsnmp_transport);
15648 if (n == NULL) {
15649 return NULL;
15650 }
15651- memset(n, 0, sizeof(netsnmp_transport));
15652
15653 if (t->domain != NULL) {
15654 n->domain = t->domain;
15655@@ -551,7 +550,7 @@ netsnmp_tdomain_transport_full(const char *application,
15656 if (NULL !=
15657 (newhost = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
15658 NETSNMP_DS_LIB_HOSTNAME))) {
15659- strncpy(buf, newhost, sizeof(buf)-1);
15660+ strlcpy(buf, newhost, sizeof(buf));
15661 str = buf;
15662 }
15663
15664diff --git a/snmplib/snmptsm.c b/snmplib/snmptsm.c
15665index 778001e..bf4b612 100644
15666--- a/snmplib/snmptsm.c
15667+++ b/snmplib/snmptsm.c
15668@@ -193,6 +193,7 @@ tsm_rgenerate_out_msg(struct snmp_secmod_outgoing_params *parms)
15669 size_t *wholeMsgLen = parms->wholeMsgLen;
15670 netsnmp_tsmSecurityReference *tsmSecRef;
15671 netsnmp_tmStateReference *tmStateRef;
15672+ int tmStateRefLocal = 0;
15673
15674 DEBUGMSGTL(("tsm", "Starting TSM processing\n"));
15675
15676@@ -229,7 +230,8 @@ tsm_rgenerate_out_msg(struct snmp_secmod_outgoing_params *parms)
15677 tmStateReference cache. */
15678 tmStateRef = SNMP_MALLOC_TYPEDEF(netsnmp_tmStateReference);
15679 netsnmp_assert_or_return(NULL != tmStateRef, SNMPERR_GENERR);
15680-
15681+ tmStateRefLocal = 1;
15682+
15683 /* XXX: we don't actually use this really in our implementation */
15684 /* 4.2, step 2: Set tmTransportDomain to the value of
15685 transportDomain, tmTransportAddress to the value of
15686@@ -263,6 +265,7 @@ tsm_rgenerate_out_msg(struct snmp_secmod_outgoing_params *parms)
15687 incremented, an error indication is returned to the
15688 calling module, and message processing stops. */
15689 snmp_increment_statistic(STAT_TSM_SNMPTSMUNKNOWNPREFIXES);
15690+ SNMP_FREE(tmStateRef);
15691 return SNMPERR_GENERR;
15692 }
15693
15694@@ -281,6 +284,7 @@ tsm_rgenerate_out_msg(struct snmp_secmod_outgoing_params *parms)
15695 /* Note: since we're assiging the prefixes above the
15696 prefix lengths always meet the 1-4 criteria */
15697 snmp_increment_statistic(STAT_TSM_SNMPTSMINVALIDPREFIXES);
15698+ SNMP_FREE(tmStateRef);
15699 return SNMPERR_GENERR;
15700 }
15701
15702@@ -315,6 +319,8 @@ tsm_rgenerate_out_msg(struct snmp_secmod_outgoing_params *parms)
15703 DEBUGINDENTLESS();
15704 if (rc == 0) {
15705 DEBUGMSGTL(("tsm", "building msgSecurityParameters failed.\n"));
15706+ if (tmStateRefLocal)
15707+ SNMP_FREE(tmStateRef);
15708 return SNMPERR_TOO_LONG;
15709 }
15710
15711@@ -324,6 +330,8 @@ tsm_rgenerate_out_msg(struct snmp_secmod_outgoing_params *parms)
15712 while ((*wholeMsgLen - *offset) < parms->globalDataLen) {
15713 if (!asn_realloc(wholeMsg, wholeMsgLen)) {
15714 DEBUGMSGTL(("tsm", "building global data failed.\n"));
15715+ if (tmStateRefLocal)
15716+ SNMP_FREE(tmStateRef);
15717 return SNMPERR_TOO_LONG;
15718 }
15719 }
15720@@ -347,6 +355,8 @@ tsm_rgenerate_out_msg(struct snmp_secmod_outgoing_params *parms)
15721 ASN_CONSTRUCTOR), *offset);
15722 if (rc == 0) {
15723 DEBUGMSGTL(("tsm", "building master packet sequence failed.\n"));
15724+ if (tmStateRefLocal)
15725+ SNMP_FREE(tmStateRef);
15726 return SNMPERR_TOO_LONG;
15727 }
15728
15729@@ -364,6 +374,8 @@ tsm_rgenerate_out_msg(struct snmp_secmod_outgoing_params *parms)
15730 }
15731 parms->pdu->transport_data_length = sizeof(*tmStateRef);
15732
15733+ if (tmStateRefLocal)
15734+ SNMP_FREE(tmStateRef);
15735 DEBUGMSGTL(("tsm", "TSM processing completed.\n"));
15736 return SNMPERR_SUCCESS;
15737 }
15738diff --git a/snmplib/snmpusm.c b/snmplib/snmpusm.c
15739index 8a673dc..d8d8932 100644
15740--- a/snmplib/snmpusm.c
15741+++ b/snmplib/snmpusm.c
15742@@ -2727,6 +2727,7 @@ usm_handle_report(void *sessp,
15743 }
15744 session->s_snmp_errno = res;
15745 }
15746+ /* fallthrough */
15747 case SNMPERR_USM_UNKNOWNENGINEID:
15748 case SNMPERR_USM_UNKNOWNSECURITYNAME:
15749 case SNMPERR_USM_UNSUPPORTEDSECURITYLEVEL:
15750@@ -3150,6 +3151,7 @@ int usm_discover_engineid(void *slpv, netsnmp_session *session) {
15751 break;
15752 case STAT_TIMEOUT:
15753 session->s_snmp_errno = SNMPERR_TIMEOUT;
15754+ break;
15755 default:
15756 DEBUGMSGTL(("snmp_sess_open",
15757 "unable to connect with remote engine: %s (%d)\n",
15758@@ -4160,8 +4162,8 @@ usm_set_password(const char *token, char *line)
15759 {
15760 char *cp;
15761 char nameBuf[SNMP_MAXBUF];
15762- u_char *engineID;
15763- size_t engineIDLen;
15764+ u_char *engineID = NULL;
15765+ size_t engineIDLen = 0;
15766 struct usmUser *user;
15767
15768 cp = copy_nword(line, nameBuf, sizeof(nameBuf));
15769@@ -4185,15 +4187,18 @@ usm_set_password(const char *token, char *line)
15770 cp = read_config_read_octet_string(cp, &engineID, &engineIDLen);
15771 if (cp == NULL) {
15772 config_perror("invalid engineID specifier");
15773+ SNMP_FREE(engineID);
15774 return;
15775 }
15776
15777 user = usm_get_user(engineID, engineIDLen, nameBuf);
15778 if (user == NULL) {
15779 config_perror("not a valid user/engineID pair");
15780+ SNMP_FREE(engineID);
15781 return;
15782 }
15783 usm_set_user_password(user, token, cp);
15784+ SNMP_FREE(engineID);
15785 }
15786 }
15787
15788diff --git a/snmplib/snmpv3.c b/snmplib/snmpv3.c
15789index f8bd90b..3369fb6 100644
15790--- a/snmplib/snmpv3.c
15791+++ b/snmplib/snmpv3.c
15792@@ -1274,7 +1274,7 @@ getHwAddress(const char *networkDevice, /* e.g. "eth0", "eth1" */
15793 /*
15794 * copy the name of the net device we want to find the HW address for
15795 */
15796- strncpy(request.ifr_name, networkDevice, IFNAMSIZ - 1);
15797+ strlcpy(request.ifr_name, networkDevice, IFNAMSIZ);
15798 /*
15799 * Get the HW address
15800 */
15801diff --git a/snmplib/strlcat.c b/snmplib/strlcat.c
15802new file mode 100644
15803index 0000000..90713ca
15804--- /dev/null
15805+++ b/snmplib/strlcat.c
15806@@ -0,0 +1,67 @@
15807+/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
15808+
15809+/*
15810+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
15811+ *
15812+ * Permission to use, copy, modify, and distribute this software for any
15813+ * purpose with or without fee is hereby granted, provided that the above
15814+ * copyright notice and this permission notice appear in all copies.
15815+ *
15816+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15817+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15818+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15819+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15820+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15821+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15822+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15823+ */
15824+
15825+#include <net-snmp/net-snmp-config.h>
15826+
15827+#ifndef HAVE_STRLCAT
15828+
15829+#if HAVE_STRING_H
15830+#include <string.h>
15831+#else
15832+#include <strings.h>
15833+#endif
15834+#include <sys/types.h>
15835+
15836+#include <net-snmp/library/system.h>
15837+
15838+/*
15839+ * Appends src to string dst of size siz (unlike strncat, siz is the
15840+ * full size of dst, not space left). At most siz-1 characters
15841+ * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
15842+ * Returns strlen(src) + MIN(siz, strlen(initial dst)).
15843+ * If retval >= siz, truncation occurred.
15844+ */
15845+size_t
15846+strlcat(char * __restrict dst, const char * __restrict src, size_t siz)
15847+{
15848+ char *d = dst;
15849+ const char *s = src;
15850+ size_t n = siz;
15851+ size_t dlen;
15852+
15853+ /* Find the end of dst and adjust bytes left but don't go past end */
15854+ while (n-- != 0 && *d != '\0')
15855+ d++;
15856+ dlen = d - dst;
15857+ n = siz - dlen;
15858+
15859+ if (n == 0)
15860+ return(dlen + strlen(s));
15861+ while (*s != '\0') {
15862+ if (n != 1) {
15863+ *d++ = *s;
15864+ n--;
15865+ }
15866+ s++;
15867+ }
15868+ *d = '\0';
15869+
15870+ return(dlen + (s - src)); /* count does not include NUL */
15871+}
15872+
15873+#endif
15874diff --git a/snmplib/strtoull.c b/snmplib/strtoull.c
15875index be94f29..6c98fc4 100644
15876--- a/snmplib/strtoull.c
15877+++ b/snmplib/strtoull.c
15878@@ -49,13 +49,8 @@
15879 #define ULLONG_MAX UINT64_C(0xffffffffffffffff)
15880 #endif
15881
15882-#ifdef STRTOULL_UNIT_TEST
15883-uint64_t
15884-my_strtoull(const char *nptr, char **endptr, int base)
15885-#else
15886 uint64_t
15887 strtoull(const char *nptr, char **endptr, int base)
15888-#endif
15889 {
15890 uint64_t result = 0;
15891 const char *p;
15892@@ -161,123 +156,3 @@ strtoull(const char *nptr, char **endptr, int base)
15893 *endptr = (char *) nptr;
15894 return 0;
15895 }
15896-
15897-#if defined(STRTOULL_UNIT_TEST)
15898-
15899-#include <stdio.h>
15900-#include <stdlib.h>
15901-
15902-#ifndef PRIu64
15903-#ifdef _MSC_VER
15904-#define PRIu64 "I64u"
15905-#else
15906-#define PRIu64 "llu"
15907-#endif
15908-#endif
15909-
15910-struct strtoull_testcase {
15911- /*
15912- * inputs
15913- */
15914- const char *nptr;
15915- int base;
15916- /*
15917- * expected outputs
15918- */
15919- int expected_errno;
15920- int expected_end;
15921- uint64_t expected_result;
15922-};
15923-
15924-static const struct strtoull_testcase test_input[] = {
15925- {"0x0", 0, 0, 3, 0},
15926- {"1", 0, 0, 1, 1},
15927- {"0x1", 0, 0, 3, 1},
15928- {" -0666", 0, 0, 7, -0666},
15929- {" -0x666", 0, 0, 8, -0x666},
15930- {"18446744073709551614", 0, 0, 20, UINT64_C(0xfffffffffffffffe)},
15931- {"0xfffffffffffffffe", 0, 0, 18, UINT64_C(0xfffffffffffffffe)},
15932- {"18446744073709551615", 0, 0, 20, UINT64_C(0xffffffffffffffff)},
15933- {"0xffffffffffffffff", 0, 0, 18, UINT64_C(0xffffffffffffffff)},
15934- {"18446744073709551616", 0, ERANGE, 20, UINT64_C(0xffffffffffffffff)},
15935- {"0x10000000000000000", 0, ERANGE, 19, UINT64_C(0xffffffffffffffff)},
15936- {"ff", 16, 0, 2, 255},
15937- {"0xff", 16, 0, 4, 255},
15938- {" ", 0, 0, 0, 0},
15939- {"0x", 0, 0, 1, 0},
15940- {"0x", 8, 0, 1, 0},
15941- {"0x", 16, 0, 1, 0},
15942- {"zyyy", 0, 0, 0, 0},
15943- {"0xfffffffffffffffff", 0, ERANGE, 19, ULLONG_MAX},
15944- {"0xfffffffffffffffffz", 0, ERANGE, 19, ULLONG_MAX}
15945-};
15946-
15947-int
15948-main(void)
15949-{
15950- int failure_count = 0;
15951- unsigned int i;
15952-
15953- for (i = 0; i < sizeof(test_input) / sizeof(test_input[0]); i++) {
15954- const struct strtoull_testcase *const p = &test_input[i];
15955- char *endptr;
15956- uint64_t result;
15957-
15958- errno = 0;
15959- result = my_strtoull(p->nptr, &endptr, p->base);
15960- if (errno != p->expected_errno) {
15961- failure_count++;
15962- printf("test %d failed (input \"%s\"): expected errno %d"
15963- ", got errno %d\n",
15964- i, p->nptr, p->expected_errno, errno);
15965- }
15966- if (result != p->expected_result) {
15967- failure_count++;
15968- printf("test %d failed (input \"%s\"): expected result %" PRIu64
15969- ", got result %" PRIu64 "\n",
15970- i, p->nptr, p->expected_result, result);
15971- }
15972- if (endptr - p->nptr != p->expected_end) {
15973- failure_count++;
15974- printf("test %d failed (input \"%s\"): expected end %d,"
15975- " got end %d\n",
15976- i, p->nptr, p->expected_end, (int) (endptr - p->nptr));
15977- }
15978-
15979-#if HAVE_STRTOULL
15980- errno = 0;
15981- result = strtoull(p->nptr, &endptr, p->base);
15982- if (errno != p->expected_errno) {
15983- failure_count++;
15984- printf("test %d (input \"%s\"): expected errno %d"
15985- ", libc strtoull() returned errno %d\n",
15986- i, p->nptr, p->expected_errno, errno);
15987- }
15988- if (result != p->expected_result) {
15989- failure_count++;
15990- printf("test %d (input \"%s\"): expected result %" PRIu64
15991- ", libc strtoull() returned result %" PRIu64 "\n",
15992- i, p->nptr, p->expected_result, result);
15993- }
15994- if (endptr - p->nptr != p->expected_end) {
15995- failure_count++;
15996- printf("test %d (input \"%s\"): expected end %d,"
15997- " libc strtoull() returned end %d\n",
15998- i, p->nptr, p->expected_end, (int) (endptr - p->nptr));
15999- }
16000-#endif
16001- }
16002- if (failure_count == 0)
16003- printf("All %d tests passed.\n", i);
16004- return 0;
16005-}
16006-
16007-#endif /* defined(STRTOULL_UNIT_TEST) */
16008-
16009-/*
16010- * Local variables:
16011- * c-basic-offset: 4
16012- * indent-tabs-mode: nil
16013- * compile-command: "gcc -Wall -Werror -DSTRTOULL_UNIT_TEST=1 -I../include -g -o strtoull-unit-test strtoull.c && ./strtoull-unit-test"
16014- * End:
16015- */
16016diff --git a/snmplib/system.c b/snmplib/system.c
16017index cec6c34..1070bbf 100644
16018--- a/snmplib/system.c
16019+++ b/snmplib/system.c
16020@@ -184,6 +184,8 @@ SOFTWARE.
16021 #include <net-snmp/library/snmp_api.h>
16022 #include <net-snmp/library/read_config.h> /* for get_temp_file_pattern() */
16023
16024+#include "inet_ntop.h"
16025+
16026 /* NetSNMP and DNSSEC-Tools both define FREE. We'll not use either here. */
16027 #undef FREE
16028
16029@@ -637,25 +639,19 @@ get_boottime(void)
16030 }
16031 #endif
16032
16033-/*
16034- * Returns uptime in centiseconds(!).
16035+/**
16036+ * Returns the system uptime in centiseconds.
16037+ *
16038+ * @note The value returned by this function is not identical to sysUpTime
16039+ * defined in RFC 1213. get_uptime() returns the system uptime while
16040+ * sysUpTime represents the time that has elapsed since the most recent
16041+ * restart of the network manager (snmpd).
16042+ *
16043+ * @see See also netsnmp_get_agent_uptime().
16044 */
16045 long
16046 get_uptime(void)
16047 {
16048-#if !defined(solaris2) && !defined(linux) && !defined(cygwin) && !defined(aix4) && !defined(aix5) && !defined(aix6) && !defined(aix7)
16049- struct timeval now;
16050- long boottime_csecs, nowtime_csecs;
16051-
16052- boottime_csecs = get_boottime();
16053- if (boottime_csecs == 0)
16054- return 0;
16055- gettimeofday(&now, (struct timezone *) 0);
16056- nowtime_csecs = (now.tv_sec * 100) + (now.tv_usec / 10000);
16057-
16058- return (nowtime_csecs - boottime_csecs);
16059-#endif
16060-
16061 #if defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7)
16062 struct nlist nl;
16063 int kmem;
16064@@ -668,9 +664,7 @@ get_uptime(void)
16065 read(kmem, &lbolt, sizeof(lbolt));
16066 close(kmem);
16067 return(lbolt);
16068-#endif
16069-
16070-#ifdef solaris2
16071+#elif defined(solaris2)
16072 kstat_ctl_t *ksc = kstat_open();
16073 kstat_t *ks;
16074 kid_t kid;
16075@@ -695,9 +689,7 @@ get_uptime(void)
16076 kstat_close(ksc);
16077 }
16078 return lbolt;
16079-#endif /* solaris2 */
16080-
16081-#ifdef linux
16082+#elif defined(linux) || defined(cygwin)
16083 FILE *in = fopen("/proc/uptime", "r");
16084 long uptim = 0, a, b;
16085 if (in) {
16086@@ -706,10 +698,17 @@ get_uptime(void)
16087 fclose(in);
16088 }
16089 return uptim;
16090-#endif /* linux */
16091+#else
16092+ struct timeval now;
16093+ long boottime_csecs, nowtime_csecs;
16094
16095-#ifdef cygwin
16096- return (0); /* not implemented */
16097+ boottime_csecs = get_boottime();
16098+ if (boottime_csecs == 0)
16099+ return 0;
16100+ gettimeofday(&now, (struct timezone *) 0);
16101+ nowtime_csecs = (now.tv_sec * 100) + (now.tv_usec / 10000);
16102+
16103+ return (nowtime_csecs - boottime_csecs);
16104 #endif
16105 }
16106
16107@@ -928,22 +927,33 @@ netsnmp_gethostbyname(const char *name)
16108 #endif /* HAVE_GETHOSTBYNAME */
16109 }
16110
16111+/**
16112+ * Look up the host name via DNS.
16113+ *
16114+ * @param[in] addr Pointer to the address to resolve. This argument points e.g.
16115+ * to a struct in_addr for AF_INET or to a struct in6_addr for AF_INET6.
16116+ * @param[in] len Length in bytes of *addr.
16117+ * @param[in] type Address family, e.g. AF_INET or AF_INET6.
16118+ *
16119+ * @return Pointer to a hostent structure if address lookup succeeded or NULL
16120+ * if the lookup failed.
16121+ *
16122+ * @see See also the gethostbyaddr() man page.
16123+ */
16124 struct hostent *
16125 netsnmp_gethostbyaddr(const void *addr, socklen_t len, int type)
16126 {
16127 #if HAVE_GETHOSTBYADDR
16128 struct hostent *hp = NULL;
16129- struct sockaddr_in *saddr_in =
16130- NETSNMP_REMOVE_CONST(struct sockaddr_in *,addr);
16131+ char buf[64];
16132
16133- DEBUGMSGTL(("dns:gethostbyaddr", "resolving { AF_INET, %s:%hu }\n",
16134- inet_ntoa(saddr_in->sin_addr), ntohs(saddr_in->sin_port)));
16135+ DEBUGMSGTL(("dns:gethostbyaddr", "resolving %s\n",
16136+ inet_ntop(type, addr, buf, sizeof(buf))));
16137
16138 #ifdef DNSSEC_LOCAL_VALIDATION
16139 val_status_t val_status;
16140- hp = val_gethostbyaddr(netsnmp_validator_context(),
16141- (const void*)&saddr_in->sin_addr,
16142- sizeof(struct in_addr), AF_INET, &val_status);
16143+ hp = val_gethostbyaddr(netsnmp_validator_context(), addr, len, type,
16144+ &val_status);
16145 DEBUGMSGTL(("dns:sec:val", "val_status %d / %s; trusted: %d\n",
16146 val_status, p_val_status(val_status),
16147 val_istrusted(val_status)));
16148@@ -959,8 +969,7 @@ netsnmp_gethostbyaddr(const void *addr, socklen_t len, int type)
16149 else if (val_does_not_exist(val_status) && hp)
16150 hp = NULL;
16151 #else
16152- hp = gethostbyaddr((const void*) &saddr_in->sin_addr,
16153- sizeof(struct in_addr), AF_INET);
16154+ hp = gethostbyaddr(addr, len, type);
16155 #endif
16156 if (hp == NULL) {
16157 DEBUGMSGTL(("dns:gethostbyaddr", "couldn't resolve addr\n"));
16158@@ -1069,44 +1078,30 @@ setenv(const char *name, const char *value, int overwrite)
16159 }
16160 #endif /* HAVE_SETENV */
16161
16162-/* returns centiseconds */
16163 netsnmp_feature_child_of(calculate_time_diff, netsnmp_unused)
16164 #ifndef NETSNMP_FEATURE_REMOVE_CALCULATE_TIME_DIFF
16165+/**
16166+ * Compute (*now - *then) in centiseconds.
16167+ */
16168 int
16169 calculate_time_diff(const struct timeval *now, const struct timeval *then)
16170 {
16171- struct timeval tmp, diff;
16172- memcpy(&tmp, now, sizeof(struct timeval));
16173- tmp.tv_sec--;
16174- tmp.tv_usec += 1000000L;
16175- diff.tv_sec = tmp.tv_sec - then->tv_sec;
16176- diff.tv_usec = tmp.tv_usec - then->tv_usec;
16177- if (diff.tv_usec > 1000000L) {
16178- diff.tv_usec -= 1000000L;
16179- diff.tv_sec++;
16180- }
16181+ struct timeval diff;
16182+
16183+ NETSNMP_TIMERSUB(now, then, &diff);
16184 return (int)(diff.tv_sec * 100 + diff.tv_usec / 10000);
16185 }
16186 #endif /* NETSNMP_FEATURE_REMOVE_CALCULATE_TIME_DIFF */
16187
16188 #ifndef NETSNMP_FEATURE_REMOVE_CALCULATE_SECTIME_DIFF
16189-/* returns diff in rounded seconds */
16190+/** Compute rounded (*now - *then) in seconds. */
16191 u_int
16192 calculate_sectime_diff(const struct timeval *now, const struct timeval *then)
16193 {
16194- struct timeval tmp, diff;
16195- memcpy(&tmp, now, sizeof(struct timeval));
16196- tmp.tv_sec--;
16197- tmp.tv_usec += 1000000L;
16198- diff.tv_sec = tmp.tv_sec - then->tv_sec;
16199- diff.tv_usec = tmp.tv_usec - then->tv_usec;
16200- if (diff.tv_usec >= 1000000L) {
16201- diff.tv_usec -= 1000000L;
16202- diff.tv_sec++;
16203- }
16204- if (diff.tv_usec >= 500000L)
16205- return (u_int)(diff.tv_sec + 1);
16206- return (u_int)(diff.tv_sec);
16207+ struct timeval diff;
16208+
16209+ NETSNMP_TIMERSUB(now, then, &diff);
16210+ return diff.tv_sec + (diff.tv_usec >= 500000L);
16211 }
16212 #endif /* NETSNMP_FEATURE_REMOVE_CALCULATE_SECTIME_DIFF */
16213
16214@@ -1171,8 +1166,17 @@ mkdirhier(const char *pathname, mode_t mode, int skiplast)
16215 struct stat sbuf;
16216 char *ourcopy = strdup(pathname);
16217 char *entry;
16218- char buf[SNMP_MAXPATH];
16219+ char *buf = NULL;
16220 char *st = NULL;
16221+ int res;
16222+
16223+ res = SNMPERR_GENERR;
16224+ if (!ourcopy)
16225+ goto out;
16226+
16227+ buf = malloc(strlen(pathname) + 2);
16228+ if (!buf)
16229+ goto out;
16230
16231 #if defined (WIN32) || defined (cygwin)
16232 /* convert backslash to forward slash */
16233@@ -1215,12 +1219,9 @@ mkdirhier(const char *pathname, mode_t mode, int skiplast)
16234 #else
16235 if (mkdir(buf, mode) == -1)
16236 #endif
16237- {
16238- free(ourcopy);
16239- return SNMPERR_GENERR;
16240- } else {
16241+ goto out;
16242+ else
16243 snmp_log(LOG_INFO, "Created directory: %s\n", buf);
16244- }
16245 } else {
16246 /*
16247 * exists, is it a file?
16248@@ -1229,13 +1230,15 @@ mkdirhier(const char *pathname, mode_t mode, int skiplast)
16249 /*
16250 * ack! can't make a directory on top of a file
16251 */
16252- free(ourcopy);
16253- return SNMPERR_GENERR;
16254+ goto out;
16255 }
16256 }
16257 }
16258+ res = SNMPERR_SUCCESS;
16259+out:
16260+ free(buf);
16261 free(ourcopy);
16262- return SNMPERR_SUCCESS;
16263+ return res;
16264 }
16265
16266 /**
16267@@ -1254,9 +1257,14 @@ netsnmp_mktemp(void)
16268 #endif
16269 int fd = -1;
16270
16271- strcpy(name, get_temp_file_pattern());
16272+ strlcpy(name, get_temp_file_pattern(), sizeof(name));
16273 #ifdef HAVE_MKSTEMP
16274- fd = mkstemp(name);
16275+ {
16276+ mode_t oldmask = umask(~(S_IRUSR | S_IWUSR));
16277+ netsnmp_assert(oldmask != -1);
16278+ fd = mkstemp(name);
16279+ umask(oldmask);
16280+ }
16281 #else
16282 if (mktemp(name)) {
16283 # ifndef WIN32
16284@@ -1353,6 +1361,15 @@ netsnmp_os_kernel_width(void)
16285
16286 netsnmp_feature_child_of(str_to_uid, user_information)
16287 #ifndef NETSNMP_FEATURE_REMOVE_STR_TO_UID
16288+/**
16289+ * Convert a user name or number into numeric form.
16290+ *
16291+ * @param[in] useroruid Either a Unix user name or the ASCII representation
16292+ * of a user number.
16293+ *
16294+ * @return Either a user number > 0 or 0 if useroruid is not a valid user
16295+ * name, not a valid user number or the name of the root user.
16296+ */
16297 int netsnmp_str_to_uid(const char *useroruid) {
16298 int uid;
16299 #if HAVE_GETPWNAM && HAVE_PWD_H
16300@@ -1361,13 +1378,13 @@ int netsnmp_str_to_uid(const char *useroruid) {
16301
16302 uid = atoi(useroruid);
16303
16304- if ( uid == 0 ) {
16305+ if (uid == 0) {
16306 #if HAVE_GETPWNAM && HAVE_PWD_H
16307- pwd = getpwnam( useroruid );
16308- if (pwd)
16309- uid = pwd->pw_uid;
16310- else
16311+ pwd = getpwnam(useroruid);
16312+ uid = pwd ? pwd->pw_uid : 0;
16313+ endpwent();
16314 #endif
16315+ if (uid == 0)
16316 snmp_log(LOG_WARNING, "Can't identify user (%s).\n", useroruid);
16317 }
16318 return uid;
16319@@ -1377,23 +1394,31 @@ int netsnmp_str_to_uid(const char *useroruid) {
16320
16321 netsnmp_feature_child_of(str_to_gid, user_information)
16322 #ifndef NETSNMP_FEATURE_REMOVE_STR_TO_GID
16323-int netsnmp_str_to_gid(const char *grouporgid) {
16324+/**
16325+ * Convert a group name or number into numeric form.
16326+ *
16327+ * @param[in] grouporgid Either a Unix group name or the ASCII representation
16328+ * of a group number.
16329+ *
16330+ * @return Either a group number > 0 or 0 if grouporgid is not a valid group
16331+ * name, not a valid group number or the root group.
16332+ */
16333+int netsnmp_str_to_gid(const char *grouporgid)
16334+{
16335 int gid;
16336-#if HAVE_GETGRNAM && HAVE_GRP_H
16337- struct group *grp;
16338-#endif
16339
16340 gid = atoi(grouporgid);
16341
16342- if ( gid == 0 ) {
16343+ if (gid == 0) {
16344 #if HAVE_GETGRNAM && HAVE_GRP_H
16345- grp = getgrnam( grouporgid );
16346- if (grp)
16347- gid = grp->gr_gid;
16348- else
16349+ struct group *grp;
16350+
16351+ grp = getgrnam(grouporgid);
16352+ gid = grp ? grp->gr_gid : 0;
16353+ endgrent();
16354 #endif
16355- snmp_log(LOG_WARNING, "Can't identify group (%s).\n",
16356- grouporgid);
16357+ if (gid == 0)
16358+ snmp_log(LOG_WARNING, "Can't identify group (%s).\n", grouporgid);
16359 }
16360
16361 return gid;
16362diff --git a/snmplib/test_binary_array.c b/snmplib/test_binary_array.c
16363deleted file mode 100644
16364index 44b1f0e..0000000
16365--- a/snmplib/test_binary_array.c
16366+++ /dev/null
16367@@ -1,171 +0,0 @@
16368-#include <net-snmp/net-snmp-config.h>
16369-
16370-#if HAVE_IO_H
16371-#include <io.h>
16372-#endif
16373-#include <stdio.h>
16374-#if HAVE_STDLIB_H
16375-#include <stdlib.h>
16376-#endif
16377-#if HAVE_MALLOC_H
16378-#include <malloc.h>
16379-#endif
16380-#include <sys/types.h>
16381-#if HAVE_STRING_H
16382-#include <string.h>
16383-#else
16384-#include <strings.h>
16385-#endif
16386-
16387-#include <net-snmp/net-snmp-includes.h>
16388-#include <net-snmp/types.h>
16389-#include <net-snmp/library/snmp_api.h>
16390-#include <net-snmp/library/container.h>
16391-#include <net-snmp/library/container_binary_array.h>
16392-#include <net-snmp/library/tools.h>
16393-#include <net-snmp/library/snmp_assert.h>
16394-
16395-#define TEST_SIZE 7
16396-
16397-void
16398-print_int(netsnmp_index *i, void *v)
16399-{
16400- printf("item %p = %ld\n", i, i->oids[0]);
16401-}
16402-
16403-int
16404-test_int(void)
16405-{
16406- oid o1 = 1;
16407- oid o2 = 2;
16408- oid o3 = 6;
16409- oid o4 = 8;
16410- oid o5 = 9;
16411- oid ox = 7;
16412- oid oy = 10;
16413- netsnmp_index i1,i2,i3,i4,i5,ix,iy, *ip;
16414- netsnmp_index *a[TEST_SIZE] = { &i1, &i2, &i3, &ix, &i4, &i5, &iy };
16415- netsnmp_container *c = netsnmp_container_get_binary_array();
16416- int i;
16417-
16418- c->compare = netsnmp_compare_netsnmp_index;
16419-
16420- i1.oids = &o1;
16421- i2.oids = &o2;
16422- i3.oids = &o3;
16423- i4.oids = &o4;
16424- i5.oids = &o5;
16425- ix.oids = &ox;
16426- iy.oids = &oy;
16427- i1.len = i2.len = i3.len = i4.len = i5.len = ix.len = iy.len = 1;
16428-
16429- printf("Creating container...\n");
16430-
16431- printf("Inserting data...\n");
16432- CONTAINER_INSERT(c,&i4);
16433- CONTAINER_INSERT(c,&i2);
16434- CONTAINER_INSERT(c,&i3);
16435- CONTAINER_INSERT(c,&i1);
16436- CONTAINER_INSERT(c,&i5);
16437-
16438- printf("For each...\n");
16439- CONTAINER_FOR_EACH(c, print_int, NULL);
16440- printf("Done.\n");
16441-
16442- printf("\n");
16443- ip = CONTAINER_FIRST(c);
16444- printf("Find first = %p %ld\n",ip, ip->oids[0]);
16445- while( ip ) {
16446- ip = CONTAINER_NEXT(c,ip);
16447- if(ip)
16448- printf("Find next = %p %ld\n",ip, ip->oids[0]);
16449- else
16450- printf("Find next = %s\n",ip);
16451- }
16452-
16453- for( i=0; i < TEST_SIZE; ++i) {
16454- printf("\n");
16455- ip = CONTAINER_FIND(c,a[i]);
16456- printf("Find %ld = %p %ld\n", a[i]->oids[0], ip, ip ? ip->oids[0] : 0);
16457- ip = CONTAINER_NEXT(c,a[i]);
16458- printf("Next %ld = %p %ld\n", a[i]->oids[0], ip, ip ? ip->oids[0] : 0);
16459- }
16460-
16461- printf("Done.\n");
16462-
16463- return 0;
16464-}
16465-
16466-void
16467-print_string(char *i, void *v)
16468-{
16469- printf("item %s\n", i);
16470-}
16471-
16472-int
16473-my_strcmp(char *lhs, char *rhs)
16474-{
16475- int rc = strcmp(lhs,rhs);
16476-/* printf("%s %d %s\n",lhs, rc, rhs); */
16477- return rc;
16478-}
16479-
16480-int
16481-test_string()
16482-{
16483- const char *o1 = "zebra";
16484- const char *o2 = "b-two";
16485- const char *o3 = "b";
16486- const char *o4 = "cedar";
16487- const char *o5 = "alpha";
16488- const char *ox = "dev";
16489- const char *oy = "aa";
16490- const char * ip;
16491-
16492- const char *a[TEST_SIZE] = { o1, o2, o3, ox, o4, o5, oy };
16493- netsnmp_container *c = netsnmp_container_get_binary_array();
16494- int i;
16495-
16496- c->compare = my_strcmp;
16497-
16498- printf("Creating container...\n");
16499-
16500- printf("Inserting data...\n");
16501- CONTAINER_INSERT(c,o4);
16502- CONTAINER_INSERT(c,o2);
16503- CONTAINER_INSERT(c,o3);
16504- CONTAINER_INSERT(c,o1);
16505- CONTAINER_INSERT(c,o5);
16506- printf("\n");
16507- printf("For each...\n");
16508- CONTAINER_FOR_EACH(c, print_string, NULL);
16509- printf("Done.\n");
16510-
16511- printf("\n");
16512- ip = CONTAINER_FIRST(c);
16513- printf("Find first = %s\n",ip);
16514- while( ip ) {
16515- ip = CONTAINER_NEXT(c,ip);
16516- printf("Find next = %s\n",ip);
16517- }
16518-
16519- for( i=0; i < TEST_SIZE; ++i) {
16520- printf("\n");
16521- ip = CONTAINER_FIND(c,a[i]);
16522- printf("Find %s = %s\n", a[i], ip);
16523- ip = CONTAINER_NEXT(c,a[i]);
16524- printf("Next %s = %s\n", a[i], ip);
16525- }
16526-
16527- printf("Done.\n");
16528-
16529- return 0;
16530-}
16531-
16532-int
16533-main(int argc, char** argv)
16534-{
16535-
16536- test_int();
16537- test_string();
16538-}
16539diff --git a/snmplib/tools.c b/snmplib/tools.c
16540index 676f36c..b2be790 100644
16541--- a/snmplib/tools.c
16542+++ b/snmplib/tools.c
16543@@ -613,7 +613,7 @@ void
16544 dump_chunk(const char *debugtoken, const char *title, const u_char * buf,
16545 int size)
16546 {
16547- u_int printunit = 64; /* XXX Make global. */
16548+ int printunit = 64; /* XXX Make global. */
16549 char chunk[SNMP_MAXBUF], *s, *sp;
16550
16551 if (title && (*title != '\0')) {
16552@@ -626,8 +626,8 @@ dump_chunk(const char *debugtoken, const char *title, const u_char * buf,
16553 sp = s;
16554
16555 while (size > 0) {
16556- if (size > (int) printunit) {
16557- strncpy(chunk, sp, printunit);
16558+ if (size > printunit) {
16559+ memcpy(chunk, sp, printunit);
16560 chunk[printunit] = '\0';
16561 DEBUGMSGTL((debugtoken, "\t%s\n", chunk));
16562 } else {
16563@@ -803,15 +803,10 @@ dump_snmpEngineID(const u_char * estring, size_t * estring_len)
16564
16565 case 4: /* Text. */
16566
16567- /*
16568- * Doesn't exist on all (many) architectures
16569- */
16570- /*
16571- * s += snprintf(s, remaining_len+3, "\"%s\"", esp);
16572- */
16573- s += sprintf(s, "\"%.*s\"", sizeof(buf)-strlen(buf)-3, esp);
16574+ s += sprintf(s, "\"%.*s\"", (int) (sizeof(buf)-strlen(buf)-3), esp);
16575 goto dump_snmpEngineID_quit;
16576 break;
16577+
16578 /*NOTREACHED*/ case 5: /* Octets. */
16579
16580 snprint_hexstring(s, (SNMP_MAXBUF - (s-buf)),
16581@@ -820,6 +815,7 @@ dump_snmpEngineID(const u_char * estring, size_t * estring_len)
16582 s -= 1;
16583 goto dump_snmpEngineID_quit;
16584 break;
16585+
16586 /*NOTREACHED*/ dump_snmpEngineID_violation:
16587 case 0: /* Violation of RESERVED,
16588 * * -OR- of expected length.
16589@@ -941,11 +937,11 @@ uatime_hdiff(const_marker_t first, const_marker_t second)
16590 }
16591
16592 /**
16593- * Test: Has (marked time plus delta) exceeded current time (in msec) ?
16594+ * Test: Has (marked time plus delta) exceeded current time ?
16595 * Returns 0 if test fails or cannot be tested (no marker).
16596 */
16597 int
16598-atime_ready(const_marker_t pm, int deltaT)
16599+atime_ready(const_marker_t pm, int delta_ms)
16600 {
16601 marker_t now;
16602 long diff;
16603@@ -956,19 +952,19 @@ atime_ready(const_marker_t pm, int deltaT)
16604
16605 diff = atime_diff(pm, now);
16606 free(now);
16607- if (diff < deltaT)
16608+ if (diff < delta_ms)
16609 return 0;
16610
16611 return 1;
16612 }
16613
16614+#ifndef NETSNMP_FEATURE_REMOVE_UATIME_READY
16615 /**
16616- * Test: Has (marked time plus delta) exceeded current time (in msec) ?
16617+ * Test: Has (marked time plus delta) exceeded current time ?
16618 * Returns 0 if test fails or cannot be tested (no marker).
16619 */
16620-#ifndef NETSNMP_FEATURE_REMOVE_UATIME_READY
16621 int
16622-uatime_ready(const_marker_t pm, unsigned int deltaT)
16623+uatime_ready(const_marker_t pm, unsigned int delta_ms)
16624 {
16625 marker_t now;
16626 u_long diff;
16627@@ -979,7 +975,7 @@ uatime_ready(const_marker_t pm, unsigned int deltaT)
16628
16629 diff = uatime_diff(pm, now);
16630 free(now);
16631- if (diff < deltaT)
16632+ if (diff < delta_ms)
16633 return 0;
16634
16635 return 1;
16636diff --git a/snmplib/transports/snmpAAL5PVCDomain.c b/snmplib/transports/snmpAAL5PVCDomain.c
16637index f6684f0..5ac69a1 100644
16638--- a/snmplib/transports/snmpAAL5PVCDomain.c
16639+++ b/snmplib/transports/snmpAAL5PVCDomain.c
16640@@ -32,6 +32,7 @@
16641 #include <net-snmp/config_api.h>
16642
16643 #include <net-snmp/library/snmp_transport.h>
16644+#include <net-snmp/library/tools.h>
16645
16646
16647 oid netsnmp_AAL5PVCDomain[10] = { NETSNMP_ENTERPRISE_MIB, 3, 3, 3 };
16648@@ -87,11 +88,13 @@ netsnmp_aal5pvc_recv(netsnmp_transport *t, void *buf, int size,
16649 }
16650
16651 if (rc >= 0) {
16652- char *str = netsnmp_aal5pvc_fmtaddr(t, NULL, 0);
16653- DEBUGMSGTL(("netsnmp_aal5pvc",
16654- "recv on fd %d got %d bytes (from %s)\n", t->sock,
16655- rc, str));
16656- free(str);
16657+ DEBUGIF("netsnmp_aal5pvc") {
16658+ char *str = netsnmp_aal5pvc_fmtaddr(t, NULL, 0);
16659+ DEBUGMSGTL(("netsnmp_aal5pvc",
16660+ "recv on fd %d got %d bytes (from %s)\n", t->sock,
16661+ rc, str));
16662+ free(str);
16663+ }
16664 } else {
16665 DEBUGMSGTL(("netsnmp_aal5pvc", "recv on fd %d err %d (\"%s\")\n",
16666 t->sock, errno, strerror(errno)));
16667@@ -120,11 +123,14 @@ netsnmp_aal5pvc_send(netsnmp_transport *t, void *buf, int size,
16668 }
16669
16670 if (to != NULL && t != NULL && t->sock >= 0) {
16671- char *str = netsnmp_aal5pvc_fmtaddr(NULL, (void *)to,
16672- sizeof(struct sockaddr_atmpvc));
16673- DEBUGMSGTL(("netsnmp_aal5pvc","send %d bytes from %p to %s on fd %d\n",
16674- size, buf, str, t->sock));
16675- free(str);
16676+ DEBUGIF("netsnmp_aal5pvc") {
16677+ char *str = netsnmp_aal5pvc_fmtaddr(NULL, (void *)to,
16678+ sizeof(struct sockaddr_atmpvc));
16679+ DEBUGMSGTL(("netsnmp_aal5pvc",
16680+ "send %d bytes from %p to %s on fd %d\n",
16681+ size, buf, str, t->sock));
16682+ free(str);
16683+ }
16684 while (rc < 0) {
16685 rc = sendto(t->sock, buf, size, 0, NULL, 0);
16686 if (rc < 0 && errno != EINTR) {
16687@@ -165,8 +171,6 @@ netsnmp_aal5pvc_close(netsnmp_transport *t)
16688 netsnmp_transport *
16689 netsnmp_aal5pvc_transport(struct sockaddr_atmpvc *addr, int local)
16690 {
16691- char *str = NULL;
16692- struct atm_qos qos;
16693 netsnmp_transport *t = NULL;
16694
16695 #ifdef NETSNMP_NO_LISTEN_SUPPORT
16696@@ -178,18 +182,18 @@ netsnmp_aal5pvc_transport(struct sockaddr_atmpvc *addr, int local)
16697 return NULL;
16698 }
16699
16700- t = (netsnmp_transport *) malloc(sizeof(netsnmp_transport));
16701+ t = SNMP_MALLOC_TYPEDEF(netsnmp_transport);
16702 if (t == NULL) {
16703 return NULL;
16704 }
16705
16706- str = netsnmp_aal5pvc_fmtaddr(NULL, (void *) addr,
16707- sizeof(struct sockaddr_atmpvc));
16708- DEBUGMSGTL(("netsnmp_aal5pvc", "open %s %s\n", local ? "local" : "remote",
16709- str));
16710- free(str);
16711-
16712- memset(t, 0, sizeof(netsnmp_transport));
16713+ DEBUGIF("netsnmp_aal5pvc") {
16714+ char *str = netsnmp_aal5pvc_fmtaddr(NULL, (void *) addr,
16715+ sizeof(struct sockaddr_atmpvc));
16716+ DEBUGMSGTL(("netsnmp_aal5pvc", "open %s %s\n",
16717+ local ? "local" : "remote", str));
16718+ free(str);
16719+ }
16720
16721 t->domain = netsnmp_AAL5PVCDomain;
16722 t->domain_length =
16723@@ -203,22 +207,24 @@ netsnmp_aal5pvc_transport(struct sockaddr_atmpvc *addr, int local)
16724 }
16725 DEBUGMSGTL(("netsnmp_aal5pvc", "fd %d opened\n", t->sock));
16726
16727- /*
16728- * Set up the QOS parameters.
16729- */
16730+ {
16731+ /*
16732+ * Set up the QOS parameters.
16733+ */
16734
16735- memset(&qos, 0, sizeof(struct atm_qos));
16736- qos.aal = ATM_AAL5;
16737- qos.rxtp.traffic_class = ATM_UBR;
16738- qos.rxtp.max_sdu = SNMP_MAX_LEN; /* Hmm -- this is a bit small? */
16739- qos.txtp = qos.rxtp;
16740+ struct atm_qos qos = { 0 };
16741+ qos.aal = ATM_AAL5;
16742+ qos.rxtp.traffic_class = ATM_UBR;
16743+ qos.rxtp.max_sdu = SNMP_MAX_LEN; /* Hmm -- this is a bit small? */
16744+ qos.txtp = qos.rxtp;
16745
16746- if (setsockopt(t->sock, SOL_ATM, SO_ATMQOS, &qos, sizeof(qos)) < 0) {
16747- DEBUGMSGTL(("netsnmp_aal5pvc", "setsockopt failed (%s)\n",
16748- strerror(errno)));
16749- netsnmp_aal5pvc_close(t);
16750- netsnmp_transport_free(t);
16751- return NULL;
16752+ if (setsockopt(t->sock, SOL_ATM, SO_ATMQOS, &qos, sizeof(qos)) < 0) {
16753+ DEBUGMSGTL(("netsnmp_aal5pvc", "setsockopt failed (%s)\n",
16754+ strerror(errno)));
16755+ netsnmp_aal5pvc_close(t);
16756+ netsnmp_transport_free(t);
16757+ return NULL;
16758+ }
16759 }
16760
16761 if (local) {
16762diff --git a/snmplib/transports/snmpCallbackDomain.c b/snmplib/transports/snmpCallbackDomain.c
16763index e487f28..95018b8 100644
16764--- a/snmplib/transports/snmpCallbackDomain.c
16765+++ b/snmplib/transports/snmpCallbackDomain.c
16766@@ -353,7 +353,7 @@ netsnmp_callback_accept(netsnmp_transport *t)
16767 {
16768 DEBUGMSGTL(("transport_callback", "hook_accept enter\n"));
16769 DEBUGMSGTL(("transport_callback", "hook_accept exit\n"));
16770- return 0;
16771+ return -1;
16772 }
16773
16774
16775@@ -385,8 +385,10 @@ netsnmp_callback_transport(int to)
16776 * our stuff
16777 */
16778 mydata = SNMP_MALLOC_TYPEDEF(netsnmp_callback_info);
16779- if (!mydata)
16780+ if (!mydata) {
16781+ SNMP_FREE(t);
16782 return NULL;
16783+ }
16784 mydata->linkedto = to;
16785 mydata->callback_num = ++callback_count;
16786 mydata->data = NULL;
16787diff --git a/snmplib/transports/snmpDTLSUDPDomain.c b/snmplib/transports/snmpDTLSUDPDomain.c
16788index fcbc5a2..9c56d19 100644
16789--- a/snmplib/transports/snmpDTLSUDPDomain.c
16790+++ b/snmplib/transports/snmpDTLSUDPDomain.c
16791@@ -231,8 +231,10 @@ start_new_cached_connection(netsnmp_transport *t,
16792 return NULL;
16793
16794 /* allocate our TLS specific data */
16795- if (NULL == (tlsdata = netsnmp_tlsbase_allocate_tlsdata(t, !we_are_client)))
16796+ if (NULL == (tlsdata = netsnmp_tlsbase_allocate_tlsdata(t, !we_are_client))) {
16797+ SNMP_FREE(cachep);
16798 return NULL;
16799+ }
16800 cachep->tlsdata = tlsdata;
16801
16802 /* RFC5953: section 5.3.1, step 1:
16803@@ -427,7 +429,7 @@ _extract_addr_pair(netsnmp_transport *t, void *opaque, int olen)
16804
16805 if (opaque && olen == sizeof(netsnmp_tmStateReference)) {
16806 netsnmp_tmStateReference *tmStateRef =
16807- tmStateRef = (netsnmp_tmStateReference *) opaque;
16808+ (netsnmp_tmStateReference *) opaque;
16809
16810 if (tmStateRef->have_addresses)
16811 addr_pair = &(tmStateRef->addresses);
16812@@ -817,6 +819,7 @@ netsnmp_dtlsudp_recv(netsnmp_transport *t, void *buf, int size,
16813 DEBUGMSGTL(("dtlsudp", "peer disconnected\n"));
16814 cachep->flags |= NETSNMP_BIO_DISCONNECTED;
16815 remove_and_free_bio_cache(cachep);
16816+ SNMP_FREE(tmStateRef);
16817 return rc;
16818 }
16819 cachep->flags |= NETSNMP_BIO_CONNECTED;
16820@@ -913,6 +916,7 @@ netsnmp_dtlsudp_recv(netsnmp_transport *t, void *buf, int size,
16821 /* XXX: probably need to check for whether we should
16822 send stuff from our end to continue the transaction
16823 */
16824+ SNMP_FREE(tmStateRef);
16825 return -1;
16826 } else {
16827 /* XXX: free needed memory */
16828@@ -922,6 +926,7 @@ netsnmp_dtlsudp_recv(netsnmp_transport *t, void *buf, int size,
16829 /* Step 5 says these are always incremented */
16830 snmp_increment_statistic(STAT_TLSTM_SNMPTLSTMSESSIONINVALIDSERVERCERTIFICATES);
16831 snmp_increment_statistic(STAT_TLSTM_SNMPTLSTMSESSIONOPENERRORS);
16832+ SNMP_FREE(tmStateRef);
16833 return -1;
16834 }
16835 }
16836@@ -939,12 +944,14 @@ netsnmp_dtlsudp_recv(netsnmp_transport *t, void *buf, int size,
16837 /* XXX: probably need to check for whether we should
16838 send stuff from our end to continue the transaction
16839 */
16840+ SNMP_FREE(tmStateRef);
16841 return -1;
16842 } else {
16843 /* XXX: free needed memory */
16844 snmp_log(LOG_ERR,
16845 "DTLSUDP: failed to verify ssl certificate (of the client)\n");
16846 snmp_increment_statistic(STAT_TLSTM_SNMPTLSTMSESSIONINVALIDCLIENTCERTIFICATES);
16847+ SNMP_FREE(tmStateRef);
16848 return -1;
16849 }
16850 }
16851@@ -1061,7 +1068,7 @@ netsnmp_dtlsudp_send(netsnmp_transport *t, void *buf, int size,
16852 specs) then we create one automatically here.
16853 */
16854 if (opaque != NULL && *opaque != NULL &&
16855- *olength == sizeof(netsnmp_tmStateReference))
16856+ olength != NULL && *olength == sizeof(netsnmp_tmStateReference))
16857 tmStateRef = (netsnmp_tmStateReference *) *opaque;
16858
16859
16860@@ -1506,13 +1513,11 @@ netsnmp_dtlsudp_create_tstring(const char *str, int isserver,
16861 tlsdata = (_netsnmpTLSBaseData *) t->data;
16862 /* search for a : */
16863 if (NULL != (cp = strrchr(str, ':'))) {
16864- strncpy(buf, str, SNMP_MIN(cp-str, sizeof(buf)-1));
16865- buf[SNMP_MIN(cp-str, sizeof(buf)-1)] = '\0';
16866+ sprintf(buf, "%.*s", (int) SNMP_MIN(cp - str, sizeof(buf) - 1),
16867+ str);
16868 } else {
16869 /* else the entire spec is a host name only */
16870- strncpy(buf, str,
16871- SNMP_MIN(strlen(str), sizeof(buf)-1));
16872- buf[SNMP_MIN(strlen(str), sizeof(buf)-1)] = '\0';
16873+ strlcpy(buf, str, sizeof(buf));
16874 }
16875 tlsdata->their_hostname = strdup(buf);
16876 }
16877diff --git a/snmplib/transports/snmpIPXDomain.c b/snmplib/transports/snmpIPXDomain.c
16878index 75994d4..24c13a4 100644
16879--- a/snmplib/transports/snmpIPXDomain.c
16880+++ b/snmplib/transports/snmpIPXDomain.c
16881@@ -34,6 +34,7 @@
16882 #include <net-snmp/config_api.h>
16883
16884 #include <net-snmp/library/snmp_transport.h>
16885+#include <net-snmp/library/tools.h>
16886
16887 #define SNMP_IPX_DEFAULT_PORT 36879 /* Specified in RFC 1420. */
16888 static netsnmp_tdomain ipxDomain;
16889@@ -99,10 +100,13 @@ netsnmp_ipx_recv(netsnmp_transport *t, void *buf, int size,
16890 }
16891
16892 if (rc >= 0) {
16893- char *str = netsnmp_ipx_fmtaddr(NULL, from, fromlen);
16894- DEBUGMSGTL(("netsnmp_ipx","recvfrom fd %d got %d bytes(from %s)\n",
16895- t->sock, rc, str));
16896- free(str);
16897+ DEBUGIF("netsnmp_ipx") {
16898+ char *str = netsnmp_ipx_fmtaddr(NULL, from, fromlen);
16899+ DEBUGMSGTL(("netsnmp_ipx",
16900+ "recvfrom fd %d got %d bytes(from %s)\n",
16901+ t->sock, rc, str));
16902+ free(str);
16903+ }
16904 } else {
16905 DEBUGMSGTL(("netsnmp_ipx", "recvfrom fd %d err %d (\"%s\")\n",
16906 t->sock, errno, strerror(errno)));
16907@@ -131,11 +135,13 @@ netsnmp_ipx_send(netsnmp_transport *t, void *buf, int size,
16908 }
16909
16910 if (to != NULL && t != NULL && t->sock >= 0) {
16911- char *str = netsnmp_ipx_fmtaddr(NULL, (void *)to,
16912- sizeof(struct sockaddr_ipx));
16913- DEBUGMSGTL(("netsnmp_ipx", "send %d bytes from %p to %s on fd %d\n",
16914- size, buf, str, t->sock));
16915- free(str);
16916+ DEBUGIF("netsnmp_ipx") {
16917+ char *str = netsnmp_ipx_fmtaddr(NULL, (void *)to,
16918+ sizeof(struct sockaddr_ipx));
16919+ DEBUGMSGTL(("netsnmp_ipx", "send %d bytes from %p to %s on fd %d\n",
16920+ size, buf, str, t->sock));
16921+ free(str);
16922+ }
16923 while (rc < 0) {
16924 rc = sendto(t->sock, buf, size, 0, to, sizeof(struct sockaddr));
16925 if (rc < 0 && errno != EINTR) {
16926@@ -176,7 +182,6 @@ netsnmp_ipx_transport(struct sockaddr_ipx *addr, int local)
16927 {
16928 netsnmp_transport *t = NULL;
16929 int rc = 0;
16930- char *str = NULL;
16931
16932 #ifdef NETSNMP_NO_LISTEN_SUPPORT
16933 if (local)
16934@@ -187,18 +192,18 @@ netsnmp_ipx_transport(struct sockaddr_ipx *addr, int local)
16935 return NULL;
16936 }
16937
16938- t = (netsnmp_transport *) malloc(sizeof(netsnmp_transport));
16939+ t = SNMP_MALLOC_TYPEDEF(netsnmp_transport);
16940 if (t == NULL) {
16941 return NULL;
16942 }
16943
16944- str = netsnmp_ipx_fmtaddr(NULL, (void *)addr,
16945- sizeof(struct sockaddr_ipx));
16946- DEBUGMSGTL(("netsnmp_ipx", "open %s %s\n", local ? "local" : "remote",
16947- str));
16948- free(str);
16949-
16950- memset(t, 0, sizeof(netsnmp_transport));
16951+ DEBUGIF("netsnmp_ipx") {
16952+ char *str = netsnmp_ipx_fmtaddr(NULL, (void *)addr,
16953+ sizeof(struct sockaddr_ipx));
16954+ DEBUGMSGTL(("netsnmp_ipx", "open %s %s\n", local ? "local" : "remote",
16955+ str));
16956+ free(str);
16957+ }
16958
16959 t->domain = netsnmpIPXDomain;
16960 t->domain_length = netsnmpIPXDomain_len;
16961@@ -358,9 +363,7 @@ netsnmp_sockaddr_ipx2(struct sockaddr_ipx *addr, const char *peername,
16962 node = "000000000000";
16963
16964 if (port == NULL || *port == '\0')
16965-#define val(x) __STRING(x)
16966- port = val(SNMP_IPX_DEFAULT_PORT);
16967-#undef val
16968+ port = __STRING(SNMP_IPX_DEFAULT_PORT);
16969
16970 DEBUGMSGTL(("netsnmp_sockaddr_ipx", "Address: %s:%s/%s\n",
16971 network ? network : "[NIL]", node ? node : "[NIL]",
16972diff --git a/snmplib/transports/snmpIPv6BaseDomain.c b/snmplib/transports/snmpIPv6BaseDomain.c
16973index a7daf1c..9bad950 100644
16974--- a/snmplib/transports/snmpIPv6BaseDomain.c
16975+++ b/snmplib/transports/snmpIPv6BaseDomain.c
16976@@ -127,7 +127,6 @@ netsnmp_sockaddr_in6_2(struct sockaddr_in6 *addr,
16977 char debug_addr[INET6_ADDRSTRLEN];
16978 #if HAVE_GETADDRINFO
16979 struct addrinfo *addrs = NULL;
16980- struct addrinfo hint;
16981 int err;
16982 #elif HAVE_GETIPNODEBYNAME
16983 struct hostent *hp = NULL;
16984@@ -333,13 +332,15 @@ netsnmp_sockaddr_in6_2(struct sockaddr_in6 *addr,
16985 }
16986
16987 #if HAVE_GETADDRINFO
16988- memset(&hint, 0, sizeof hint);
16989- hint.ai_flags = 0;
16990- hint.ai_family = PF_INET6;
16991- hint.ai_socktype = SOCK_DGRAM;
16992- hint.ai_protocol = 0;
16993-
16994- err = netsnmp_getaddrinfo(peername, NULL, &hint, &addrs);
16995+ {
16996+ struct addrinfo hint = { 0 };
16997+ hint.ai_flags = 0;
16998+ hint.ai_family = PF_INET6;
16999+ hint.ai_socktype = SOCK_DGRAM;
17000+ hint.ai_protocol = 0;
17001+
17002+ err = netsnmp_getaddrinfo(peername, NULL, &hint, &addrs);
17003+ }
17004 if (err != 0) {
17005 #if HAVE_GAI_STRERROR
17006 snmp_log(LOG_ERR, "getaddrinfo(\"%s\", NULL, ...): %s\n", peername,
17007diff --git a/snmplib/transports/snmpSSHDomain.c b/snmplib/transports/snmpSSHDomain.c
17008index 72cc59e..a9ed81f 100644
17009--- a/snmplib/transports/snmpSSHDomain.c
17010+++ b/snmplib/transports/snmpSSHDomain.c
17011@@ -236,9 +236,8 @@ netsnmp_ssh_recv(netsnmp_transport *t, void *buf, int size,
17012 user_pw->pw_name);
17013 return -1;
17014 }
17015- strncpy(addr_pair->username, user_pw->pw_name,
17016+ strlcpy(addr_pair->username, user_pw->pw_name,
17017 sizeof(addr_pair->username));
17018- addr_pair->username[sizeof(addr_pair->username)-1] = '\0';
17019 }
17020 DEBUGMSGTL(("ssh", "Setting user name to %s\n",
17021 addr_pair->username));
17022@@ -309,9 +308,8 @@ netsnmp_ssh_recv(netsnmp_transport *t, void *buf, int size,
17023 user_pw->pw_name);
17024 return -1;
17025 }
17026- strncpy(addr_pair->username, user_pw->pw_name,
17027+ strlcpy(addr_pair->username, user_pw->pw_name,
17028 sizeof(addr_pair->username));
17029- addr_pair->username[sizeof(addr_pair->username)-1] = '\0';
17030 }
17031 */
17032
17033@@ -330,12 +328,12 @@ netsnmp_ssh_recv(netsnmp_transport *t, void *buf, int size,
17034 if (iamclient && 0) {
17035 /* XXX: we're on the client; we should have named the
17036 connection ourselves... pull this from session somehow? */
17037- strncpy(tmStateRef->securityName, addr_pair->username,
17038- sizeof(tmStateRef->securityName)-1);
17039+ strlcpy(tmStateRef->securityName, addr_pair->username,
17040+ sizeof(tmStateRef->securityName));
17041 } else {
17042 #ifdef SNMPSSHDOMAIN_USE_EXTERNAL_PIPE
17043- strncpy(tmStateRef->securityName, addr_pair->username,
17044- sizeof(tmStateRef->securityName)-1);
17045+ strlcpy(tmStateRef->securityName, addr_pair->username,
17046+ sizeof(tmStateRef->securityName));
17047 #else /* we're called directly by sshd and use stdin/out */
17048 /* we're on the server... */
17049 /* XXX: this doesn't copy properly and can get pointer
17050@@ -349,8 +347,8 @@ netsnmp_ssh_recv(netsnmp_transport *t, void *buf, int size,
17051
17052 /* XXX: detect and throw out overflow secname sizes rather
17053 than truncating. */
17054- strncpy(tmStateRef->securityName, getenv("USER"),
17055- sizeof(tmStateRef->securityName)-1);
17056+ strlcpy(tmStateRef->securityName, getenv("USER"),
17057+ sizeof(tmStateRef->securityName));
17058 #endif /* ! SNMPSSHDOMAIN_USE_EXTERNAL_PIPE */
17059 }
17060 tmStateRef->securityName[sizeof(tmStateRef->securityName)-1] = '\0';
17061@@ -389,9 +387,8 @@ netsnmp_ssh_send(netsnmp_transport *t, void *buf, int size,
17062
17063 if (NULL != t && NULL != addr_pair && NULL != addr_pair->channel) {
17064 if (addr_pair->username[0] == '\0') {
17065- strncpy(addr_pair->username, tmStateRef->securityName,
17066- sizeof(addr_pair->username)-1);
17067- addr_pair->username[sizeof(addr_pair->username)-1] = '\0';
17068+ strlcpy(addr_pair->username, tmStateRef->securityName,
17069+ sizeof(addr_pair->username));
17070 } else if (strcmp(addr_pair->username, tmStateRef->securityName) != 0 ||
17071 strlen(addr_pair->username) != tmStateRef->securityNameLen) {
17072 /* error! they must always match */
17073@@ -599,7 +596,6 @@ netsnmp_ssh_transport(struct sockaddr_in *addr, int local)
17074 if (t == NULL) {
17075 return NULL;
17076 }
17077- memset(t, 0, sizeof(netsnmp_transport));
17078
17079 t->domain = netsnmp_snmpSSHDomain;
17080 t->domain_length = netsnmp_snmpSSHDomain_len;
17081@@ -728,7 +724,6 @@ netsnmp_ssh_transport(struct sockaddr_in *addr, int local)
17082 #endif /* NETSNMP_NO_LISTEN_SUPPORT */
17083 } else {
17084 char *username;
17085- size_t username_len;
17086 char *keyfilepub;
17087 char *keyfilepriv;
17088
17089@@ -740,7 +735,6 @@ netsnmp_ssh_transport(struct sockaddr_in *addr, int local)
17090 snmp_log(LOG_ERR, "You must specify a ssh username to use. See the snmp.conf manual page\n");
17091 return NULL;
17092 }
17093- username_len = strlen(username);
17094
17095 /* use the requested public key file */
17096 keyfilepub = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
17097diff --git a/snmplib/transports/snmpSTDDomain.c b/snmplib/transports/snmpSTDDomain.c
17098index 21e0d79..0a1c3f9 100644
17099--- a/snmplib/transports/snmpSTDDomain.c
17100+++ b/snmplib/transports/snmpSTDDomain.c
17101@@ -154,11 +154,10 @@ netsnmp_std_transport(const char *instring, size_t instring_len,
17102 {
17103 netsnmp_transport *t;
17104
17105- t = (netsnmp_transport *) malloc(sizeof(netsnmp_transport));
17106+ t = SNMP_MALLOC_TYPEDEF(netsnmp_transport);
17107 if (t == NULL) {
17108 return NULL;
17109 }
17110- memset(t, 0, sizeof(netsnmp_transport));
17111
17112 t->domain = netsnmp_snmpSTDDomain;
17113 t->domain_length =
17114diff --git a/snmplib/transports/snmpTCPDomain.c b/snmplib/transports/snmpTCPDomain.c
17115index 426ae08..b8bdba4 100644
17116--- a/snmplib/transports/snmpTCPDomain.c
17117+++ b/snmplib/transports/snmpTCPDomain.c
17118@@ -41,6 +41,7 @@
17119 #include <net-snmp/library/snmpIPv4BaseDomain.h>
17120 #include <net-snmp/library/snmpSocketBaseDomain.h>
17121 #include <net-snmp/library/snmpTCPBaseDomain.h>
17122+#include <net-snmp/library/tools.h>
17123
17124 /*
17125 * needs to be in sync with the definitions in snmplib/snmpUDPDomain.c
17126@@ -77,7 +78,6 @@ netsnmp_tcp_accept(netsnmp_transport *t)
17127 netsnmp_udp_addr_pair *addr_pair = NULL;
17128 int newsock = -1;
17129 socklen_t farendlen = sizeof(netsnmp_udp_addr_pair);
17130- char *str = NULL;
17131
17132 addr_pair = (netsnmp_udp_addr_pair *)malloc(farendlen);
17133 if (addr_pair == NULL) {
17134@@ -106,9 +106,11 @@ netsnmp_tcp_accept(netsnmp_transport *t)
17135
17136 t->data = addr_pair;
17137 t->data_length = sizeof(netsnmp_udp_addr_pair);
17138- str = netsnmp_tcp_fmtaddr(NULL, farend, farendlen);
17139- DEBUGMSGTL(("netsnmp_tcp", "accept succeeded (from %s)\n", str));
17140- free(str);
17141+ DEBUGIF("netsnmp_tcp") {
17142+ char *str = netsnmp_tcp_fmtaddr(NULL, farend, farendlen);
17143+ DEBUGMSGTL(("netsnmp_tcp", "accept succeeded (from %s)\n", str));
17144+ free(str);
17145+ }
17146
17147 /*
17148 * Try to make the new socket blocking.
17149@@ -157,11 +159,10 @@ netsnmp_tcp_transport(struct sockaddr_in *addr, int local)
17150 return NULL;
17151 }
17152
17153- t = (netsnmp_transport *) malloc(sizeof(netsnmp_transport));
17154+ t = SNMP_MALLOC_TYPEDEF(netsnmp_transport);
17155 if (t == NULL) {
17156 return NULL;
17157 }
17158- memset(t, 0, sizeof(netsnmp_transport));
17159
17160 addr_pair = (netsnmp_udp_addr_pair *)malloc(sizeof(netsnmp_udp_addr_pair));
17161 if (addr_pair == NULL) {
17162diff --git a/snmplib/transports/snmpTCPIPv6Domain.c b/snmplib/transports/snmpTCPIPv6Domain.c
17163index 5e866eb..3c96856 100644
17164--- a/snmplib/transports/snmpTCPIPv6Domain.c
17165+++ b/snmplib/transports/snmpTCPIPv6Domain.c
17166@@ -47,6 +47,7 @@
17167 #include <net-snmp/library/snmp_transport.h>
17168 #include <net-snmp/library/snmpSocketBaseDomain.h>
17169 #include <net-snmp/library/snmpTCPBaseDomain.h>
17170+#include <net-snmp/library/tools.h>
17171
17172 #include "inet_ntop.h"
17173
17174@@ -70,7 +71,6 @@ netsnmp_tcp6_accept(netsnmp_transport *t)
17175 struct sockaddr_in6 *farend = NULL;
17176 int newsock = -1;
17177 socklen_t farendlen = sizeof(struct sockaddr_in6);
17178- char *str = NULL;
17179
17180 farend = (struct sockaddr_in6 *) malloc(sizeof(struct sockaddr_in6));
17181
17182@@ -98,9 +98,11 @@ netsnmp_tcp6_accept(netsnmp_transport *t)
17183
17184 t->data = farend;
17185 t->data_length = farendlen;
17186- str = netsnmp_tcp6_fmtaddr(NULL, farend, farendlen);
17187- DEBUGMSGTL(("netsnmp_tcp6", "accept succeeded (from %s)\n", str));
17188- free(str);
17189+ DEBUGIF("netsnmp_tcp6") {
17190+ char *str = netsnmp_tcp6_fmtaddr(NULL, farend, farendlen);
17191+ DEBUGMSGTL(("netsnmp_tcp6", "accept succeeded (from %s)\n", str));
17192+ free(str);
17193+ }
17194
17195 /*
17196 * Try to make the new socket blocking.
17197@@ -138,7 +140,6 @@ netsnmp_tcp6_transport(struct sockaddr_in6 *addr, int local)
17198 {
17199 netsnmp_transport *t = NULL;
17200 int rc = 0;
17201- char *str = NULL;
17202
17203 #ifdef NETSNMP_NO_LISTEN_SUPPORT
17204 if (local)
17205@@ -149,19 +150,18 @@ netsnmp_tcp6_transport(struct sockaddr_in6 *addr, int local)
17206 return NULL;
17207 }
17208
17209- t = (netsnmp_transport *) malloc(sizeof(netsnmp_transport));
17210+ t = SNMP_MALLOC_TYPEDEF(netsnmp_transport);
17211 if (t == NULL) {
17212 return NULL;
17213 }
17214- memset(t, 0, sizeof(netsnmp_transport));
17215-
17216- str = netsnmp_tcp6_fmtaddr(NULL, (void *)addr,
17217- sizeof(struct sockaddr_in6));
17218- DEBUGMSGTL(("netsnmp_tcp6", "open %s %s\n", local ? "local" : "remote",
17219- str));
17220- free(str);
17221
17222- memset(t, 0, sizeof(netsnmp_transport));
17223+ DEBUGIF("netsnmp_tcp6") {
17224+ char *str = netsnmp_tcp6_fmtaddr(NULL, (void *)addr,
17225+ sizeof(struct sockaddr_in6));
17226+ DEBUGMSGTL(("netsnmp_tcp6", "open %s %s\n", local ? "local" : "remote",
17227+ str));
17228+ free(str);
17229+ }
17230
17231 t->data = malloc(sizeof(netsnmp_indexed_addr_pair));
17232 if (t->data == NULL) {
17233@@ -169,7 +169,7 @@ netsnmp_tcp6_transport(struct sockaddr_in6 *addr, int local)
17234 return NULL;
17235 }
17236 t->data_length = sizeof(netsnmp_indexed_addr_pair);
17237- memcpy(t->data, addr, sizeof(netsnmp_indexed_addr_pair));
17238+ memcpy(t->data, addr, sizeof(struct sockaddr_in6));
17239
17240 t->domain = netsnmp_TCPIPv6Domain;
17241 t->domain_length = sizeof(netsnmp_TCPIPv6Domain) / sizeof(oid);
17242diff --git a/snmplib/transports/snmpTLSBaseDomain.c b/snmplib/transports/snmpTLSBaseDomain.c
17243index 12a69c6..c54d6ad 100644
17244--- a/snmplib/transports/snmpTLSBaseDomain.c
17245+++ b/snmplib/transports/snmpTLSBaseDomain.c
17246@@ -51,6 +51,7 @@ netsnmp_feature_require(cert_util)
17247 #include <net-snmp/library/snmp_transport.h>
17248 #include <net-snmp/library/snmp_secmod.h>
17249 #include <net-snmp/library/read_config.h>
17250+#include <net-snmp/library/system.h>
17251
17252 #define LOGANDDIE(msg) do { snmp_log(LOG_ERR, "%s\n", msg); return 0; } while(0)
17253
17254@@ -105,12 +106,13 @@ int verify_callback(int ok, X509_STORE_CTX *ctx) {
17255 DEBUGMSGTL(("tls_x509:verify", "verify_callback called with: ok=%d ctx=%p depth=%d err=%i:%s\n", ok, ctx, depth, err, X509_verify_cert_error_string(err)));
17256 DEBUGMSGTL(("tls_x509:verify", " accepting matching fp of self-signed certificate found in: %s\n",
17257 cert->info.filename));
17258+ SNMP_FREE(fingerprint);
17259 return 1;
17260 } else {
17261 DEBUGMSGTL(("tls_x509:verify", " no matching fp found\n"));
17262 /* log where we are and why called */
17263 snmp_log(LOG_ERR, "tls verification failure: ok=%d ctx=%p depth=%d err=%i:%s\n", ok, ctx, depth, err, X509_verify_cert_error_string(err));
17264-
17265+ SNMP_FREE(fingerprint);
17266 return 0;
17267 }
17268
17269@@ -118,6 +120,7 @@ int verify_callback(int ok, X509_STORE_CTX *ctx) {
17270 (verify_info->flags & VRFY_PARENT_WAS_OK)) {
17271 DEBUGMSGTL(("tls_x509:verify", "verify_callback called with: ok=%d ctx=%p depth=%d err=%i:%s\n", ok, ctx, depth, err, X509_verify_cert_error_string(err)));
17272 DEBUGMSGTL(("tls_x509:verify", " a parent was ok, so returning ok for this child certificate\n"));
17273+ SNMP_FREE(fingerprint);
17274 return 1; /* we'll check the hostname later at this level */
17275 }
17276 }
17277@@ -128,6 +131,7 @@ int verify_callback(int ok, X509_STORE_CTX *ctx) {
17278 DEBUGMSGTL(("tls_x509:verify", "verify_callback called with: ok=%d ctx=%p depth=%d err=%i:%s\n", ok, ctx, depth, err, X509_verify_cert_error_string(err)));
17279 DEBUGMSGTL(("tls_x509:verify", " returning the passed in value of %d\n",
17280 ok));
17281+ SNMP_FREE(fingerprint);
17282 return(ok);
17283 }
17284
17285@@ -186,6 +190,7 @@ _netsnmp_tlsbase_verify_remote_fingerprint(X509 *remote_cert,
17286 }
17287 } else {
17288 DEBUGMSGTL(("tls_x509:verify", "No fingerprint for the remote entity available to verify\n"));
17289+ free(fingerprint);
17290 return NO_FINGERPRINT_AVAILABLE;
17291 }
17292
17293@@ -262,7 +267,7 @@ netsnmp_tlsbase_verify_server_cert(SSL *ssl, _netsnmpTLSBaseData *tlsdata) {
17294 *check_name && j < sizeof(buf)-1;
17295 ++check_name, ++j ) {
17296 if (isascii(*check_name))
17297- buf[j] = tolower(*check_name);
17298+ buf[j] = tolower(0xFF & *check_name);
17299 }
17300 if (j < sizeof(buf))
17301 buf[j] = '\0';
17302@@ -914,9 +919,8 @@ int netsnmp_tlsbase_wrapup_recv(netsnmp_tmStateReference *tmStateRef,
17303 /* RFC5953 Section 5.1.2 step 2: tmSecurityName */
17304 /* XXX: detect and throw out overflow secname sizes rather
17305 than truncating. */
17306- strncpy(tmStateRef->securityName, tlsdata->securityName,
17307- sizeof(tmStateRef->securityName)-1);
17308- tmStateRef->securityName[sizeof(tmStateRef->securityName)-1] = '\0';
17309+ strlcpy(tmStateRef->securityName, tlsdata->securityName,
17310+ sizeof(tmStateRef->securityName));
17311 tmStateRef->securityNameLen = strlen(tmStateRef->securityName);
17312
17313 /* RFC5953 Section 5.1.2 step 2: tmSessionID */
17314@@ -1080,6 +1084,7 @@ const char * _x509_get_error(int x509failvalue, const char *location) {
17315 #endif
17316 case X509_V_ERR_APPLICATION_VERIFICATION:
17317 reason = "X509_V_ERR_APPLICATION_VERIFICATION";
17318+ break;
17319 default:
17320 reason = "unknown failure code";
17321 }
17322diff --git a/snmplib/transports/snmpTLSTCPDomain.c b/snmplib/transports/snmpTLSTCPDomain.c
17323index c1423f6..a92091e 100644
17324--- a/snmplib/transports/snmpTLSTCPDomain.c
17325+++ b/snmplib/transports/snmpTLSTCPDomain.c
17326@@ -152,7 +152,7 @@ netsnmp_tlstcp_recv(netsnmp_transport *t, void *buf, int size,
17327 snmp_log(LOG_ERR,
17328 "tlstcp received an invalid invocation with missing data\n");
17329 DEBUGMSGTL(("tlstcp", "recvfrom fd %d err %d (\"%s\")\n",
17330- t->sock, errno, strerror(errno)));
17331+ (t ? t->sock : -1), errno, strerror(errno)));
17332 DEBUGMSGTL(("tlstcp", " tdata = %p\n", t->data));
17333 return -1;
17334 }
17335@@ -248,8 +248,8 @@ netsnmp_tlstcp_recv(netsnmp_transport *t, void *buf, int size,
17336 */
17337
17338 /* read the packet from openssl */
17339- rc = SSL_read(tlsdata->ssl, buf, size);
17340- while (rc <= 0) {
17341+ do {
17342+ rc = SSL_read(tlsdata->ssl, buf, size);
17343 if (rc == 0) {
17344 /* XXX closed connection */
17345 DEBUGMSGTL(("tlstcp", "remote side closed connection\n"));
17346@@ -257,24 +257,22 @@ netsnmp_tlstcp_recv(netsnmp_transport *t, void *buf, int size,
17347 SNMP_FREE(tmStateRef);
17348 return -1;
17349 }
17350- rc = SSL_read(tlsdata->ssl, buf, size);
17351- }
17352+ if (rc == -1) {
17353+ int err = SSL_get_error(tlsdata->ssl, rc);
17354+ if (err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE) {
17355+ /* error detected */
17356+ _openssl_log_error(rc, tlsdata->ssl, "SSL_read");
17357+ SNMP_FREE(tmStateRef);
17358+ return rc;
17359+ }
17360+ }
17361+ /* retry read for SSL_ERROR_WANT_READ || SSL_ERROR_WANT_WRITE */
17362+ } while (rc <= 0);
17363
17364 DEBUGMSGTL(("tlstcp", "received %d decoded bytes from tls\n", rc));
17365
17366- /* Check for errors */
17367- if (rc == -1) {
17368- if (SSL_get_error(tlsdata->ssl, rc) == SSL_ERROR_WANT_READ)
17369- return -1; /* XXX: it's ok, but what's the right return? */
17370-
17371- _openssl_log_error(rc, tlsdata->ssl, "SSL_read");
17372- SNMP_FREE(tmStateRef);
17373-
17374- return rc;
17375- }
17376-
17377 /* log the packet */
17378- {
17379+ DEBUGIF("tlstcp") {
17380 char *str = netsnmp_tlstcp_fmtaddr(t, NULL, 0);
17381 DEBUGMSGTL(("tlstcp",
17382 "recvfrom fd %d got %d bytes (from %s)\n",
17383@@ -416,7 +414,7 @@ netsnmp_tlstcp_send(netsnmp_transport *t, void *buf, int size,
17384 /* If the first packet and we have no secname, then copy the
17385 important securityName data into the longer-lived session
17386 reference information. */
17387- if ((tlsdata->flags | NETSNMP_TLSBASE_IS_CLIENT) &&
17388+ if ((tlsdata->flags & NETSNMP_TLSBASE_IS_CLIENT) &&
17389 !tlsdata->securityName && tmStateRef && tmStateRef->securityNameLen > 0)
17390 tlsdata->securityName = strdup(tmStateRef->securityName);
17391
17392@@ -921,7 +919,6 @@ netsnmp_tlstcp_transport(const char *addr_string, int isserver)
17393 if (NULL == t) {
17394 return NULL;
17395 }
17396- memset(t, 0, sizeof(netsnmp_transport));
17397
17398 /* allocate our TLS specific data */
17399 if (NULL == (tlsdata = netsnmp_tlsbase_allocate_tlsdata(t, isserver)))
17400@@ -936,12 +933,13 @@ netsnmp_tlstcp_transport(const char *addr_string, int isserver)
17401 if (!isserver && tlsdata && addr_string) {
17402 /* search for a : */
17403 if (NULL != (cp = strrchr(addr_string, ':'))) {
17404- strncpy(buf, addr_string, sizeof(buf)-1);
17405+ sprintf(buf, "%.*s",
17406+ (int) SNMP_MIN(cp - addr_string, sizeof(buf) - 1),
17407+ addr_string);
17408 } else {
17409 /* else the entire spec is a host name only */
17410- strncpy(buf, addr_string, sizeof(buf)-1);
17411+ strlcpy(buf, addr_string, sizeof(buf));
17412 }
17413- buf[sizeof(buf)-1] = '\0';
17414 tlsdata->their_hostname = strdup(buf);
17415 }
17416
17417@@ -989,7 +987,7 @@ netsnmp_tlstcp_create_tstring(const char *str, int local,
17418 for(cp = str; *cp != '\0'; cp++) {
17419 /* if ALL numbers, it must be just a port */
17420 /* if it contains anything else, assume a host or ip address */
17421- if (!isdigit(*cp)) {
17422+ if (!isdigit(0xFF & *cp)) {
17423 isport = 0;
17424 break;
17425 }
17426diff --git a/snmplib/transports/snmpUDPBaseDomain.c b/snmplib/transports/snmpUDPBaseDomain.c
17427index eb5f1a1..fc5c1cc 100644
17428--- a/snmplib/transports/snmpUDPBaseDomain.c
17429+++ b/snmplib/transports/snmpUDPBaseDomain.c
17430@@ -89,6 +89,160 @@ _netsnmp_udp_sockopt_set(int fd, int local)
17431 netsnmp_sock_buffer_set(fd, SO_RCVBUF, local, 0);
17432 }
17433
17434+#if (defined(linux) && defined(IP_PKTINFO)) \
17435+ || defined(IP_RECVDSTADDR) && HAVE_STRUCT_MSGHDR_MSG_CONTROL \
17436+ && HAVE_STRUCT_MSGHDR_MSG_FLAGS
17437+#if defined(linux) && defined(IP_PKTINFO)
17438+#elif defined(IP_RECVDSTADDR)
17439+# ifndef IP_SENDSRCADDR
17440+# define IP_SENDSRCADDR IP_RECVDSTADDR /* DragonFly BSD */
17441+# endif
17442+#endif
17443+
17444+#define netsnmp_udpbase_recvfrom_sendto_defined
17445+
17446+enum {
17447+#if defined(linux) && defined(IP_PKTINFO)
17448+ cmsg_data_size = sizeof(struct in_pktinfo)
17449+#elif defined(IP_RECVDSTADDR)
17450+ cmsg_data_size = sizeof(struct in_addr)
17451+#endif
17452+};
17453+
17454+int
17455+netsnmp_udpbase_recvfrom(int s, void *buf, int len, struct sockaddr *from,
17456+ socklen_t *fromlen, struct sockaddr *dstip,
17457+ socklen_t *dstlen, int *if_index)
17458+{
17459+ int r;
17460+ struct iovec iov;
17461+ char cmsg[CMSG_SPACE(cmsg_data_size)];
17462+ struct cmsghdr *cm;
17463+ struct msghdr msg;
17464+
17465+ iov.iov_base = buf;
17466+ iov.iov_len = len;
17467+
17468+ memset(&msg, 0, sizeof msg);
17469+ msg.msg_name = from;
17470+ msg.msg_namelen = *fromlen;
17471+ msg.msg_iov = &iov;
17472+ msg.msg_iovlen = 1;
17473+ msg.msg_control = &cmsg;
17474+ msg.msg_controllen = sizeof(cmsg);
17475+
17476+ r = recvmsg(s, &msg, NETSNMP_DONTWAIT);
17477+
17478+ if (r == -1) {
17479+ return -1;
17480+ }
17481+
17482+ DEBUGMSGTL(("udpbase:recv", "got source addr: %s\n",
17483+ inet_ntoa(((struct sockaddr_in *)from)->sin_addr)));
17484+
17485+ {
17486+ /* Get the local port number for use in diagnostic messages */
17487+ int r2 = getsockname(s, dstip, dstlen);
17488+ netsnmp_assert(r2 == 0);
17489+ }
17490+
17491+ for (cm = CMSG_FIRSTHDR(&msg); cm != NULL; cm = CMSG_NXTHDR(&msg, cm)) {
17492+#if defined(linux) && defined(IP_PKTINFO)
17493+ if (cm->cmsg_level == SOL_IP && cm->cmsg_type == IP_PKTINFO) {
17494+ struct in_pktinfo* src = (struct in_pktinfo *)CMSG_DATA(cm);
17495+ netsnmp_assert(dstip->sa_family == AF_INET);
17496+ ((struct sockaddr_in*)dstip)->sin_addr = src->ipi_addr;
17497+ *if_index = src->ipi_ifindex;
17498+ DEBUGMSGTL(("udpbase:recv",
17499+ "got destination (local) addr %s, iface %d\n",
17500+ inet_ntoa(((struct sockaddr_in*)dstip)->sin_addr),
17501+ *if_index));
17502+ }
17503+#elif defined(IP_RECVDSTADDR)
17504+ if (cm->cmsg_level == IPPROTO_IP && cm->cmsg_type == IP_RECVDSTADDR) {
17505+ struct in_addr* src = (struct in_addr *)CMSG_DATA(cm);
17506+ ((struct sockaddr_in*)dstip)->sin_addr = *src;
17507+ DEBUGMSGTL(("netsnmp_udp", "got destination (local) addr %s\n",
17508+ inet_ntoa(((struct sockaddr_in*)dstip)->sin_addr)));
17509+ }
17510+#endif
17511+ }
17512+ return r;
17513+}
17514+
17515+int netsnmp_udpbase_sendto(int fd, struct in_addr *srcip, int if_index,
17516+ struct sockaddr *remote, void *data, int len)
17517+{
17518+ struct iovec iov;
17519+ struct msghdr m = { 0 };
17520+ char cmsg[CMSG_SPACE(cmsg_data_size)];
17521+
17522+ iov.iov_base = data;
17523+ iov.iov_len = len;
17524+
17525+ m.msg_name = remote;
17526+ m.msg_namelen = sizeof(struct sockaddr_in);
17527+ m.msg_iov = &iov;
17528+ m.msg_iovlen = 1;
17529+ m.msg_flags = 0;
17530+
17531+ if (srcip && srcip->s_addr != INADDR_ANY) {
17532+ struct cmsghdr *cm;
17533+
17534+ DEBUGMSGTL(("udpbase:sendto", "sending from %s\n", inet_ntoa(*srcip)));
17535+
17536+ memset(cmsg, 0, sizeof(cmsg));
17537+
17538+ m.msg_control = &cmsg;
17539+ m.msg_controllen = sizeof(cmsg);
17540+
17541+ cm = CMSG_FIRSTHDR(&m);
17542+ cm->cmsg_len = CMSG_LEN(cmsg_data_size);
17543+
17544+#if defined(linux) && defined(IP_PKTINFO)
17545+ cm->cmsg_level = SOL_IP;
17546+ cm->cmsg_type = IP_PKTINFO;
17547+
17548+ {
17549+ struct in_pktinfo ipi = { 0 };
17550+ ipi.ipi_ifindex = 0;
17551+ ipi.ipi_spec_dst.s_addr = srcip->s_addr;
17552+ memcpy(CMSG_DATA(cm), &ipi, sizeof(ipi));
17553+ }
17554+
17555+ {
17556+ errno = 0;
17557+ const int rc = sendmsg(fd, &m, NETSNMP_NOSIGNAL|NETSNMP_DONTWAIT);
17558+
17559+ if (rc >= 0 || errno != EINVAL)
17560+ return rc;
17561+ }
17562+
17563+ /*
17564+ * The error might be caused by broadcast srcip (i.e. we're responding
17565+ * to a broadcast request) - sendmsg does not like it. Try to resend it
17566+ * using the interface on which it was received
17567+ */
17568+
17569+ DEBUGMSGTL(("udpbase:sendto", "re-sending on iface %d\n", if_index));
17570+
17571+ {
17572+ struct in_pktinfo ipi = { 0 };
17573+ ipi.ipi_ifindex = if_index;
17574+ ipi.ipi_spec_dst.s_addr = INADDR_ANY;
17575+ memcpy(CMSG_DATA(cm), &ipi, sizeof(ipi));
17576+ }
17577+#elif defined(IP_SENDSRCADDR)
17578+ cm->cmsg_level = IPPROTO_IP;
17579+ cm->cmsg_type = IP_SENDSRCADDR;
17580+ memcpy((struct in_addr *)CMSG_DATA(cm), srcip, sizeof(struct in_addr));
17581+#endif
17582+ }
17583+
17584+ return sendmsg(fd, &m, NETSNMP_NOSIGNAL|NETSNMP_DONTWAIT);
17585+}
17586+#endif /* (linux && IP_PKTINFO) || IP_RECVDSTADDR */
17587+
17588 /*
17589 * You can write something into opaque that will subsequently get passed back
17590 * to your send function if you like. For instance, you might want to
17591@@ -116,25 +270,28 @@ netsnmp_udpbase_recv(netsnmp_transport *t, void *buf, int size,
17592 }
17593
17594 while (rc < 0) {
17595-#if defined(linux) && defined(IP_PKTINFO)
17596+#ifdef netsnmp_udpbase_recvfrom_sendto_defined
17597 socklen_t local_addr_len = sizeof(addr_pair->local_addr);
17598 rc = netsnmp_udp_recvfrom(t->sock, buf, size, from, &fromlen,
17599 (struct sockaddr*)&(addr_pair->local_addr),
17600 &local_addr_len, &(addr_pair->if_index));
17601 #else
17602 rc = recvfrom(t->sock, buf, size, NETSNMP_DONTWAIT, from, &fromlen);
17603-#endif /* linux && IP_PKTINFO */
17604+#endif /* netsnmp_udpbase_recvfrom_sendto_defined */
17605 if (rc < 0 && errno != EINTR) {
17606 break;
17607 }
17608 }
17609
17610 if (rc >= 0) {
17611- char *str = netsnmp_udp_fmtaddr(NULL, addr_pair, sizeof(netsnmp_indexed_addr_pair));
17612- DEBUGMSGTL(("netsnmp_udp",
17613- "recvfrom fd %d got %d bytes (from %s)\n",
17614- t->sock, rc, str));
17615- free(str);
17616+ DEBUGIF("netsnmp_udp") {
17617+ char *str = netsnmp_udp_fmtaddr(
17618+ NULL, addr_pair, sizeof(netsnmp_indexed_addr_pair));
17619+ DEBUGMSGTL(("netsnmp_udp",
17620+ "recvfrom fd %d got %d bytes (from %s)\n",
17621+ t->sock, rc, str));
17622+ free(str);
17623+ }
17624 } else {
17625 DEBUGMSGTL(("netsnmp_udp", "recvfrom fd %d err %d (\"%s\")\n",
17626 t->sock, errno, strerror(errno)));
17627@@ -167,19 +324,21 @@ netsnmp_udpbase_send(netsnmp_transport *t, void *buf, int size,
17628 to = &addr_pair->remote_addr.sa;
17629
17630 if (to != NULL && t != NULL && t->sock >= 0) {
17631- char *str = netsnmp_udp_fmtaddr(NULL, (void *) addr_pair,
17632- sizeof(netsnmp_indexed_addr_pair));
17633- DEBUGMSGTL(("netsnmp_udp", "send %d bytes from %p to %s on fd %d\n",
17634- size, buf, str, t->sock));
17635- free(str);
17636+ DEBUGIF("netsnmp_udp") {
17637+ char *str = netsnmp_udp_fmtaddr(NULL, (void *) addr_pair,
17638+ sizeof(netsnmp_indexed_addr_pair));
17639+ DEBUGMSGTL(("netsnmp_udp", "send %d bytes from %p to %s on fd %d\n",
17640+ size, buf, str, t->sock));
17641+ free(str);
17642+ }
17643 while (rc < 0) {
17644-#if defined(linux) && defined(IP_PKTINFO)
17645+#ifdef netsnmp_udpbase_recvfrom_sendto_defined
17646 rc = netsnmp_udp_sendto(t->sock,
17647 addr_pair ? &(addr_pair->local_addr.sin.sin_addr) : NULL,
17648 addr_pair ? addr_pair->if_index : 0, to, buf, size);
17649 #else
17650 rc = sendto(t->sock, buf, size, 0, to, sizeof(struct sockaddr));
17651-#endif /* linux && IP_PKTINFO */
17652+#endif /* netsnmp_udpbase_recvfrom_sendto_defined */
17653 if (rc < 0 && errno != EINTR) {
17654 DEBUGMSGTL(("netsnmp_udp", "sendto error, rc %d (errno %d)\n",
17655 rc, errno));
17656@@ -189,153 +348,3 @@ netsnmp_udpbase_send(netsnmp_transport *t, void *buf, int size,
17657 }
17658 return rc;
17659 }
17660-
17661-#if (defined(linux) && defined(IP_PKTINFO)) \
17662- || defined(IP_RECVDSTADDR) && HAVE_STRUCT_MSGHDR_MSG_CONTROL \
17663- && HAVE_STRUCT_MSGHDR_MSG_FLAGS
17664-#if defined(linux) && defined(IP_PKTINFO)
17665-# define netsnmp_dstaddr(x) (&(((struct in_pktinfo *)(CMSG_DATA(x)))->ipi_addr))
17666-#elif defined(IP_RECVDSTADDR)
17667-# define netsnmp_dstaddr(x) (&(struct cmsghr *)(CMSG_DATA(x)))
17668-# ifndef IP_SENDSRCADDR
17669-# define IP_SENDSRCADDR IP_RECVDSTADDR /* DragonFly BSD */
17670-# endif
17671-#endif
17672-
17673-int
17674-netsnmp_udpbase_recvfrom(int s, void *buf, int len, struct sockaddr *from,
17675- socklen_t *fromlen, struct sockaddr *dstip,
17676- socklen_t *dstlen, int *if_index)
17677-{
17678- int r, r2;
17679- struct iovec iov[1];
17680-#if defined(linux) && defined(IP_PKTINFO)
17681- char cmsg[CMSG_SPACE(sizeof(struct in_pktinfo))];
17682-#elif defined(IP_RECVDSTADDR)
17683- char cmsg[CMSG_SPACE(sizeof(struct in_addr))];
17684-#endif
17685- struct cmsghdr *cmsgptr;
17686- struct msghdr msg;
17687-
17688- iov[0].iov_base = buf;
17689- iov[0].iov_len = len;
17690-
17691- memset(&msg, 0, sizeof msg);
17692- msg.msg_name = from;
17693- msg.msg_namelen = *fromlen;
17694- msg.msg_iov = iov;
17695- msg.msg_iovlen = 1;
17696- msg.msg_control = &cmsg;
17697- msg.msg_controllen = sizeof(cmsg);
17698-
17699- r = recvmsg(s, &msg, NETSNMP_DONTWAIT);
17700-
17701- if (r == -1) {
17702- return -1;
17703- }
17704-
17705- r2 = getsockname(s, dstip, dstlen);
17706- netsnmp_assert(r2 == 0);
17707-
17708- DEBUGMSGTL(("udpbase:recv", "got source addr: %s\n",
17709- inet_ntoa(((struct sockaddr_in *)from)->sin_addr)));
17710-#if defined(linux) && defined(IP_PKTINFO)
17711- for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL; cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) {
17712- if (cmsgptr->cmsg_level != SOL_IP || cmsgptr->cmsg_type != IP_PKTINFO)
17713- continue;
17714-
17715- netsnmp_assert(dstip->sa_family == AF_INET);
17716- ((struct sockaddr_in*)dstip)->sin_addr = *netsnmp_dstaddr(cmsgptr);
17717- *if_index = (((struct in_pktinfo *)(CMSG_DATA(cmsgptr)))->ipi_ifindex);
17718- DEBUGMSGTL(("udpbase:recv",
17719- "got destination (local) addr %s, iface %d\n",
17720- inet_ntoa(((struct sockaddr_in*)dstip)->sin_addr),
17721- *if_index));
17722- }
17723-#elif defined(IP_RECVDSTADDR)
17724- for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL; cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) {
17725- if (cmsgptr->cmsg_level == IPPROTO_IP && cmsgptr->cmsg_type == IP_RECVDSTADDR) {
17726- memcpy((void *) dstip, CMSG_DATA(cmsgptr), sizeof(struct in_addr));
17727- DEBUGMSGTL(("netsnmp_udp", "got destination (local) addr %s\n",
17728- inet_ntoa(((struct sockaddr_in*)dstip)->sin_addr)));
17729- }
17730- }
17731-#endif
17732- return r;
17733-}
17734-
17735-#if defined(linux) && defined(IP_PKTINFO)
17736-int netsnmp_udpbase_sendto(int fd, struct in_addr *srcip, int if_index,
17737- struct sockaddr *remote, void *data, int len)
17738-{
17739- struct iovec iov;
17740- struct {
17741- struct cmsghdr cm;
17742- struct in_pktinfo ipi;
17743- } cmsg;
17744- struct msghdr m;
17745- int ret;
17746-
17747- iov.iov_base = data;
17748- iov.iov_len = len;
17749- memset(&cmsg, 0, sizeof(cmsg));
17750- cmsg.cm.cmsg_len = sizeof(struct cmsghdr) + sizeof(struct in_pktinfo);
17751- cmsg.cm.cmsg_level = SOL_IP;
17752- cmsg.cm.cmsg_type = IP_PKTINFO;
17753- cmsg.ipi.ipi_ifindex = 0;
17754- cmsg.ipi.ipi_spec_dst.s_addr = (srcip ? srcip->s_addr : INADDR_ANY);
17755-
17756- m.msg_name = remote;
17757- m.msg_namelen = sizeof(struct sockaddr_in);
17758- m.msg_iov = &iov;
17759- m.msg_iovlen = 1;
17760- m.msg_control = &cmsg;
17761- m.msg_controllen = sizeof(cmsg);
17762- m.msg_flags = 0;
17763-
17764- DEBUGMSGTL(("udpbase:sendto", "sending from %s iface %d\n",
17765- (srcip ? inet_ntoa(*srcip) : "NULL"), if_index));
17766- errno = 0;
17767- ret = sendmsg(fd, &m, NETSNMP_NOSIGNAL|NETSNMP_DONTWAIT);
17768- if (ret < 0 && errno == EINVAL && srcip) {
17769- /* The error might be caused by broadcast srcip (i.e. we're responding
17770- * to broadcast request) - sendmsg does not like it. Try to resend it
17771- * with global address and using the interface on whicg it was
17772- * received */
17773- cmsg.ipi.ipi_ifindex = if_index;
17774- cmsg.ipi.ipi_spec_dst.s_addr = INADDR_ANY;
17775- DEBUGMSGTL(("udpbase:sendto", "re-sending the message\n"));
17776- ret = sendmsg(fd, &m, NETSNMP_NOSIGNAL|NETSNMP_DONTWAIT);
17777- }
17778- return ret;
17779-}
17780-#elif defined(IP_SENDSRCADDR)
17781-int netsnmp_udpbase_sendto(int fd, struct in_addr *srcip, int if_index,
17782- struct sockaddr *remote, void *data, int len)
17783-{
17784- struct iovec iov = { data, len };
17785- struct cmsghdr *cm;
17786- struct msghdr m;
17787- char cmbuf[CMSG_SPACE(sizeof(struct in_addr))];
17788-
17789- memset(&m, 0, sizeof(struct msghdr));
17790- m.msg_name = remote;
17791- m.msg_namelen = sizeof(struct sockaddr_in);
17792- m.msg_iov = &iov;
17793- m.msg_iovlen = 1;
17794- m.msg_control = cmbuf;
17795- m.msg_controllen = sizeof(cmbuf);
17796- m.msg_flags = 0;
17797-
17798- cm = CMSG_FIRSTHDR(&m);
17799- cm->cmsg_len = CMSG_LEN(sizeof(struct in_addr));
17800- cm->cmsg_level = IPPROTO_IP;
17801- cm->cmsg_type = IP_SENDSRCADDR;
17802-
17803- memcpy((struct in_addr *)CMSG_DATA(cm), srcip, sizeof(struct in_addr));
17804-
17805- return sendmsg(fd, &m, NETSNMP_NOSIGNAL|NETSNMP_DONTWAIT);
17806-}
17807-#endif
17808-#endif /* (linux && IP_PKTINFO) || IP_RECVDSTADDR */
17809-
17810diff --git a/snmplib/transports/snmpUDPIPv4BaseDomain.c b/snmplib/transports/snmpUDPIPv4BaseDomain.c
17811index 5a4f5b0..5f2f2da 100644
17812--- a/snmplib/transports/snmpUDPIPv4BaseDomain.c
17813+++ b/snmplib/transports/snmpUDPIPv4BaseDomain.c
17814@@ -64,7 +64,6 @@ netsnmp_udpipv4base_transport(struct sockaddr_in *addr, int local)
17815 {
17816 netsnmp_transport *t = NULL;
17817 int rc = 0, rc2;
17818- char *str = NULL;
17819 char *client_socket = NULL;
17820 netsnmp_indexed_addr_pair addr_pair;
17821 socklen_t local_addr_len;
17822@@ -84,11 +83,13 @@ netsnmp_udpipv4base_transport(struct sockaddr_in *addr, int local)
17823 t = SNMP_MALLOC_TYPEDEF(netsnmp_transport);
17824 netsnmp_assert_or_return(t != NULL, NULL);
17825
17826- str = netsnmp_udp_fmtaddr(NULL, (void *)&addr_pair,
17827- sizeof(netsnmp_indexed_addr_pair));
17828- DEBUGMSGTL(("netsnmp_udpbase", "open %s %s\n", local ? "local" : "remote",
17829- str));
17830- free(str);
17831+ DEBUGIF("netsnmp_udpbase") {
17832+ char *str = netsnmp_udp_fmtaddr(NULL, (void *)&addr_pair,
17833+ sizeof(netsnmp_indexed_addr_pair));
17834+ DEBUGMSGTL(("netsnmp_udpbase", "open %s %s\n",
17835+ local ? "local" : "remote", str));
17836+ free(str);
17837+ }
17838
17839 t->sock = socket(PF_INET, SOCK_DGRAM, 0);
17840 DEBUGMSGTL(("UDPBase", "openned socket %d as local=%d\n", t->sock, local));
17841@@ -128,6 +129,17 @@ netsnmp_udpipv4base_transport(struct sockaddr_in *addr, int local)
17842 }
17843 DEBUGMSGTL(("netsnmp_udpbase", "set IP_PKTINFO\n"));
17844 }
17845+#elif defined(IP_RECVDSTADDR)
17846+ {
17847+ int sockopt = 1;
17848+ if (setsockopt(t->sock, IPPROTO_IP, IP_RECVDSTADDR, &sockopt, sizeof sockopt) == -1) {
17849+ DEBUGMSGTL(("netsnmp_udp", "couldn't set IP_RECVDSTADDR: %s\n",
17850+ strerror(errno)));
17851+ netsnmp_transport_free(t);
17852+ return NULL;
17853+ }
17854+ DEBUGMSGTL(("netsnmp_udp", "set IP_RECVDSTADDR\n"));
17855+ }
17856 #endif
17857 rc = bind(t->sock, (struct sockaddr *) addr,
17858 sizeof(struct sockaddr));
17859@@ -169,10 +181,12 @@ netsnmp_udpipv4base_transport(struct sockaddr_in *addr, int local)
17860 netsnmp_assert(rc2 == 0);
17861 }
17862
17863- str = netsnmp_udp_fmtaddr(NULL, (void *)&addr_pair,
17864- sizeof(netsnmp_indexed_addr_pair));
17865- DEBUGMSGTL(("netsnmp_udpbase", "client open %s\n", str));
17866- free(str);
17867+ DEBUGIF("netsnmp_udpbase") {
17868+ char *str = netsnmp_udp_fmtaddr(NULL, (void *)&addr_pair,
17869+ sizeof(netsnmp_indexed_addr_pair));
17870+ DEBUGMSGTL(("netsnmp_udpbase", "client open %s\n", str));
17871+ free(str);
17872+ }
17873
17874 /*
17875 * Save the (remote) address in the
17876diff --git a/snmplib/transports/snmpUDPIPv6Domain.c b/snmplib/transports/snmpUDPIPv6Domain.c
17877index 90607b5..b3eaae4 100644
17878--- a/snmplib/transports/snmpUDPIPv6Domain.c
17879+++ b/snmplib/transports/snmpUDPIPv6Domain.c
17880@@ -65,6 +65,7 @@ static const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
17881
17882 #include <net-snmp/library/snmp_transport.h>
17883 #include <net-snmp/library/snmpSocketBaseDomain.h>
17884+#include <net-snmp/library/tools.h>
17885
17886 #include "inet_ntop.h"
17887 #include "inet_pton.h"
17888@@ -123,11 +124,13 @@ netsnmp_udp6_recv(netsnmp_transport *t, void *buf, int size,
17889 }
17890
17891 if (rc >= 0) {
17892- char *str = netsnmp_udp6_fmtaddr(NULL, from, fromlen);
17893- DEBUGMSGTL(("netsnmp_udp6",
17894- "recvfrom fd %d got %d bytes (from %s)\n", t->sock,
17895- rc, str));
17896- free(str);
17897+ DEBUGIF("netsnmp_udp6") {
17898+ char *str = netsnmp_udp6_fmtaddr(NULL, from, fromlen);
17899+ DEBUGMSGTL(("netsnmp_udp6",
17900+ "recvfrom fd %d got %d bytes (from %s)\n", t->sock,
17901+ rc, str));
17902+ free(str);
17903+ }
17904 } else {
17905 DEBUGMSGTL(("netsnmp_udp6", "recvfrom fd %d err %d (\"%s\")\n",
17906 t->sock, errno, strerror(errno)));
17907@@ -157,11 +160,14 @@ netsnmp_udp6_send(netsnmp_transport *t, void *buf, int size,
17908 }
17909
17910 if (to != NULL && t != NULL && t->sock >= 0) {
17911- char *str = netsnmp_udp6_fmtaddr(NULL, (void *)to,
17912- sizeof(struct sockaddr_in6));
17913- DEBUGMSGTL(("netsnmp_udp6", "send %d bytes from %p to %s on fd %d\n",
17914- size, buf, str, t->sock));
17915- free(str);
17916+ DEBUGIF("netsnmp_udp6") {
17917+ char *str = netsnmp_udp6_fmtaddr(NULL, (void *)to,
17918+ sizeof(struct sockaddr_in6));
17919+ DEBUGMSGTL(("netsnmp_udp6",
17920+ "send %d bytes from %p to %s on fd %d\n",
17921+ size, buf, str, t->sock));
17922+ free(str);
17923+ }
17924 while (rc < 0) {
17925 rc = sendto(t->sock, buf, size, 0, to,sizeof(struct sockaddr_in6));
17926 if (rc < 0 && errno != EINTR) {
17927@@ -184,7 +190,6 @@ netsnmp_udp6_transport(struct sockaddr_in6 *addr, int local)
17928 {
17929 netsnmp_transport *t = NULL;
17930 int rc = 0;
17931- char *str = NULL;
17932
17933 #ifdef NETSNMP_NO_LISTEN_SUPPORT
17934 if (local)
17935@@ -195,18 +200,18 @@ netsnmp_udp6_transport(struct sockaddr_in6 *addr, int local)
17936 return NULL;
17937 }
17938
17939- t = (netsnmp_transport *) malloc(sizeof(netsnmp_transport));
17940+ t = SNMP_MALLOC_TYPEDEF(netsnmp_transport);
17941 if (t == NULL) {
17942 return NULL;
17943 }
17944
17945- str = netsnmp_udp6_fmtaddr(NULL, (void *) addr,
17946- sizeof(struct sockaddr_in6));
17947- DEBUGMSGTL(("netsnmp_udp6", "open %s %s\n", local ? "local" : "remote",
17948- str));
17949- free(str);
17950-
17951- memset(t, 0, sizeof(netsnmp_transport));
17952+ DEBUGIF("netsnmp_udp6") {
17953+ char *str = netsnmp_udp6_fmtaddr(NULL, (void *) addr,
17954+ sizeof(struct sockaddr_in6));
17955+ DEBUGMSGTL(("netsnmp_udp6", "open %s %s\n", local ? "local" : "remote",
17956+ str));
17957+ free(str);
17958+ }
17959
17960 t->domain = netsnmp_UDPIPv6Domain;
17961 t->domain_length =
17962diff --git a/snmplib/transports/snmpUnixDomain.c b/snmplib/transports/snmpUnixDomain.c
17963index fbdeb03..674dc2b 100644
17964--- a/snmplib/transports/snmpUnixDomain.c
17965+++ b/snmplib/transports/snmpUnixDomain.c
17966@@ -35,6 +35,7 @@
17967 #include <net-snmp/library/snmp_transport.h>
17968 #include <net-snmp/library/snmpSocketBaseDomain.h>
17969 #include <net-snmp/library/system.h> /* mkdirhier */
17970+#include <net-snmp/library/tools.h>
17971
17972 netsnmp_feature_child_of(transport_unix_socket_all, transport_all)
17973 netsnmp_feature_child_of(unix_socket_paths, transport_unix_socket_all)
17974@@ -294,7 +295,6 @@ netsnmp_unix_transport(struct sockaddr_un *addr, int local)
17975 netsnmp_transport *t = NULL;
17976 sockaddr_un_pair *sup = NULL;
17977 int rc = 0;
17978- char *string = NULL;
17979
17980 #ifdef NETSNMP_NO_LISTEN_SUPPORT
17981 /* SPECIAL CIRCUMSTANCE: We still want AgentX to be able to operate,
17982@@ -307,18 +307,18 @@ netsnmp_unix_transport(struct sockaddr_un *addr, int local)
17983 return NULL;
17984 }
17985
17986- t = (netsnmp_transport *) malloc(sizeof(netsnmp_transport));
17987+ t = SNMP_MALLOC_TYPEDEF(netsnmp_transport);
17988 if (t == NULL) {
17989 return NULL;
17990 }
17991
17992- string = netsnmp_unix_fmtaddr(NULL, (void *)addr,
17993- sizeof(struct sockaddr_un));
17994- DEBUGMSGTL(("netsnmp_unix", "open %s %s\n", local ? "local" : "remote",
17995- string));
17996- free(string);
17997-
17998- memset(t, 0, sizeof(netsnmp_transport));
17999+ DEBUGIF("netsnmp_unix") {
18000+ char *str = netsnmp_unix_fmtaddr(NULL, (void *)addr,
18001+ sizeof(struct sockaddr_un));
18002+ DEBUGMSGTL(("netsnmp_unix", "open %s %s\n", local ? "local" : "remote",
18003+ str));
18004+ free(str);
18005+ }
18006
18007 t->domain = netsnmp_UnixDomain;
18008 t->domain_length =
18009@@ -463,7 +463,7 @@ netsnmp_unix_create_tstring(const char *string, int local,
18010 (strlen(string) < sizeof(addr.sun_path))) {
18011 addr.sun_family = AF_UNIX;
18012 memset(addr.sun_path, 0, sizeof(addr.sun_path));
18013- strncpy(addr.sun_path, string, sizeof(addr.sun_path) - 1);
18014+ strlcpy(addr.sun_path, string, sizeof(addr.sun_path));
18015 return netsnmp_unix_transport(&addr, local);
18016 } else {
18017 if (string != NULL && *string != '\0') {
18018@@ -483,7 +483,7 @@ netsnmp_unix_create_ostring(const u_char * o, size_t o_len, int local)
18019 if (o_len > 0 && o_len < (sizeof(addr.sun_path) - 1)) {
18020 addr.sun_family = AF_UNIX;
18021 memset(addr.sun_path, 0, sizeof(addr.sun_path));
18022- strncpy(addr.sun_path, (const char *)o, o_len);
18023+ strlcpy(addr.sun_path, (const char *)o, sizeof(addr.sun_path));
18024 return netsnmp_unix_transport(&addr, local);
18025 } else {
18026 if (o_len > 0) {
18027diff --git a/testing/RUNTESTS b/testing/RUNTESTS
18028index 8976c31..0b093da 100755
18029--- a/testing/RUNTESTS
18030+++ b/testing/RUNTESTS
18031@@ -10,13 +10,13 @@ if [ "x$MIBDIRS" = "x" ]; then
18032 export MIBDIRS
18033 fi
18034
18035-# Make sure MinGW / MSYS users have the kill.exe program to stop the agent and
18036+# Make sure MinGW / MSYS users have the pskill.exe program to stop the agent and
18037 # snmptrapd
18038-if [ "x$OSTYPE" = "xmsys" -a "x`type -p kill.exe`" = "x" ]; then
18039- echo Could not find kill.exe. Aborting tests.
18040- echo kill.exe can be installed as follows:
18041- echo - Download pskill.exe from http://technet.microsoft.com/en-us/sysinternals/default.aspx.
18042- echo - Copy pskill.exe to C:\Windows\kill.exe.
18043+if [ "x$OSTYPE" = "xmsys" -a "x`type -p pskill.exe`" = "x" ]; then
18044+ echo "Could not find pskill.exe. Aborting tests."
18045+ echo "pskill.exe can be installed as follows:"
18046+ echo "- Download pskill.exe from http://technet.microsoft.com/en-us/sysinternals/default.aspx."
18047+ echo "- Copy pskill.exe to C:\\MinGW\\msys\\1.0\\bin."
18048 exit 1
18049 fi
18050
18051diff --git a/testing/fulltests/default/T035snmpv3trapdusermgmt_simple b/testing/fulltests/default/T035snmpv3trapdusermgmt_simple
18052index e42690f..e1b06c1 100644
18053--- a/testing/fulltests/default/T035snmpv3trapdusermgmt_simple
18054+++ b/testing/fulltests/default/T035snmpv3trapdusermgmt_simple
18055@@ -7,7 +7,8 @@ HEADER SNMPv3 snmptrapd USM user management with snmpusm
18056 SKIPIFNOT USING_AGENTX_MASTER_MODULE
18057 SKIPIFNOT USING_AGENTX_SUBAGENT_MODULE
18058 SKIPIFNOT USING_SNMPV3_USMUSER_MODULE
18059-SKIPIF NETSNMP_SNMPTRAPD_DISABLE_AGENTX
18060+SKIPIF NETSNMP_SNMPTRAPD_DISABLE_AGENTX
18061+SKIPIF NETSNMP_DISABLE_SET_SUPPORT
18062 SKIPIFNOT NETSNMP_CAN_DO_CRYPTO
18063 SKIPIFNOT NETSNMP_ENABLE_SCAPI_AUTHPRIV
18064
18065diff --git a/testing/fulltests/default/T065agentextend_simple b/testing/fulltests/default/T065agentextend_simple
18066index c7cf6aa..07dcae3 100644
18067--- a/testing/fulltests/default/T065agentextend_simple
18068+++ b/testing/fulltests/default/T065agentextend_simple
18069@@ -4,6 +4,7 @@
18070
18071 HEADER "extending agent functionality with extend"
18072
18073+[ "x$OSTYPE" = xmsys -a "x$MSYS_SH" = x ] && SKIP "\$MSYS_SH has not been set"
18074 SKIPIF NETSNMP_DISABLE_SNMPV2C
18075 SKIPIFNOT USING_AGENT_EXTEND_MODULE
18076 SKIPIFNOT USING_UTILITIES_EXECUTE_MODULE
18077diff --git a/testing/fulltests/default/T066pass_simple b/testing/fulltests/default/T066pass_simple
18078new file mode 100644
18079index 0000000..6396ed1
18080--- /dev/null
18081+++ b/testing/fulltests/default/T066pass_simple
18082@@ -0,0 +1,53 @@
18083+#!/bin/sh
18084+
18085+. ../support/simple_eval_tools.sh
18086+
18087+HEADER "extending agent functionality with pass"
18088+
18089+SKIPIF NETSNMP_DISABLE_SNMPV2C
18090+SKIPIFNOT USING_UCD_SNMP_PASS_MODULE
18091+SKIPIFNOT USING_UTILITIES_EXECUTE_MODULE
18092+
18093+# Don't run this test on MinGW - local/passtest is a shell script and
18094+# hence passing it to the MSVCRT popen() doesn't work.
18095+[ "x$OSTYPE" = "xmsys" ] && SKIP "MinGW"
18096+
18097+# make sure snmpget and snmpwalk can be executed
18098+SNMPGET="${builddir}/apps/snmpget"
18099+[ -x "$SNMPGET" ] || SKIP
18100+SNMPWALK="${builddir}/apps/snmpwalk"
18101+[ -x "$SNMPWALK" ] || SKIP
18102+
18103+snmp_version=v2c
18104+TESTCOMMUNITY=testcommunity
18105+. ./Sv2cconfig
18106+
18107+#
18108+# Begin test
18109+#
18110+oid=.1.3.6.1.4.1.8072.2.255 # NET-SNMP-PASS-MIB::netSnmpPassExamples
18111+CONFIGAGENT pass $oid ${srcdir}/local/passtest
18112+
18113+ORIG_AGENT_FLAGS="$AGENT_FLAGS"
18114+AGENT_FLAGS="$ORIG_AGENT_FLAGS -Ducd-snmp/pass"
18115+STARTAGENT
18116+
18117+#COMMENT Check a full walk of the sample data
18118+CAPTURE "$SNMPWALK $SNMP_FLAGS -$snmp_version -c $TESTCOMMUNITY $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT $oid"
18119+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassString.0 = STRING: Life, the Universe, and Everything"
18120+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassInteger.1 = INTEGER: 42"
18121+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassOID.1 = OID: NET-SNMP-PASS-MIB::netSnmpPassOIDValue"
18122+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassTimeTicks.0 = Timeticks: (363136200) 42 days, 0:42:42.00 "
18123+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassIpAddress.0 = IpAddress: 127.0.0.1"
18124+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassCounter.0 = Counter32: 42"
18125+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassGauge.0 = Gauge32: 42"
18126+
18127+#COMMENT A couple of spot checks of GET requests.
18128+CAPTURE "$SNMPGET $SNMP_FLAGS -$snmp_version -c $TESTCOMMUNITY $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT NET-SNMP-PASS-MIB::netSnmpPassInteger.1"
18129+CHECKORDIE "INTEGER: 42"
18130+
18131+CAPTURE "$SNMPGET $SNMP_FLAGS -$snmp_version -c $TESTCOMMUNITY $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT NET-SNMP-PASS-MIB::netSnmpPassCounter.0"
18132+CHECKORDIE "Counter32: 42"
18133+
18134+STOPAGENT
18135+FINISHED
18136diff --git a/testing/fulltests/default/T067passpersist_simple b/testing/fulltests/default/T067passpersist_simple
18137new file mode 100644
18138index 0000000..f91651a
18139--- /dev/null
18140+++ b/testing/fulltests/default/T067passpersist_simple
18141@@ -0,0 +1,61 @@
18142+#!/bin/sh
18143+
18144+. ../support/simple_eval_tools.sh
18145+
18146+HEADER "extending agent functionality with pass_persist"
18147+
18148+SKIPIF NETSNMP_DISABLE_SNMPV2C
18149+SKIPIFNOT USING_UCD_SNMP_PASS_PERSIST_MODULE
18150+
18151+# Don't run this test on MinGW - local/pass_persisttest is a shell script and
18152+# hence passing it to the MSVCRT popen() doesn't work.
18153+[ "x$OSTYPE" = "xmsys" ] && SKIP "MinGW"
18154+
18155+# make sure snmpget and snmpwalk can be executed
18156+SNMPGET="${builddir}/apps/snmpget"
18157+[ -x "$SNMPGET" ] || SKIP
18158+SNMPWALK="${builddir}/apps/snmpwalk"
18159+[ -x "$SNMPWALK" ] || SKIP
18160+
18161+snmp_version=v2c
18162+TESTCOMMUNITY=testcommunity
18163+. ./Sv2cconfig
18164+
18165+#
18166+# Begin test
18167+#
18168+oid=.1.3.6.1.4.1.8072.2.255 # NET-SNMP-PASS-MIB::netSnmpPassExamples
18169+CONFIGAGENT pass_persist $oid ${srcdir}/local/pass_persisttest
18170+
18171+ORIG_AGENT_FLAGS="$AGENT_FLAGS"
18172+AGENT_FLAGS="$ORIG_AGENT_FLAGS -Ducd-snmp/pass_persist"
18173+PASS_PERSIST_PIDFILE="$SNMP_TMPDIR/pass_persist.pid.$$"
18174+export PASS_PERSIST_PIDFILE
18175+STARTAGENT
18176+
18177+#COMMENT Check a full walk of the sample data
18178+CAPTURE "$SNMPWALK $SNMP_FLAGS -$snmp_version -c $TESTCOMMUNITY $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT $oid"
18179+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassString.0 = STRING: Life, the Universe, and Everything"
18180+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassInteger.1 = INTEGER: 42"
18181+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassOID.1 = OID: NET-SNMP-PASS-MIB::netSnmpPassOIDValue"
18182+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassTimeTicks.0 = Timeticks: (363136200) 42 days, 0:42:42.00 "
18183+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassIpAddress.0 = IpAddress: 127.0.0.1"
18184+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassCounter.0 = Counter32: 1"
18185+CHECKORDIE "NET-SNMP-PASS-MIB::netSnmpPassGauge.0 = Gauge32: 42"
18186+
18187+#COMMENT A couple of spot checks of GET requests.
18188+CAPTURE "$SNMPGET $SNMP_FLAGS -$snmp_version -c $TESTCOMMUNITY $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT NET-SNMP-PASS-MIB::netSnmpPassInteger.1"
18189+CHECKORDIE "INTEGER: 42"
18190+
18191+#COMMENT netSnmpPassCounter should increment, since this is pass_persist
18192+CAPTURE "$SNMPGET $SNMP_FLAGS -$snmp_version -c $TESTCOMMUNITY $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT NET-SNMP-PASS-MIB::netSnmpPassCounter.0"
18193+CHECKORDIE "Counter32: 2"
18194+
18195+#COMMENT now kill the pass_persist script, and check that it recovers.
18196+STOPPROG $PASS_PERSIST_PIDFILE
18197+#COMMENT netSnmpPassCounter should have reverted to 1, as this is a new instance.
18198+CAPTURE "$SNMPGET $SNMP_FLAGS -$snmp_version -c $TESTCOMMUNITY $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT NET-SNMP-PASS-MIB::netSnmpPassCounter.0"
18199+CHECKORDIE "Counter32: 1"
18200+
18201+STOPAGENT
18202+FINISHED
18203diff --git a/testing/fulltests/default/T111agentxset_simple b/testing/fulltests/default/T111agentxset_simple
18204index 2423be5..c767064 100644
18205--- a/testing/fulltests/default/T111agentxset_simple
18206+++ b/testing/fulltests/default/T111agentxset_simple
18207@@ -7,6 +7,7 @@ HEADER AgentX SET support
18208 SKIPIFNOT USING_AGENTX_MASTER_MODULE
18209 SKIPIFNOT USING_AGENTX_SUBAGENT_MODULE
18210 SKIPIFNOT USING_MIBII_SYSTEM_MIB_MODULE
18211+SKIPIF NETSNMP_DISABLE_SET_SUPPORT
18212
18213 #
18214 # Begin test
18215diff --git a/testing/fulltests/default/T112agentxsetfail_simple b/testing/fulltests/default/T112agentxsetfail_simple
18216index 9976144..4f1f0cb 100644
18217--- a/testing/fulltests/default/T112agentxsetfail_simple
18218+++ b/testing/fulltests/default/T112agentxsetfail_simple
18219@@ -7,6 +7,7 @@ HEADER AgentX illegal SET handling support
18220 SKIPIFNOT USING_AGENTX_MASTER_MODULE
18221 SKIPIFNOT USING_AGENTX_SUBAGENT_MODULE
18222 SKIPIFNOT USING_MIBII_SYSTEM_MIB_MODULE
18223+SKIPIF NETSNMP_DISABLE_SET_SUPPORT
18224
18225 #
18226 # Begin test
18227diff --git a/testing/fulltests/default/T114agentxagentxtrap_simple b/testing/fulltests/default/T114agentxagentxtrap_simple
18228index ae72d5c..58475d0 100644
18229--- a/testing/fulltests/default/T114agentxagentxtrap_simple
18230+++ b/testing/fulltests/default/T114agentxagentxtrap_simple
18231@@ -38,7 +38,7 @@ STOPAGENT
18232 STOPTRAPD
18233
18234 # Check that the trap was received
18235-CHECKTRAPD "mostly_harmless"
18236+CHECKTRAPD "= STRING: \"*mostly_harmless\"*"
18237
18238 # all done (whew)
18239 FINISHED
18240diff --git a/testing/fulltests/default/T121proxyset_simple b/testing/fulltests/default/T121proxyset_simple
18241index 335a2da..d3d77d9 100644
18242--- a/testing/fulltests/default/T121proxyset_simple
18243+++ b/testing/fulltests/default/T121proxyset_simple
18244@@ -6,7 +6,8 @@ HEADER Proxy SET support
18245
18246 SKIPIFNOT USING_UCD_SNMP_PROXY_MODULE
18247 SKIPIFNOT USING_MIBII_SYSTEM_MIB_MODULE
18248-SKIPIF NETSNMP_DISABLE_SNMPV2C
18249+SKIPIF NETSNMP_DISABLE_SNMPV2C
18250+SKIPIF NETSNMP_DISABLE_SET_SUPPORT
18251
18252 # XXX: ucd-snmp/proxy doesn't properly support TCP -- remove this once it does
18253 [ "x$SNMP_TRANSPORT_SPEC" = "xtcp" -o "x$SNMP_TRANSPORT_SPEC" = "xtcp6" ] && SKIP
18254diff --git a/testing/fulltests/default/T122proxysetfail_simple b/testing/fulltests/default/T122proxysetfail_simple
18255index a49b3ef..d149f56 100644
18256--- a/testing/fulltests/default/T122proxysetfail_simple
18257+++ b/testing/fulltests/default/T122proxysetfail_simple
18258@@ -6,7 +6,8 @@ HEADER Proxy illegal SET handling support
18259
18260 SKIPIFNOT USING_UCD_SNMP_PROXY_MODULE
18261 SKIPIFNOT USING_MIBII_SYSTEM_MIB_MODULE
18262-SKIPIF NETSNMP_DISABLE_SNMPV2C
18263+SKIPIF NETSNMP_DISABLE_SNMPV2C
18264+SKIPIF NETSNMP_DISABLE_SET_SUPPORT
18265
18266 # XXX: ucd-snmp/proxy doesn't properly support TCP -- remove this once it does
18267 [ "x$SNMP_TRANSPORT_SPEC" = "xtcp" ] && SKIP
18268diff --git a/testing/fulltests/default/T130snmpv1vacmget_simple b/testing/fulltests/default/T130snmpv1vacmget_simple
18269index 1974b7f..80623f4 100644
18270--- a/testing/fulltests/default/T130snmpv1vacmget_simple
18271+++ b/testing/fulltests/default/T130snmpv1vacmget_simple
18272@@ -16,6 +16,7 @@ SKIPIF NETSNMP_DISABLE_SNMPV1
18273 snmp_version=v1
18274 . ./Svacmconfig
18275
18276+AGENT_FLAGS="$AGENT_FLAGS -I-winExtDLL"
18277 STARTAGENT
18278
18279 CAPTURE "snmpget -On $SNMP_FLAGS -c testcommunity1 -v 1 $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT .1.3.6.1.2.1.1.1.0"
18280diff --git a/testing/fulltests/default/T141snmpv2cvacmgetfail_simple b/testing/fulltests/default/T141snmpv2cvacmgetfail_simple
18281index b97cf5d..69c2925 100644
18282--- a/testing/fulltests/default/T141snmpv2cvacmgetfail_simple
18283+++ b/testing/fulltests/default/T141snmpv2cvacmgetfail_simple
18284@@ -5,6 +5,7 @@
18285 HEADER SNMPv2 vacm denial support
18286
18287 SKIPIF NETSNMP_DISABLE_SNMPV2C
18288+SKIPIF NETSNMP_DISABLE_SET_SUPPORT
18289 SKIPIFNOT USING_MIBII_VACM_CONF_MODULE
18290
18291 #
18292diff --git a/testing/fulltests/snmpv3/T040keymanagetest_capp.c b/testing/fulltests/snmpv3/T040keymanagetest_capp.c
18293index f3f8dcc..d68f663 100644
18294--- a/testing/fulltests/snmpv3/T040keymanagetest_capp.c
18295+++ b/testing/fulltests/snmpv3/T040keymanagetest_capp.c
18296@@ -360,7 +360,6 @@ test_genkul(void)
18297 char *s = NULL;
18298 const char *testname = "Using HMACMD5 to create master key.";
18299 const char *hashname_Ku = "usmHMACMD5AuthProtocol";
18300- const char *hashname_kul = NULL;
18301
18302 u_char Ku[LOCAL_MAXBUF], kul[LOCAL_MAXBUF];
18303
18304@@ -413,7 +412,6 @@ test_genkul(void)
18305 test_genkul_again_master:
18306 memset(Ku, 0, LOCAL_MAXBUF);
18307 kulen = LOCAL_MAXBUF;
18308- hashname_kul = "usmHMACMD5AuthProtocol";
18309 hashtype_kul = usmHMACMD5AuthProtocol;
18310 properlength = BYTESIZE(SNMP_TRANS_AUTHLEN_HMACMD5);
18311
18312@@ -461,7 +459,6 @@ test_genkul(void)
18313 */
18314 if (hashtype_kul == usmHMACMD5AuthProtocol) {
18315 hashtype_kul = usmHMACSHA1AuthProtocol;
18316- hashname_kul = "usmHMACSHA1AuthProtocol";
18317 properlength = BYTESIZE(SNMP_TRANS_AUTHLEN_HMACSHA1);
18318 goto test_genkul_again_local;
18319 }
18320diff --git a/testing/fulltests/support/clib_build b/testing/fulltests/support/clib_build
18321index 7a72285..0c7eb6d 100755
18322--- a/testing/fulltests/support/clib_build
18323+++ b/testing/fulltests/support/clib_build
18324@@ -13,6 +13,7 @@ cat >>"$2.c" <<EOF
18325 #include <net-snmp/library/testing.h>
18326
18327 /* standard headers */
18328+#include <errno.h>
18329 #include <stdio.h>
18330 #include <sys/types.h>
18331 #ifdef HAVE_STDLIB_H
18332@@ -23,6 +24,9 @@ cat >>"$2.c" <<EOF
18333 #else
18334 #include <strings.h>
18335 #endif
18336+#ifdef HAVE_NETDB_H
18337+#include <netdb.h>
18338+#endif
18339 #ifdef HAVE_ARPA_INET_H
18340 #include <arpa/inet.h>
18341 #endif
18342diff --git a/testing/fulltests/support/simple_TESTCONF.sh b/testing/fulltests/support/simple_TESTCONF.sh
18343index f8f229a..83c38c2 100644
18344--- a/testing/fulltests/support/simple_TESTCONF.sh
18345+++ b/testing/fulltests/support/simple_TESTCONF.sh
18346@@ -7,6 +7,28 @@
18347 # *SNMP_PERSISTENT_FILE: where to store the agent's persistent information
18348 # (XXX: this should be specific to just the agent)
18349
18350+# MinGW/MSYS only: translate an MSYS path back into a DOS path such that snmpd
18351+# and the Net-SNMP applications can understand it. One of the features of MSYS
18352+# is that if a POSIX-style path is passed as a command-line argument to an
18353+# executable that MSYS translates that path to a DOS-style path before
18354+# starting the executable. This is a key feature of MSYS that makes it
18355+# possible to run shell scripts unmodified and at the same time to use
18356+# executables that accept DOS-style paths. There is no support however for
18357+# automatical translation of environment variables that contain paths. Hence
18358+# this function that translates paths explicitly.
18359+translate_path() {
18360+ if [ "$OSTYPE" = msys ]; then
18361+ local t=`set \
18362+ | sed -n -e "s/^$1='\(.*\)'$/${SNMP_ENV_SEPARATOR}\1/p" \
18363+ -e "s/^$1=\(.*\)$/${SNMP_ENV_SEPARATOR}\1/p" \
18364+ | sed -e "s|${SNMP_ENV_SEPARATOR}/c/|${SNMP_ENV_SEPARATOR}c:/|g" \
18365+ -e "s|${SNMP_ENV_SEPARATOR}/tmp/|${SNMP_ENV_SEPARATOR}c:/windows/temp/|g" \
18366+ | sed -e "s/^${SNMP_ENV_SEPARATOR}//" \
18367+ `
18368+ eval "$1='$t'"
18369+ fi
18370+}
18371+
18372 #
18373 # Only allow ourselves to be eval'ed once
18374 #
18375@@ -48,6 +70,8 @@ if [ "x$SNMP_VERBOSE" = "x" ]; then
18376 export SNMP_VERBOSE
18377 fi
18378
18379+SNMP_ENV_SEPARATOR="`${builddir}/net-snmp-config --env-separator`"
18380+
18381 if [ "x$MIBDIRS" = "x" ]; then
18382 if [ "x$SNMP_PREFER_NEAR_MIBS" = "x1" ]; then
18383 MIBDIRS=${srcdir}/mibs
18384@@ -103,6 +127,7 @@ if [ "x$SNMP_HEADERONLY" != "xyes" ]; then
18385 testnum=0
18386 fi
18387 SNMP_TMPDIR="/tmp/snmp-test-$testnum-$$"
18388+ translate_path SNMP_TMPDIR
18389 export SNMP_TMPDIR
18390 if [ -d $SNMP_TMPDIR ]; then
18391 echo "$0: ERROR: $SNMP_TMPDIR already existed."
18392@@ -110,7 +135,7 @@ if [ "x$SNMP_HEADERONLY" != "xyes" ]; then
18393 fi
18394 fi
18395 if [ ! -d $SNMP_TMPDIR ]; then
18396- mkdir $SNMP_TMPDIR
18397+ mkdir -p $SNMP_TMPDIR
18398 chmod 0700 $SNMP_TMPDIR
18399 fi
18400 if [ "x$SNMP_TMP_PERSISTENTDIR" = "x" ]; then
18401@@ -130,7 +155,6 @@ fi
18402
18403 SNMP_IGNORE_WINDOWS_REGISTRY="true"
18404 export SNMP_IGNORE_WINDOWS_REGISTRY
18405-SNMP_ENV_SEPARATOR="`${builddir}/net-snmp-config --env-separator`"
18406 SNMP_PERLPROG="`${builddir}/net-snmp-config --perlprog`"
18407 SNMP_TESTDIR="$SNMP_BASEDIR/tests"
18408 SNMP_CONFIG_FILE="$SNMP_TMPDIR/snmpd.conf"
18409@@ -144,8 +168,10 @@ SNMP_SNMPD_LOG_FILE="$SNMP_TMPDIR/snmpd.log"
18410 SNMP_AGENTX_PID_FILE="$SNMP_TMPDIR/agentx.pid"
18411 SNMP_AGENTX_LOG_FILE="$SNMP_TMPDIR/agentx.log"
18412 SNMPCONFPATH="${SNMP_TMPDIR}${SNMP_ENV_SEPARATOR}${SNMP_TMP_PERSISTENTDIR}"
18413+translate_path SNMPCONFPATH
18414 export SNMPCONFPATH
18415 SNMP_PERSISTENT_DIR=$SNMP_TMP_PERSISTENTDIR
18416+translate_path SNMP_PERSISTENT_DIR
18417 export SNMP_PERSISTENT_DIR
18418 #SNMP_PERSISTENT_FILE="$SNMP_TMP_PERSISTENTDIR/persistent-store.conf"
18419 #export SNMP_PERSISTENT_FILE
18420@@ -175,8 +201,12 @@ else
18421 fi
18422
18423 if [ "x$OSTYPE" = "xmsys" ]; then
18424- # To do: make configure find out the path of MSYS' sh.exe.
18425- MSYS_SH="c:/msys/1.0/bin/sh.exe"
18426+ # Obtain the MSYS installation path from the !C: environment variable,
18427+ # remove surrounding single quotes and convert backslashes into forward
18428+ # slashes.
18429+ MSYS_PATH="$(set \
18430+ | sed -n 's|^\!C:='"'"'\(.*\)'"'"'$|\1|p' | sed 's|\\|/|g')"
18431+ MSYS_SH="$MSYS_PATH/sh.exe"
18432 fi
18433
18434 PROBE_FOR_PORT() {
18435diff --git a/testing/fulltests/support/simple_eval_tools.sh b/testing/fulltests/support/simple_eval_tools.sh
18436index f16d9a6..d1dfbc8 100644
18437--- a/testing/fulltests/support/simple_eval_tools.sh
18438+++ b/testing/fulltests/support/simple_eval_tools.sh
18439@@ -114,7 +114,7 @@ SKIP() {
18440 }
18441
18442 ISDEFINED() {
18443- grep "^#define $1" ${builddir}/include/net-snmp/net-snmp-config.h ${builddir}/include/net-snmp/agent/mib_module_config.h ${builddir}/include/net-snmp/agent/agent_module_config.h > /dev/null
18444+ grep -wq "^#define $1" ${builddir}/include/net-snmp/net-snmp-config.h ${builddir}/include/net-snmp/agent/mib_module_config.h ${builddir}/include/net-snmp/agent/agent_module_config.h
18445 }
18446
18447 SKIPIFNOT() {
18448@@ -131,7 +131,7 @@ VERIFY() { # <path_to_file(s)>
18449 local missingfiles=
18450
18451 for f in $*; do
18452- [ -e "$f" ] && continue
18453+ [ -f "$f" ] && continue
18454 echo "FAILED: Cannot find file \"$f\"."
18455 missingfiles=true
18456 done
18457@@ -148,7 +148,7 @@ NEWOUTPUTFILE() {
18458 #
18459 STARTTEST() {
18460 NEWOUTPUTFILE
18461- [ ! -e "$junkoutputfile" ] && {
18462+ [ ! -f "$junkoutputfile" ] && {
18463 touch $junkoutputfile
18464 return
18465 }
18466@@ -365,7 +365,7 @@ ISRUNNING() {
18467 # Echo a command that asks the process with pid $1 to stop.
18468 ECHOSENDSIGTERM() {
18469 if [ "x$OSTYPE" = "xmsys" ]; then
18470- echo kill.exe $1
18471+ echo pskill.exe $1
18472 else
18473 echo kill -TERM $1
18474 fi
18475@@ -374,7 +374,7 @@ ECHOSENDSIGTERM() {
18476 # Echo a command that stops the process with pid $1 forcibly.
18477 ECHOSENDSIGKILL() {
18478 if [ "x$OSTYPE" = "xmsys" ]; then
18479- echo kill.exe $1
18480+ echo pskill.exe $1
18481 else
18482 echo kill -KILL $1
18483 fi
18484@@ -489,7 +489,6 @@ CONFIGAPP() {
18485 #
18486 # common to STARTAGENT and STARTTRAPD
18487 # log command to "invoked" file
18488-# delay after command to allow for settle
18489 #
18490 STARTPROG() {
18491 if [ "x$DYNAMIC_ANALYZER" != "x" ]; then
18492@@ -537,6 +536,7 @@ STARTAGENT() {
18493 PORT_SPEC="${SNMP_TRANSPORT_SPEC}:${SNMP_TEST_DEST}${PORT_SPEC}"
18494 fi
18495 STARTPROG
18496+ WAITFORCOND test -f $SNMP_SNMPD_PID_FILE
18497 WAITFORAGENT "NET-SNMP version"
18498 }
18499
18500@@ -551,6 +551,7 @@ STARTTRAPD() {
18501 PORT_SPEC="${SNMP_TRANSPORT_SPEC}:${SNMP_TEST_DEST}${PORT_SPEC}"
18502 fi
18503 STARTPROG
18504+ WAITFORCOND test -f $SNMP_SNMPTRAPD_PID_FILE
18505 WAITFORTRAPD "NET-SNMP version"
18506 }
18507
18508@@ -559,7 +560,7 @@ STARTTRAPD() {
18509 HUPPROG() {
18510 if [ -f $1 ]; then
18511 if [ "x$OSTYPE" = "xmsys" ]; then
18512- COMMAND='echo "Skipping SIGHUP (not supported by kill.exe on MinGW)"'
18513+ COMMAND='echo "Skipping SIGHUP (not possible with MinGW)"'
18514 else
18515 COMMAND="kill -HUP `cat $1`"
18516 fi
18517@@ -595,7 +596,10 @@ STOPPROG() {
18518 echo "$COMMAND ($1)" >> $SNMP_TMPDIR/invoked
18519 VERBOSE_OUT 0 "$COMMAND ($1)"
18520 $COMMAND >/dev/null 2>&1
18521- if [ "x$OSTYPE" != "xmsys" ]; then
18522+ if [ "x$OSTYPE" = "xmsys" ]; then
18523+ # Wait until $pid and its parent have stopped.
18524+ sleep 1
18525+ else
18526 WAITFORNOTCOND "ISRUNNING $pid"
18527 fi
18528 fi
18529diff --git a/testing/fulltests/unit-tests/T004snmp_enum_clib.c b/testing/fulltests/unit-tests/T004snmp_enum_clib.c
18530index e78ffca..d28b19b 100644
18531--- a/testing/fulltests/unit-tests/T004snmp_enum_clib.c
18532+++ b/testing/fulltests/unit-tests/T004snmp_enum_clib.c
18533@@ -1,15 +1,69 @@
18534 /* HEADER Testing snmp_enum */
18535
18536+#define CONFIG_TYPE "snmp-enum-unit-test"
18537 #define STRING1 "life, and everything"
18538 #define STRING2 "restaurant at the end of the universe"
18539 #define STRING3 "label3"
18540+#define LONG_STRING "a-string-of-255-characters-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
18541
18542+#define STORE_AND_COMPARE(maj, min, s) \
18543+ { \
18544+ FILE *fp; \
18545+ int read = 0; \
18546+ char *p, contents[4096]; \
18547+ \
18548+ se_store_list(maj, min, CONFIG_TYPE); \
18549+ fp = fopen(tmp_persist_file, "r"); \
18550+ if (fp) { \
18551+ read = fread(contents, 1, sizeof(contents) - 1, fp); \
18552+ fclose(fp); \
18553+ } \
18554+ contents[read > 0 ? read : 0] = '\0'; \
18555+ for (p = contents; *p; ++p) \
18556+ if (*p == '\n') \
18557+ *p = '|'; \
18558+ OKF(strcmp(contents, (s)) == 0, \
18559+ ("stored list %s <> %s", (s), contents)); \
18560+ remove(tmp_persist_file); \
18561+ }
18562+
18563+char tmp_persist_file[256];
18564 char *se_find_result;
18565
18566+sprintf(tmp_persist_file, "/tmp/snmp-enum-unit-test-%d", getpid());
18567+netsnmp_setenv("SNMP_PERSISTENT_FILE", tmp_persist_file, 1);
18568+
18569 init_snmp_enum("snmp");
18570+
18571+STORE_AND_COMPARE(1, 1, "enum 1:1|");
18572+
18573 se_add_pair(1, 1, strdup("hi"), 1);
18574+
18575+STORE_AND_COMPARE(1, 1, "enum 1:1 1:hi|");
18576+
18577 se_add_pair(1, 1, strdup("there"), 2);
18578
18579+STORE_AND_COMPARE(1, 1, "enum 1:1 1:hi 2:there|");
18580+
18581+se_add_pair(1, 1, strdup(LONG_STRING), 3);
18582+se_add_pair(1, 1, strdup(LONG_STRING), 4);
18583+se_add_pair(1, 1, strdup(LONG_STRING), 5);
18584+se_add_pair(1, 1, strdup(LONG_STRING), 6);
18585+se_add_pair(1, 1, strdup(LONG_STRING), 7);
18586+se_add_pair(1, 1, strdup(LONG_STRING), 8);
18587+se_add_pair(1, 1, strdup(LONG_STRING), 9);
18588+
18589+STORE_AND_COMPARE(1, 1, "enum 1:1 1:hi 2:there 3:" LONG_STRING " 4:" LONG_STRING
18590+ " 5:" LONG_STRING " 6:" LONG_STRING " 7:" LONG_STRING
18591+ " 8:" LONG_STRING " 9:" LONG_STRING "|");
18592+
18593+se_add_pair(1, 1, strdup(LONG_STRING), 10);
18594+
18595+STORE_AND_COMPARE(1, 1, "enum 1:1 1:hi 2:there 3:" LONG_STRING " 4:" LONG_STRING
18596+ " 5:" LONG_STRING " 6:" LONG_STRING " 7:" LONG_STRING
18597+ " 8:" LONG_STRING " 9:" LONG_STRING "|"
18598+ "enum 1:1 10:" LONG_STRING "|");
18599+
18600 OK(se_find_value(1, 1, "hi") == 1,
18601 "lookup by number #1 should be the proper string");
18602 OK(strcmp(se_find_label(1, 1, 2), "there") == 0,
18603@@ -33,10 +87,10 @@ se_read_conf("enum",
18604 OK(se_find_list(2, 3), "list (2, 3) should be present");
18605 if (se_find_list(2, 3)) {
18606 OK(se_find_value(2, 3, "kiwifruit") == 3,
18607- "lookup by string should return the proper value")
18608+ "lookup by string should return the proper value");
18609 se_find_result = se_find_label(2, 3, 2);
18610 OK(se_find_result && strcmp(se_find_result, "pear") == 0,
18611- "lookup by label should return the proper string")
18612+ "lookup by label should return the proper string");
18613 }
18614
18615 se_read_conf("enum",
18616diff --git a/testing/fulltests/unit-tests/T008asn1_clib.c b/testing/fulltests/unit-tests/T008asn1_clib.c
18617index 222ec7a..73a2f73 100644
18618--- a/testing/fulltests/unit-tests/T008asn1_clib.c
18619+++ b/testing/fulltests/unit-tests/T008asn1_clib.c
18620@@ -78,6 +78,8 @@ debug_register_tokens("dumpv_recv,dumpv_send,asn");
18621 }
18622 }
18623
18624+#ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
18625+
18626 #define TOINT64(c) ((long long)(long)(c).high << 32 | (c).low)
18627
18628 {
18629@@ -128,6 +130,8 @@ debug_register_tokens("dumpv_recv,dumpv_send,asn");
18630 }
18631 }
18632
18633+#endif
18634+
18635 #define TOUINT64(c) ((unsigned long long)(c).high << 32 | (c).low)
18636
18637 {
18638diff --git a/testing/fulltests/unit-tests/T009large_fd_set_clib.c b/testing/fulltests/unit-tests/T009large_fd_set_clib.c
18639index 0951dc2..eee4d41 100644
18640--- a/testing/fulltests/unit-tests/T009large_fd_set_clib.c
18641+++ b/testing/fulltests/unit-tests/T009large_fd_set_clib.c
18642@@ -2,7 +2,8 @@
18643
18644 netsnmp_large_fd_set fds;
18645 netsnmp_large_fd_set_init(&fds, 2000);
18646-netsnmp_large_fd_set_resize(&fds, 2000);
18647+OKF(fds.lfs_setsize == 2000, ("initialization"));
18648+OKF(netsnmp_large_fd_set_resize(&fds, 2000) == 1, ("resizing to 2000"));
18649 NETSNMP_LARGE_FD_ZERO(&fds);
18650
18651 {
18652@@ -16,7 +17,7 @@ NETSNMP_LARGE_FD_ZERO(&fds);
18653 }
18654 }
18655
18656-netsnmp_large_fd_set_resize(&fds, 3000);
18657+OKF(netsnmp_large_fd_set_resize(&fds, 3000) == 1, ("resizing to 3000"));
18658
18659 {
18660 int i;
18661@@ -29,7 +30,7 @@ netsnmp_large_fd_set_resize(&fds, 3000);
18662 }
18663 }
18664
18665-netsnmp_large_fd_set_resize(&fds, 1000);
18666+OKF(netsnmp_large_fd_set_resize(&fds, 1000) == 1, ("resizing to 1000"));
18667
18668 {
18669 int i;
18670diff --git a/testing/fulltests/unit-tests/T011snmp_old_api_registration_cagentlib.c b/testing/fulltests/unit-tests/T011snmp_old_api_registration_cagentlib.c
18671new file mode 100644
18672index 0000000..6f1d449
18673--- /dev/null
18674+++ b/testing/fulltests/unit-tests/T011snmp_old_api_registration_cagentlib.c
18675@@ -0,0 +1,46 @@
18676+/* HEADER Testing SNMP handler registration via the old API */
18677+
18678+static oid Oid[] = { 1, 3, 6, 1, 3, 327 }; /* experimental.327 */
18679+struct variable var_array[] = {
18680+ { 0, 0/*type*/, 0/*acl*/, NULL/*findVar*/, 7, { 1, 3, 6, 1, 3, 327, 1 } },
18681+ { 0, 0/*type*/, 0/*acl*/, NULL/*findVar*/, 7, { 1, 3, 6, 1, 3, 327, 2 } },
18682+ { 0, 0/*type*/, 0/*acl*/, NULL/*findVar*/, 7, { 1, 3, 6, 1, 3, 327, 3 } },
18683+};
18684+netsnmp_session *sess;
18685+int res;
18686+
18687+init_snmp("snmp");
18688+
18689+sess = calloc(1, sizeof(*sess));
18690+snmp_sess_init(sess);
18691+
18692+res =
18693+netsnmp_register_old_api("exp.327.a",
18694+ var_array,
18695+ sizeof(var_array[0]),
18696+ sizeof(var_array)/sizeof(var_array[0]),
18697+ Oid,
18698+ sizeof(Oid)/sizeof(Oid[0]),
18699+ 2, /* priority */
18700+ 0, /* range_subid */
18701+ 0, /* range_ubound */
18702+ sess,
18703+ "context", 5/*timeout*/, 0/*flags - ignored*/);
18704+OK(res == SNMPERR_SUCCESS, "Handler registration (1).");
18705+
18706+/* Verify that duplicate registration does not cause any havoc. */
18707+res =
18708+netsnmp_register_old_api("exp.327.b",
18709+ var_array,
18710+ sizeof(var_array[0]),
18711+ sizeof(var_array)/sizeof(var_array[0]),
18712+ Oid,
18713+ sizeof(Oid)/sizeof(Oid[0]),
18714+ 2, /* priority */
18715+ 0, /* range_subid */
18716+ 0, /* range_ubound */
18717+ sess,
18718+ "context", 5/*timeout*/, 0/*flags - ignored*/);
18719+OK(res == SNMPERR_SUCCESS, "Handler registration (2).");
18720+
18721+snmp_shutdown("snmp");
18722diff --git a/testing/fulltests/unit-tests/T012binary_array_oid_clib.c b/testing/fulltests/unit-tests/T012binary_array_oid_clib.c
18723new file mode 100644
18724index 0000000..aeeb502
18725--- /dev/null
18726+++ b/testing/fulltests/unit-tests/T012binary_array_oid_clib.c
18727@@ -0,0 +1,72 @@
18728+/* HEADER Testing binary OID array */
18729+
18730+static const char test_name[] = "binary-array-of-OIDs-test";
18731+oid o1 = 1;
18732+oid o2 = 2;
18733+oid o3 = 6;
18734+oid o4 = 8;
18735+oid o5 = 9;
18736+oid ox = 7;
18737+oid oy = 10;
18738+netsnmp_index i1, i2, i3, i4, i5, ix, iy, *ip;
18739+const netsnmp_index *const i_last = &i5;
18740+netsnmp_index *a[] = { &ix, &iy };
18741+netsnmp_index *b[] = { &i4, &i2, &i3, &i1, &i5 };
18742+netsnmp_container *c;
18743+int i;
18744+
18745+init_snmp(test_name);
18746+
18747+c = netsnmp_container_get_binary_array();
18748+c->compare = netsnmp_compare_netsnmp_index;
18749+
18750+i1.oids = &o1;
18751+i2.oids = &o2;
18752+i3.oids = &o3;
18753+i4.oids = &o4;
18754+i5.oids = &o5;
18755+ix.oids = &ox;
18756+iy.oids = &oy;
18757+i1.len = i2.len = i3.len = i4.len = i5.len = ix.len = iy.len = 1;
18758+
18759+for (i = 0; i < sizeof(b)/sizeof(b[0]); ++i)
18760+ CONTAINER_INSERT(c, b[i]);
18761+
18762+for (ip = CONTAINER_FIRST(c); ip; ip = CONTAINER_NEXT(c, ip)) {
18763+ for (i = sizeof(b)/sizeof(b[0]) - 1; i >= 0; --i)
18764+ if (c->compare(ip, b[i]) == 0)
18765+ break;
18766+ OKF(i >= 0, ("OID b[%d] = %" NETSNMP_PRIo "d present", i, b[i]->oids[0]));
18767+}
18768+
18769+for (i = 0; i < sizeof(b)/sizeof(b[0]); ++i) {
18770+ ip = CONTAINER_FIND(c, b[i]);
18771+ OKF(ip, ("Value b[%d] = %" NETSNMP_PRIo "d present", i, b[i]->oids[0]));
18772+ ip = CONTAINER_NEXT(c, b[i]);
18773+ if (c->compare(b[i], i_last) < 0)
18774+ OKF(ip && c->compare(b[i], ip) < 0,
18775+ ("Successor of b[%d] = %" NETSNMP_PRIo "d is %" NETSNMP_PRIo "d",
18776+ i, b[i]->oids[0], ip->oids[0]));
18777+ else
18778+ OKF(!ip, ("No successor found for b[%d] = %" NETSNMP_PRIo "d", i,
18779+ b[i]->oids[0]));
18780+}
18781+
18782+for (i = 0; i < sizeof(a)/sizeof(a[0]); ++i) {
18783+ ip = CONTAINER_FIND(c, a[i]);
18784+ OKF(!ip, ("a[%d] = %" NETSNMP_PRIo "d absent", i, a[i]->oids[0]));
18785+ ip = CONTAINER_NEXT(c, a[i]);
18786+ if (c->compare(a[i], i_last) < 0)
18787+ OKF(ip && c->compare(ip, a[i]) > 0,
18788+ ("Successor of a[%d] = %" NETSNMP_PRIo "d is %" NETSNMP_PRIo "d",
18789+ i, a[i]->oids[0], ip->oids[0]));
18790+ else
18791+ OKF(!ip, ("No successor found for a[%d] = %" NETSNMP_PRIo "d", i,
18792+ a[i]->oids[0]));
18793+}
18794+
18795+while ((ip = CONTAINER_FIRST(c)))
18796+ CONTAINER_REMOVE(c, ip);
18797+CONTAINER_FREE(c);
18798+
18799+snmp_shutdown(test_name);
18800diff --git a/testing/fulltests/unit-tests/T013binary_array_string_clib.c b/testing/fulltests/unit-tests/T013binary_array_string_clib.c
18801new file mode 100644
18802index 0000000..cc4361b
18803--- /dev/null
18804+++ b/testing/fulltests/unit-tests/T013binary_array_string_clib.c
18805@@ -0,0 +1,59 @@
18806+/* HEADER Testing binary string array */
18807+
18808+static const char test_name[] = "binary-array-of-strings-test";
18809+const char o1[] = "zebra";
18810+const char o2[] = "b-two";
18811+const char o3[] = "b";
18812+const char o4[] = "cedar";
18813+const char o5[] = "alpha";
18814+const char ox[] = "dev";
18815+const char oy[] = "aa";
18816+const char* const o_last = o1;
18817+const char *ip;
18818+const char *const a[] = { ox, oy };
18819+const char *const b[] = { o4, o2, o3, o1, o5 };
18820+netsnmp_container *c;
18821+int i;
18822+
18823+init_snmp(test_name);
18824+
18825+c = netsnmp_container_get_binary_array();
18826+c->compare = (netsnmp_container_compare*)strcmp;
18827+
18828+for (i = 0; i < sizeof(b)/sizeof(b[0]); ++i)
18829+ CONTAINER_INSERT(c, b[i]);
18830+
18831+for (ip = CONTAINER_FIRST(c); ip; ip = CONTAINER_NEXT(c, ip)) {
18832+ for (i = sizeof(b)/sizeof(b[0]) - 1; i >= 0; --i)
18833+ if (c->compare(ip, b[i]) == 0)
18834+ break;
18835+ OKF(i >= 0, ("string b[%d] = \"%s\" present", i, b[i]));
18836+}
18837+
18838+for (i = 0; i < sizeof(b)/sizeof(b[0]); ++i) {
18839+ ip = CONTAINER_FIND(c, b[i]);
18840+ OKF(ip, ("b[%d] = \"%s\" present", i, b[i]));
18841+ ip = CONTAINER_NEXT(c, b[i]);
18842+ if (c->compare(b[i], o_last) < 0)
18843+ OKF(ip && c->compare(b[i], ip) < 0,
18844+ ("Successor of b[%d] = \"%s\" is \"%s\"", i, b[i], ip));
18845+ else
18846+ OKF(!ip, ("No successor found for b[%d] = \"%s\"", i, b[i]));
18847+}
18848+
18849+for (i = 0; i < sizeof(a)/sizeof(a[0]); ++i) {
18850+ ip = CONTAINER_FIND(c, a[i]);
18851+ OKF(!ip, ("a[%d] = \"%s\" absent", i, a[i]));
18852+ ip = CONTAINER_NEXT(c, a[i]);
18853+ if (c->compare(a[i], o_last) < 0)
18854+ OKF(ip && c->compare(ip, a[i]) > 0,
18855+ ("Successor of a[%d] = \"%s\" is \"%s\"", i, a[i], ip));
18856+ else
18857+ OKF(!ip, ("No successor found for a[%d] = \"%s\"", i, a[i]));
18858+}
18859+
18860+while ((ip = CONTAINER_FIRST(c)))
18861+ CONTAINER_REMOVE(c, ip);
18862+CONTAINER_FREE(c);
18863+
18864+snmp_shutdown(test_name);
18865diff --git a/testing/fulltests/unit-tests/T014gethostbyaddr_clib.c b/testing/fulltests/unit-tests/T014gethostbyaddr_clib.c
18866new file mode 100644
18867index 0000000..4c633ed
18868--- /dev/null
18869+++ b/testing/fulltests/unit-tests/T014gethostbyaddr_clib.c
18870@@ -0,0 +1,55 @@
18871+/* HEADER Testing netsnmp_gethostbyaddr() */
18872+
18873+SOCK_STARTUP;
18874+
18875+{
18876+ int ran_test = 0;
18877+#ifdef HAVE_GETHOSTBYADDR
18878+ struct hostent *h;
18879+ struct in_addr v4loop;
18880+ struct sockaddr_in sin_addr;
18881+ int s;
18882+
18883+ v4loop.s_addr = htonl(INADDR_LOOPBACK);
18884+ memset(&sin_addr, 0, sizeof(sin_addr));
18885+ sin_addr.sin_family = AF_INET;
18886+ sin_addr.sin_addr = v4loop;
18887+ s = socket(AF_INET, SOCK_DGRAM, 0);
18888+ if (s >= 0) {
18889+ if (bind(s, (struct sockaddr *)&sin_addr, sizeof(sin_addr)) >= 0) {
18890+ h = netsnmp_gethostbyaddr(&v4loop, sizeof(v4loop), AF_INET);
18891+ OKF(h && strcmp(h->h_name, "localhost") == 0,
18892+ ("127.0.0.1 lookup (%s)", h ? h->h_name : "(failed)"));
18893+ ran_test = 1;
18894+ }
18895+ close(s);
18896+ }
18897+#endif
18898+ if (!ran_test)
18899+ OKF(1, ("Skipped IPv4 test"));
18900+}
18901+
18902+{
18903+ struct hostent *h;
18904+ static const struct in6_addr v6loop = IN6ADDR_LOOPBACK_INIT;
18905+ struct sockaddr_in6 sin6_addr;
18906+ int s, ran_test = 0;
18907+
18908+ memset(&sin6_addr, 0, sizeof(sin6_addr));
18909+ sin6_addr.sin6_family = AF_INET6;
18910+ sin6_addr.sin6_addr = v6loop;
18911+ s = socket(AF_INET6, SOCK_DGRAM, 0);
18912+ if (s >= 0) {
18913+ if (bind(s, (struct sockaddr*)&sin6_addr, sizeof(sin6_addr)) >= 0) {
18914+ h = netsnmp_gethostbyaddr(&v6loop, sizeof(v6loop), AF_INET6);
18915+ OKF(h && strcmp(h->h_name, "localhost") == 0,
18916+ ("::1 lookup (%s)", h ? h->h_name : "(failed)"));
18917+ ran_test = 1;
18918+ }
18919+ close(s);
18920+ }
18921+ if (!ran_test)
18922+ OKF(1, ("Skipped IPv6 test"));
18923+}
18924+
18925+SOCK_CLEANUP;
18926diff --git a/testing/fulltests/unit-tests/T015int64_clib.c b/testing/fulltests/unit-tests/T015int64_clib.c
18927new file mode 100644
18928index 0000000..5f5f4b6
18929--- /dev/null
18930+++ b/testing/fulltests/unit-tests/T015int64_clib.c
18931@@ -0,0 +1,82 @@
18932+/* HEADER Testing 64-bit integer operations (U64). */
18933+
18934+int i, j;
18935+char buf[22];
18936+static const int64_t intval[] = {
18937+ 0,
18938+ -1,
18939+ 1,
18940+ 37,
18941+ 0x7fffffffUL,
18942+ 0x80000000UL,
18943+ 0x99999999UL,
18944+ 0x7fffffffffffffffULL,
18945+ 0x8000000000000000ULL,
18946+};
18947+
18948+for (i = 0; i < sizeof(intval)/sizeof(intval[0]); ++i) {
18949+ U64 a, b;
18950+ a.low = (uint32_t)intval[i];
18951+ a.high = (uint32_t)(intval[i] >> 32);
18952+ printI64(buf, &a);
18953+ read64(&b, buf);
18954+ OKF(memcmp(&a, &b, sizeof(a)) == 0,
18955+ ("[%d]: %" PRId64 " <> %s <> %" PRId64, i, intval[i], buf,
18956+ ((uint64_t)b.high) << 32 | b.low));
18957+}
18958+
18959+for (i = 0; i < sizeof(intval)/sizeof(intval[0]); ++i) {
18960+ for (j = i; j < sizeof(intval)/sizeof(intval[0]); ++j) {
18961+ U64 a, b;
18962+ uint64_t d;
18963+ a.low = (uint32_t)intval[i];
18964+ a.high = (uint32_t)(intval[i] >> 32);
18965+ b.low = (uint32_t)intval[j];
18966+ b.high = (uint32_t)(intval[j] >> 32);
18967+ u64Incr(&a, &b);
18968+ d = (uint64_t)a.high << 32 | a.low;
18969+ OKF(intval[i] + intval[j] == d,
18970+ ("%" PRId64 " + %" PRId64 " = %" PRId64 " <> %" PRId64, intval[i],
18971+ intval[j], intval[i] + intval[j], d));
18972+ }
18973+}
18974+
18975+for (i = 0; i < sizeof(intval)/sizeof(intval[0]); ++i) {
18976+ for (j = i; j < sizeof(intval)/sizeof(intval[0]); ++j) {
18977+ U64 a, b, c;
18978+ uint64_t d;
18979+ a.low = (uint32_t)intval[i];
18980+ a.high = (uint32_t)(intval[i] >> 32);
18981+ b.low = (uint32_t)intval[j];
18982+ b.high = (uint32_t)(intval[j] >> 32);
18983+ u64Subtract(&a, &b, &c);
18984+ d = (uint64_t)c.high << 32 | c.low;
18985+ OKF(intval[i] - intval[j] == d,
18986+ ("%" PRId64 " - %" PRId64 " = %" PRId64 " <> %" PRId64, intval[i],
18987+ intval[j], intval[i] - intval[j], d));
18988+ }
18989+}
18990+
18991+{
18992+ U64 old_val, new_val;
18993+ old_val.low = 7;
18994+ old_val.high = 0;
18995+ new_val = old_val;
18996+ OK(netsnmp_c64_check_for_32bit_wrap(&old_val, &new_val, 0) == 0, "cwrap1");
18997+ new_val.low = 8;
18998+ OK(netsnmp_c64_check_for_32bit_wrap(&old_val, &new_val, 0) == 0, "cwrap2");
18999+ new_val.low = 6;
19000+ OK(netsnmp_c64_check_for_32bit_wrap(&old_val, &new_val, 0) == 32, "cwrap3");
19001+ OK(netsnmp_c64_check_for_32bit_wrap(&old_val, &new_val, 1) == 32
19002+ && new_val.low == 6 && new_val.high == 1, "cwrap4");
19003+ old_val.low = 7;
19004+ old_val.high = 0xffffffffU;
19005+ new_val.low = 7;
19006+ new_val.high = old_val.high;
19007+ OK(netsnmp_c64_check_for_32bit_wrap(&old_val, &new_val, 0) == 0, "cwrap5");
19008+ new_val.low = 8;
19009+ OK(netsnmp_c64_check_for_32bit_wrap(&old_val, &new_val, 0) == 0, "cwrap6");
19010+ new_val.low = 6;
19011+ new_val.high = 0;
19012+ OK(netsnmp_c64_check_for_32bit_wrap(&old_val, &new_val, 0) == 64, "cwrap7");
19013+}
19014diff --git a/testing/fulltests/unit-tests/T016read_config_clib.c b/testing/fulltests/unit-tests/T016read_config_clib.c
19015new file mode 100644
19016index 0000000..c11a591
19017--- /dev/null
19018+++ b/testing/fulltests/unit-tests/T016read_config_clib.c
19019@@ -0,0 +1,82 @@
19020+/* HEADER Testing read_config_read_octet_string_const(). */
19021+
19022+struct read_config_testcase {
19023+ /*
19024+ * inputs
19025+ */
19026+ const char *(*pf) (const char * readfrom, u_char ** str,
19027+ size_t * len);
19028+ const char *readfrom;
19029+ size_t obuf_len;
19030+
19031+ /*
19032+ * expected outputs
19033+ */
19034+ size_t expected_offset;
19035+ const u_char *expected_output;
19036+ size_t expected_len;
19037+};
19038+
19039+static const u_char obuf1[] = { 1, 0, 2 };
19040+static const u_char obuf2[] = { 'a', 'b', 'c', 0 };
19041+
19042+static const struct read_config_testcase test_input[] = {
19043+ { &read_config_read_octet_string_const, "", 1, -1, NULL, 0 },
19044+ { &read_config_read_octet_string_const, "0x0", 1, -1, NULL, 1 },
19045+ { &read_config_read_octet_string_const, "0x0 0", 1, -1, NULL, 1 },
19046+
19047+ { &read_config_read_octet_string_const, "0x010002", 1, -1, NULL, 0 },
19048+ { &read_config_read_octet_string_const, "0x010002", 2, -1, NULL, 0 },
19049+ { &read_config_read_octet_string_const, "0x010002", 3, -1, obuf1, 0 },
19050+ { &read_config_read_octet_string_const, "0x010002", 4, -1, obuf1, 3 },
19051+ { &read_config_read_octet_string_const, "0x010002 0", 4, 9, obuf1, 3 },
19052+ { &read_config_read_octet_string_const, "0x010002", 0, -1, obuf1, 3 },
19053+
19054+ { &read_config_read_octet_string_const, "abc", 1, -1, NULL, 0 },
19055+ { &read_config_read_octet_string_const, "abc z", 1, 4, NULL, 0 },
19056+ { &read_config_read_octet_string_const, "abc", 2, -1, NULL, 1 },
19057+ { &read_config_read_octet_string_const, "abc", 3, -1, obuf2, 2 },
19058+ { &read_config_read_octet_string_const, "abc", 4, -1, obuf2, 3 },
19059+ { &read_config_read_octet_string_const, "abc z", 4, 4, obuf2, 3 },
19060+ { &read_config_read_octet_string_const, "abc", 0, -1, obuf2, 3 },
19061+};
19062+
19063+unsigned int i, j, ok;
19064+
19065+for (i = 0; i < sizeof(test_input) / sizeof(test_input[0]); i++) {
19066+ const struct read_config_testcase *const p = &test_input[i];
19067+ size_t len = p->obuf_len;
19068+ u_char *str = len > 0 ? malloc(len) : NULL;
19069+ const char *result;
19070+ size_t offset;
19071+
19072+ fflush(stdout);
19073+ result = (p->pf) (p->readfrom, &str, &len);
19074+ offset = result ? result - p->readfrom : -1;
19075+ OKF(offset == p->expected_offset,
19076+ ("test %d: expected offset %zd, got offset %" NETSNMP_PRIz "d",
19077+ i, p->expected_offset, offset));
19078+ if (offset == p->expected_offset) {
19079+ OKF(len == p->expected_len,
19080+ ("test %d: expected length %" NETSNMP_PRIz "d, got length %"
19081+ NETSNMP_PRIz "d", i, p->expected_len, len));
19082+ if (len == p->expected_len) {
19083+ ok = len < 0 || !p->expected_output
19084+ || memcmp(str, p->expected_output, len) == 0
19085+ || p->expected_output[len] != 0;
19086+ OKF(ok, ("test %d: output buffer mismatch", i));
19087+ if (!ok) {
19088+ printf("Expected: ");
19089+ for (j = 0; j < p->expected_len; ++j)
19090+ printf("%02x ", p->expected_output[j]);
19091+ printf("\nActual: ");
19092+ for (j = 0; j < len; ++j)
19093+ printf("%02x ", str[j]);
19094+ printf("\n");
19095+ }
19096+ }
19097+ }
19098+
19099+ if (str)
19100+ free(str);
19101+}
19102diff --git a/testing/fulltests/unit-tests/T017strtoull_clib.c b/testing/fulltests/unit-tests/T017strtoull_clib.c
19103new file mode 100644
19104index 0000000..4ab9cad
19105--- /dev/null
19106+++ b/testing/fulltests/unit-tests/T017strtoull_clib.c
19107@@ -0,0 +1,94 @@
19108+/* HEADER Testing strtoull(). */
19109+
19110+#ifdef HAVE_STRTOULL
19111+
19112+OK(1, "Skipping strtoull() test because using strtoull() from C library.\n");;
19113+
19114+#else
19115+
19116+/*
19117+ * UINT64_C: C99 macro for the suffix for uint64_t constants.
19118+ */
19119+#ifndef UINT64_C
19120+#ifdef _MSC_VER
19121+#define UINT64_C(c) c##ui64
19122+#else
19123+#define UINT64_C(c) c##ULL
19124+#endif
19125+#endif
19126+
19127+/*
19128+ * According to the C99 standard, the constant ULLONG_MAX must be defined in
19129+ * <limits.h>. Define it here for pre-C99 compilers.
19130+ */
19131+#ifndef ULLONG_MAX
19132+#define ULLONG_MAX UINT64_C(0xffffffffffffffff)
19133+#endif
19134+
19135+#ifndef PRIu64
19136+#ifdef _MSC_VER
19137+#define PRIu64 "I64u"
19138+#else
19139+#define PRIu64 "llu"
19140+#endif
19141+#endif
19142+
19143+struct strtoull_testcase {
19144+ /*
19145+ * inputs
19146+ */
19147+ const char *nptr;
19148+ int base;
19149+ /*
19150+ * expected outputs
19151+ */
19152+ int expected_errno;
19153+ int expected_end;
19154+ uint64_t expected_result;
19155+};
19156+
19157+static const struct strtoull_testcase test_input[] = {
19158+ {"0x0", 0, 0, 3, 0},
19159+ {"1", 0, 0, 1, 1},
19160+ {"0x1", 0, 0, 3, 1},
19161+ {" -0666", 0, 0, 7, -0666},
19162+ {" -0x666", 0, 0, 8, -0x666},
19163+ {"18446744073709551614", 0, 0, 20, UINT64_C(0xfffffffffffffffe)},
19164+ {"0xfffffffffffffffe", 0, 0, 18, UINT64_C(0xfffffffffffffffe)},
19165+ {"18446744073709551615", 0, 0, 20, UINT64_C(0xffffffffffffffff)},
19166+ {"0xffffffffffffffff", 0, 0, 18, UINT64_C(0xffffffffffffffff)},
19167+ {"18446744073709551616", 0, ERANGE, 20, UINT64_C(0xffffffffffffffff)},
19168+ {"0x10000000000000000", 0, ERANGE, 19, UINT64_C(0xffffffffffffffff)},
19169+ {"ff", 16, 0, 2, 255},
19170+ {"0xff", 16, 0, 4, 255},
19171+ {" ", 0, 0, 0, 0},
19172+ {"0x", 0, 0, 1, 0},
19173+ {"0x", 8, 0, 1, 0},
19174+ {"0x", 16, 0, 1, 0},
19175+ {"zyyy", 0, 0, 0, 0},
19176+ {"0xfffffffffffffffff", 0, ERANGE, 19, ULLONG_MAX},
19177+ {"0xfffffffffffffffffz", 0, ERANGE, 19, ULLONG_MAX}
19178+};
19179+
19180+unsigned int i;
19181+
19182+for (i = 0; i < sizeof(test_input) / sizeof(test_input[0]); i++) {
19183+ const struct strtoull_testcase *const p = &test_input[i];
19184+ char *endptr;
19185+ uint64_t result;
19186+
19187+ errno = 0;
19188+ result = strtoull(p->nptr, &endptr, p->base);
19189+ OKF(errno == p->expected_errno,
19190+ ("test %d (input \"%s\"): expected errno %d, got errno %d",
19191+ i, p->nptr, p->expected_errno, errno));
19192+ OKF(result == p->expected_result,
19193+ ("test %d (input \"%s\"): expected result %" PRIu64
19194+ ", got result %" PRIu64,
19195+ i, p->nptr, p->expected_result, result));
19196+ OKF(endptr - p->nptr == p->expected_end,
19197+ ("test %d (input \"%s\"): expected end %d, got end %d",
19198+ i, p->nptr, p->expected_end, (int) (endptr - p->nptr)));
19199+}
19200+
19201+#endif
19202diff --git a/testing/fulltests/unit-tests/T102pdu_build_clib.c b/testing/fulltests/unit-tests/T102pdu_build_clib.c
19203index 088a282..1fba69e 100644
19204--- a/testing/fulltests/unit-tests/T102pdu_build_clib.c
19205+++ b/testing/fulltests/unit-tests/T102pdu_build_clib.c
19206@@ -1,4 +1,7 @@
19207 /* HEADER PDU building */
19208+
19209+SOCK_STARTUP;
19210+
19211 netsnmp_pdu *pdu;
19212 u_char *packet;
19213 size_t packet_len, offset = 0;
19214@@ -60,3 +63,5 @@ rc = snmp_build(&packet, &packet_len, &offset, ss, pdu);
19215
19216 OKF((rc == SNMPERR_SUCCESS),
19217 ("Building an INFORM PDU/packet should have succeed: %d", rc));
19218+
19219+SOCK_CLEANUP;
19220diff --git a/win32/encode_keychange/encode_keychange.dsp b/win32/encode_keychange/encode_keychange.dsp
19221index 5e19366..5a252f5 100644
19222--- a/win32/encode_keychange/encode_keychange.dsp
19223+++ b/win32/encode_keychange/encode_keychange.dsp
19224@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19225 # ADD BSC32 /nologo
19226 LINK32=link.exe
19227 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19228-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/encode_keychange.exe" /libpath:"../lib/release"
19229+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/encode_keychange.exe" /libpath:"../lib/release"
19230
19231 !ELSEIF "$(CFG)" == "encode_keychange - Win32 Debug"
19232
19233@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19234 # ADD BSC32 /nologo
19235 LINK32=link.exe
19236 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19237-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/encode_keychange.exe" /pdbtype:sept /libpath:"../lib/debug"
19238+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/encode_keychange.exe" /pdbtype:sept /libpath:"../lib/debug"
19239
19240 !ENDIF
19241
19242diff --git a/win32/libsnmp/Makefile.in b/win32/libsnmp/Makefile.in
19243index 382b329..98d83c8 100644
19244--- a/win32/libsnmp/Makefile.in
19245+++ b/win32/libsnmp/Makefile.in
19246@@ -66,6 +66,7 @@ LIB32_OBJS= \
19247 "$(INTDIR)\snmp_version.obj" \
19248 "$(INTDIR)\snmpusm.obj" \
19249 "$(INTDIR)\snmpv3.obj" \
19250+ "$(INTDIR)\strlcat.obj" \
19251 "$(INTDIR)\strlcpy.obj" \
19252 "$(INTDIR)\strtok_r.obj" \
19253 "$(INTDIR)\strtoull.obj" \
19254@@ -468,6 +469,12 @@ SOURCE=..\..\snmplib\snmpv3.c
19255 $(CPP) $(CPP_PROJ) $(SOURCE)
19256
19257
19258+SOURCE=..\..\snmplib\strlcat.c
19259+
19260+"$(INTDIR)\strlcat.obj" : $(SOURCE) "$(INTDIR)"
19261+ $(CPP) $(CPP_PROJ) $(SOURCE)
19262+
19263+
19264 SOURCE=..\..\snmplib\strlcpy.c
19265
19266 "$(INTDIR)\strlcpy.obj" : $(SOURCE) "$(INTDIR)"
19267diff --git a/win32/libsnmp/libsnmp.dsp b/win32/libsnmp/libsnmp.dsp
19268index 7a34939..2386331 100644
19269--- a/win32/libsnmp/libsnmp.dsp
19270+++ b/win32/libsnmp/libsnmp.dsp
19271@@ -313,6 +313,10 @@ SOURCE=..\..\snmplib\snmpv3.c
19272 # End Source File
19273 # Begin Source File
19274
19275+SOURCE=..\..\snmplib\strlcat.c
19276+# End Source File
19277+# Begin Source File
19278+
19279 SOURCE=..\..\snmplib\strlcpy.c
19280 # End Source File
19281 # Begin Source File
19282diff --git a/win32/libsnmp_dll/Makefile.in b/win32/libsnmp_dll/Makefile.in
19283index 31279f3..42235d2 100644
19284--- a/win32/libsnmp_dll/Makefile.in
19285+++ b/win32/libsnmp_dll/Makefile.in
19286@@ -67,6 +67,7 @@ LINK32_OBJS= \
19287 "$(INTDIR)\snmp_version.obj" \
19288 "$(INTDIR)\snmpusm.obj" \
19289 "$(INTDIR)\snmpv3.obj" \
19290+ "$(INTDIR)\strlcat.obj" \
19291 "$(INTDIR)\strlcpy.obj" \
19292 "$(INTDIR)\strtok_r.obj" \
19293 "$(INTDIR)\strtoull.obj" \
19294@@ -484,6 +485,12 @@ SOURCE=..\..\snmplib\snmpv3.c
19295 $(CPP) $(CPP_PROJ) $(SOURCE)
19296
19297
19298+SOURCE=..\..\snmplib\strlcat.c
19299+
19300+"$(INTDIR)\strlcat.obj" : $(SOURCE) "$(INTDIR)"
19301+ $(CPP) $(CPP_PROJ) $(SOURCE)
19302+
19303+
19304 SOURCE=..\..\snmplib\strlcpy.c
19305
19306 "$(INTDIR)\strlcpy.obj" : $(SOURCE) "$(INTDIR)"
19307diff --git a/win32/libsnmp_dll/libsnmp_dll.dsp b/win32/libsnmp_dll/libsnmp_dll.dsp
19308index 098c3b9..12c0414 100644
19309--- a/win32/libsnmp_dll/libsnmp_dll.dsp
19310+++ b/win32/libsnmp_dll/libsnmp_dll.dsp
19311@@ -320,6 +320,10 @@ SOURCE=..\..\snmplib\snmpv3.c
19312 # End Source File
19313 # Begin Source File
19314
19315+SOURCE=..\..\snmplib\strlcat.c
19316+# End Source File
19317+# Begin Source File
19318+
19319 SOURCE=..\..\snmplib\strlcpy.c
19320 # End Source File
19321 # Begin Source File
19322diff --git a/win32/mib_module_includes.h b/win32/mib_module_includes.h
19323index 18a9281..014ade0 100644
19324--- a/win32/mib_module_includes.h
19325+++ b/win32/mib_module_includes.h
19326@@ -73,7 +73,6 @@
19327 #include "mibgroup/agent/extend.h"
19328 #include "mibgroup/ucd-snmp/errormib.h"
19329 #include "mibgroup/ucd-snmp/file.h"
19330-#include "mibgroup/ucd-snmp/dlmod.h"
19331 #include "mibgroup/ucd-snmp/proxy.h"
19332 #endif
19333
19334diff --git a/win32/mib_module_inits.h b/win32/mib_module_inits.h
19335index 875fcb9..a4b39bc 100644
19336--- a/win32/mib_module_inits.h
19337+++ b/win32/mib_module_inits.h
19338@@ -34,7 +34,6 @@
19339 if (should_init("extend")) init_extend();
19340 if (should_init("errormib")) init_errormib();
19341 if (should_init("file")) init_file();
19342- if (should_init("dlmod")) init_dlmod();
19343 if (should_init("proxy")) init_proxy();
19344 #endif
19345 if (should_init("snmpEngine")) init_snmpEngine();
19346diff --git a/win32/net-snmp/net-snmp-config.h b/win32/net-snmp/net-snmp-config.h
19347index da3c031..f63a83f 100644
19348--- a/win32/net-snmp/net-snmp-config.h
19349+++ b/win32/net-snmp/net-snmp-config.h
19350@@ -22,7 +22,9 @@
19351 * When compiling with the MSVC workspace, this must be set manually.
19352 * See the PACKAGE_VERSION variable in Unix /configure script
19353 */
19354+#ifndef PACKAGE_VERSION
19355 #define PACKAGE_VERSION "unknown"
19356+#endif
19357
19358 /* Define HAVE_WIN32_PLATFORM_SDK if you have:
19359 * Microsoft Visual Studio MSVC 6.0 and the Platform SDK (PSDK)
19360@@ -60,7 +62,7 @@
19361
19362 /* default list of mibs to load */
19363
19364-#define NETSNMP_DEFAULT_MIBS "IP-MIB;IF-MIB;TCP-MIB;UDP-MIB;HOST-RESOURCES-MIB;SNMPv2-MIB;RFC1213-MIB;NOTIFICATION-LOG-MIB;UCD-SNMP-MIB;UCD-DEMO-MIB;SNMP-TARGET-MIB;NET-SNMP-AGENT-MIB;DISMAN-EVENT-MIB;SNMP-VIEW-BASED-ACM-MIB;SNMP-COMMUNITY-MIB;UCD-DLMOD-MIB;SNMP-FRAMEWORK-MIB;SNMP-MPD-MIB;SNMP-USER-BASED-SM-MIB;SNMP-NOTIFICATION-MIB;SNMPv2-TM"
19365+#define NETSNMP_DEFAULT_MIBS "IP-MIB;IF-MIB;TCP-MIB;UDP-MIB;HOST-RESOURCES-MIB;SNMPv2-MIB;RFC1213-MIB;NOTIFICATION-LOG-MIB;UCD-SNMP-MIB;UCD-DEMO-MIB;SNMP-TARGET-MIB;NET-SNMP-AGENT-MIB;DISMAN-EVENT-MIB;SNMP-VIEW-BASED-ACM-MIB;SNMP-COMMUNITY-MIB;SNMP-FRAMEWORK-MIB;SNMP-MPD-MIB;SNMP-USER-BASED-SM-MIB;SNMP-NOTIFICATION-MIB;SNMPv2-TM"
19366
19367 /* default location to look for mibs to load using the above tokens
19368 and/or those in the MIBS envrionment variable*/
19369@@ -944,13 +946,17 @@
19370 /* #undef PACKAGE_BUGREPORT */
19371
19372 /* Define to the full name of this package. */
19373+#ifndef PACKAGE_NAME
19374 #define PACKAGE_NAME "Net-SNMP"
19375+#endif
19376
19377 /* Define to the full name and version of this package. */
19378 /* #undef PACKAGE_STRING */
19379
19380 /* Define to the one symbol short name of this package. */
19381+#ifndef PACKAGE_TARNAME
19382 #define PACKAGE_TARNAME "net-snmp"
19383+#endif
19384
19385 /* Define to the version of this package. */
19386 /* #undef PACKAGE_VERSION */
19387@@ -1358,6 +1364,12 @@
19388 /* Define to 1 if you have the <openssl/aes.h> header file. */
19389 #define HAVE_OPENSSL_AES_H 1
19390
19391+/* Define to 1 if you have the `EVP_MD_CTX_create' function. */
19392+#define HAVE_EVP_MD_CTX_CREATE 1
19393+
19394+/* Define to 1 if you have the `EVP_MD_CTX_destroy' function. */
19395+#define HAVE_EVP_MD_CTX_DESTROY 1
19396+
19397 /* Define to 1 if you have the `AES_cfb128_encrypt' function. */
19398 #define HAVE_AES_CFB128_ENCRYPT 1
19399
19400@@ -1570,15 +1582,14 @@ typedef unsigned short mode_t;
19401 #ifndef HAVE_STDINT_H
19402 typedef unsigned char uint8_t;
19403 typedef char int8_t;
19404-typedef unsigned short uint16_t;
19405-typedef short int16_t;
19406+typedef unsigned __int16 uint16_t;
19407+typedef __int16 int16_t;
19408 typedef unsigned __int32 uint32_t;
19409-typedef long int32_t;
19410+typedef __int32 int32_t;
19411 typedef unsigned __int64 uint64_t;
19412 typedef __int64 int64_t;
19413 typedef unsigned __int64 uintmax_t;
19414 typedef __int64 intmax_t;
19415-typedef unsigned short uint16_t;
19416 #else /* HAVE_STDINT_H */
19417 #include <stdint.h>
19418 #endif /* HAVE_STDINT_H */
19419@@ -1663,9 +1674,9 @@ enum {
19420 #endif /* NETSNMP_USE_DLL */
19421
19422 /* MSVC OpenSSL linker settings. */
19423-#if defined(WIN32) && !defined(mingw32)
19424+#if defined(_MSC_VER)
19425 # if defined(NETSNMP_USE_OPENSSL)
19426-# ifdef NETSNMP_USE_DLL
19427+# ifdef _DLL
19428 # ifdef _DEBUG
19429 # pragma comment(lib, "libeay32MDd.lib")
19430 # else
19431@@ -1679,6 +1690,7 @@ enum {
19432 # endif
19433 # endif
19434 # pragma comment(lib, "gdi32.lib")
19435+# pragma comment(lib, "user32.lib")
19436 # endif
19437 #endif
19438
19439diff --git a/win32/net-snmp/net-snmp-config.h.in b/win32/net-snmp/net-snmp-config.h.in
19440index 7101702..005e4f9 100644
19441--- a/win32/net-snmp/net-snmp-config.h.in
19442+++ b/win32/net-snmp/net-snmp-config.h.in
19443@@ -22,7 +22,9 @@
19444 * When compiling with the MSVC workspace, this must be set manually.
19445 * See the PACKAGE_VERSION variable in Unix /configure script
19446 */
19447+#ifndef PACKAGE_VERSION
19448 #define PACKAGE_VERSION "unknown"
19449+#endif
19450
19451 /* Define HAVE_WIN32_PLATFORM_SDK if you have:
19452 * Microsoft Visual Studio MSVC 6.0 and the Platform SDK (PSDK)
19453@@ -60,7 +62,7 @@
19454
19455 /* default list of mibs to load */
19456
19457-#define NETSNMP_DEFAULT_MIBS "IP-MIB;IF-MIB;TCP-MIB;UDP-MIB;HOST-RESOURCES-MIB;SNMPv2-MIB;RFC1213-MIB;NOTIFICATION-LOG-MIB;UCD-SNMP-MIB;UCD-DEMO-MIB;SNMP-TARGET-MIB;NET-SNMP-AGENT-MIB;DISMAN-EVENT-MIB;SNMP-VIEW-BASED-ACM-MIB;SNMP-COMMUNITY-MIB;UCD-DLMOD-MIB;SNMP-FRAMEWORK-MIB;SNMP-MPD-MIB;SNMP-USER-BASED-SM-MIB;SNMP-NOTIFICATION-MIB;SNMPv2-TM"
19458+#define NETSNMP_DEFAULT_MIBS "IP-MIB;IF-MIB;TCP-MIB;UDP-MIB;HOST-RESOURCES-MIB;SNMPv2-MIB;RFC1213-MIB;NOTIFICATION-LOG-MIB;UCD-SNMP-MIB;UCD-DEMO-MIB;SNMP-TARGET-MIB;NET-SNMP-AGENT-MIB;DISMAN-EVENT-MIB;SNMP-VIEW-BASED-ACM-MIB;SNMP-COMMUNITY-MIB;SNMP-FRAMEWORK-MIB;SNMP-MPD-MIB;SNMP-USER-BASED-SM-MIB;SNMP-NOTIFICATION-MIB;SNMPv2-TM"
19459
19460 /* default location to look for mibs to load using the above tokens
19461 and/or those in the MIBS envrionment variable*/
19462@@ -944,13 +946,17 @@
19463 /* #undef PACKAGE_BUGREPORT */
19464
19465 /* Define to the full name of this package. */
19466+#ifndef PACKAGE_NAME
19467 #define PACKAGE_NAME "Net-SNMP"
19468+#endif
19469
19470 /* Define to the full name and version of this package. */
19471 /* #undef PACKAGE_STRING */
19472
19473 /* Define to the one symbol short name of this package. */
19474+#ifndef PACKAGE_TARNAME
19475 #define PACKAGE_TARNAME "net-snmp"
19476+#endif
19477
19478 /* Define to the version of this package. */
19479 /* #undef PACKAGE_VERSION */
19480@@ -1358,6 +1364,12 @@
19481 /* Define to 1 if you have the <openssl/aes.h> header file. */
19482 #define HAVE_OPENSSL_AES_H 1
19483
19484+/* Define to 1 if you have the `EVP_MD_CTX_create' function. */
19485+#define HAVE_EVP_MD_CTX_CREATE 1
19486+
19487+/* Define to 1 if you have the `EVP_MD_CTX_destroy' function. */
19488+#define HAVE_EVP_MD_CTX_DESTROY 1
19489+
19490 /* Define to 1 if you have the `AES_cfb128_encrypt' function. */
19491 #define HAVE_AES_CFB128_ENCRYPT 1
19492
19493@@ -1570,15 +1582,14 @@ typedef unsigned short mode_t;
19494 #ifndef HAVE_STDINT_H
19495 typedef unsigned char uint8_t;
19496 typedef char int8_t;
19497-typedef unsigned short uint16_t;
19498-typedef short int16_t;
19499+typedef unsigned __int16 uint16_t;
19500+typedef __int16 int16_t;
19501 typedef unsigned __int32 uint32_t;
19502-typedef long int32_t;
19503+typedef __int32 int32_t;
19504 typedef unsigned __int64 uint64_t;
19505 typedef __int64 int64_t;
19506 typedef unsigned __int64 uintmax_t;
19507 typedef __int64 intmax_t;
19508-typedef unsigned short uint16_t;
19509 #else /* HAVE_STDINT_H */
19510 #include <stdint.h>
19511 #endif /* HAVE_STDINT_H */
19512@@ -1663,9 +1674,9 @@ enum {
19513 #endif /* NETSNMP_USE_DLL */
19514
19515 /* MSVC OpenSSL linker settings. */
19516-#if defined(WIN32) && !defined(mingw32)
19517+#if defined(_MSC_VER)
19518 # if defined(NETSNMP_USE_OPENSSL)
19519-# ifdef NETSNMP_USE_DLL
19520+# ifdef _DLL
19521 # ifdef _DEBUG
19522 # pragma comment(lib, "libeay32MDd.lib")
19523 # else
19524@@ -1679,6 +1690,7 @@ enum {
19525 # endif
19526 # endif
19527 # pragma comment(lib, "gdi32.lib")
19528+# pragma comment(lib, "user32.lib")
19529 # endif
19530 #endif
19531
19532diff --git a/win32/netsnmpmibs/Makefile.in b/win32/netsnmpmibs/Makefile.in
19533index ed44162..44d0203 100644
19534--- a/win32/netsnmpmibs/Makefile.in
19535+++ b/win32/netsnmpmibs/Makefile.in
19536@@ -85,13 +85,13 @@ LIB32_OBJS1= \
19537 "$(INTDIR)\mteTriggerThresholdTable.obj" \
19538 "$(INTDIR)\example.obj" \
19539 "$(INTDIR)\ucdDemoPublic.obj" \
19540- "$(INTDIR)\dlmod.obj" \
19541 "$(INTDIR)\errormib.obj" \
19542 "$(INTDIR)\extensible.obj" \
19543 "$(INTDIR)\file.obj"
19544 LIB32_OBJS2= \
19545 "$(INTDIR)\loadave.obj" \
19546 "$(INTDIR)\pass.obj" \
19547+ "$(INTDIR)\pass_common.obj" \
19548 "$(INTDIR)\pass_persist.obj" \
19549 "$(INTDIR)\proc.obj" \
19550 "$(INTDIR)\proxy.obj" \
19551@@ -314,12 +314,6 @@ SOURCE=..\..\agent\mibgroup\examples\ucdDemoPublic.c
19552 $(CPP) $(CPP_PROJ) $(SOURCE)
19553
19554
19555-SOURCE="..\..\agent\mibgroup\ucd-snmp\dlmod.c"
19556-
19557-"$(INTDIR)\dlmod.obj" : $(SOURCE) "$(INTDIR)"
19558- $(CPP) $(CPP_PROJ) $(SOURCE)
19559-
19560-
19561 SOURCE="..\..\agent\mibgroup\ucd-snmp\errormib.c"
19562
19563 "$(INTDIR)\errormib.obj" : $(SOURCE) "$(INTDIR)"
19564@@ -350,6 +344,12 @@ SOURCE="..\..\agent\mibgroup\ucd-snmp\pass.c"
19565 $(CPP) $(CPP_PROJ) $(SOURCE)
19566
19567
19568+SOURCE="..\..\agent\mibgroup\ucd-snmp\pass_common.c"
19569+
19570+"$(INTDIR)\pass_common.obj" : $(SOURCE) "$(INTDIR)"
19571+ $(CPP) $(CPP_PROJ) $(SOURCE)
19572+
19573+
19574 SOURCE="..\..\agent\mibgroup\ucd-snmp\pass_persist.c"
19575
19576 "$(INTDIR)\pass_persist.obj" : $(SOURCE) "$(INTDIR)"
19577diff --git a/win32/netsnmpmibs/netsnmpmibs.dsp b/win32/netsnmpmibs/netsnmpmibs.dsp
19578index 5c88b97..9034eed 100644
19579--- a/win32/netsnmpmibs/netsnmpmibs.dsp
19580+++ b/win32/netsnmpmibs/netsnmpmibs.dsp
19581@@ -245,10 +245,6 @@ SOURCE=..\..\agent\mibgroup\examples\ucdDemoPublic.c
19582 # PROP Default_Filter ""
19583 # Begin Source File
19584
19585-SOURCE="..\..\agent\mibgroup\ucd-snmp\dlmod.c"
19586-# End Source File
19587-# Begin Source File
19588-
19589 SOURCE="..\..\agent\mibgroup\ucd-snmp\errormib.c"
19590 # End Source File
19591 # Begin Source File
19592@@ -269,6 +265,10 @@ SOURCE="..\..\agent\mibgroup\ucd-snmp\pass.c"
19593 # End Source File
19594 # Begin Source File
19595
19596+SOURCE="..\..\agent\mibgroup\ucd-snmp\pass_common.c"
19597+# End Source File
19598+# Begin Source File
19599+
19600 SOURCE="..\..\agent\mibgroup\ucd-snmp\pass_persist.c"
19601 # End Source File
19602 # Begin Source File
19603diff --git a/win32/snmpbulkget/snmpbulkget.dsp b/win32/snmpbulkget/snmpbulkget.dsp
19604index fe5e5ae..39599db 100644
19605--- a/win32/snmpbulkget/snmpbulkget.dsp
19606+++ b/win32/snmpbulkget/snmpbulkget.dsp
19607@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19608 # ADD BSC32 /nologo
19609 LINK32=link.exe
19610 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19611-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpbulkget.exe" /libpath:"../lib/release"
19612+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpbulkget.exe" /libpath:"../lib/release"
19613
19614 !ELSEIF "$(CFG)" == "snmpbulkget - Win32 Debug"
19615
19616@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19617 # ADD BSC32 /nologo
19618 LINK32=link.exe
19619 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19620-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpbulkget.exe" /pdbtype:sept /libpath:"../lib/debug"
19621+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpbulkget.exe" /pdbtype:sept /libpath:"../lib/debug"
19622
19623 !ENDIF
19624
19625diff --git a/win32/snmpbulkwalk/snmpbulkwalk.dsp b/win32/snmpbulkwalk/snmpbulkwalk.dsp
19626index ea8bb0c..91e94d3 100644
19627--- a/win32/snmpbulkwalk/snmpbulkwalk.dsp
19628+++ b/win32/snmpbulkwalk/snmpbulkwalk.dsp
19629@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19630 # ADD BSC32 /nologo
19631 LINK32=link.exe
19632 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19633-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpbulkwalk.exe" /libpath:"../lib/release"
19634+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpbulkwalk.exe" /libpath:"../lib/release"
19635
19636 !ELSEIF "$(CFG)" == "snmpbulkwalk - Win32 Debug"
19637
19638@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19639 # ADD BSC32 /nologo
19640 LINK32=link.exe
19641 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19642-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpbulkwalk.exe" /pdbtype:sept /libpath:"../lib/debug"
19643+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpbulkwalk.exe" /pdbtype:sept /libpath:"../lib/debug"
19644
19645 !ENDIF
19646
19647diff --git a/win32/snmpd/snmpd.dsp b/win32/snmpd/snmpd.dsp
19648index 5534306..45e2cad 100644
19649--- a/win32/snmpd/snmpd.dsp
19650+++ b/win32/snmpd/snmpd.dsp
19651@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19652 # ADD BSC32 /nologo
19653 LINK32=link.exe
19654 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19655-# ADD LINK32 netsnmp.lib netsnmpagent.lib netsnmpmibs.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpd.exe" /libpath:"../lib/release"
19656+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpd.exe" /libpath:"../lib/release"
19657
19658 !ELSEIF "$(CFG)" == "snmpd - Win32 Debug"
19659
19660@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19661 # ADD BSC32 /nologo
19662 LINK32=link.exe
19663 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19664-# ADD LINK32 netsnmp.lib netsnmpagent.lib netsnmpmibs.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpd.exe" /pdbtype:sept /libpath:"../lib/debug"
19665+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpd.exe" /pdbtype:sept /libpath:"../lib/debug"
19666
19667 !ENDIF
19668
19669diff --git a/win32/snmpdelta/snmpdelta.dsp b/win32/snmpdelta/snmpdelta.dsp
19670index b17b822..7f5a5d3 100644
19671--- a/win32/snmpdelta/snmpdelta.dsp
19672+++ b/win32/snmpdelta/snmpdelta.dsp
19673@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19674 # ADD BSC32 /nologo
19675 LINK32=link.exe
19676 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19677-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpdelta.exe" /libpath:"../lib/release"
19678+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpdelta.exe" /libpath:"../lib/release"
19679
19680 !ELSEIF "$(CFG)" == "snmpdelta - Win32 Debug"
19681
19682@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19683 # ADD BSC32 /nologo
19684 LINK32=link.exe
19685 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19686-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpdelta.exe" /pdbtype:sept /libpath:"../lib/debug"
19687+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpdelta.exe" /pdbtype:sept /libpath:"../lib/debug"
19688
19689 !ENDIF
19690
19691diff --git a/win32/snmpdf/snmpdf.dsp b/win32/snmpdf/snmpdf.dsp
19692index 88c3f6d..e2e4b94 100644
19693--- a/win32/snmpdf/snmpdf.dsp
19694+++ b/win32/snmpdf/snmpdf.dsp
19695@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19696 # ADD BSC32 /nologo
19697 LINK32=link.exe
19698 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19699-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpdf.exe" /libpath:"../lib/release"
19700+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpdf.exe" /libpath:"../lib/release"
19701
19702 !ELSEIF "$(CFG)" == "snmpdf - Win32 Debug"
19703
19704@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19705 # ADD BSC32 /nologo
19706 LINK32=link.exe
19707 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19708-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpdf.exe" /pdbtype:sept /libpath:"../lib/debug"
19709+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpdf.exe" /pdbtype:sept /libpath:"../lib/debug"
19710
19711 !ENDIF
19712
19713diff --git a/win32/snmpget/snmpget.dsp b/win32/snmpget/snmpget.dsp
19714index 64980ed..0603232 100644
19715--- a/win32/snmpget/snmpget.dsp
19716+++ b/win32/snmpget/snmpget.dsp
19717@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19718 # ADD BSC32 /nologo
19719 LINK32=link.exe
19720 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19721-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpget.exe" /libpath:"../lib/release"
19722+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpget.exe" /libpath:"../lib/release"
19723
19724 !ELSEIF "$(CFG)" == "snmpget - Win32 Debug"
19725
19726@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19727 # ADD BSC32 /nologo
19728 LINK32=link.exe
19729 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19730-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpget.exe" /pdbtype:sept /libpath:"../lib/debug"
19731+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpget.exe" /pdbtype:sept /libpath:"../lib/debug"
19732
19733 !ENDIF
19734
19735diff --git a/win32/snmpgetnext/snmpgetnext.dsp b/win32/snmpgetnext/snmpgetnext.dsp
19736index 233199d..cb63c84 100644
19737--- a/win32/snmpgetnext/snmpgetnext.dsp
19738+++ b/win32/snmpgetnext/snmpgetnext.dsp
19739@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19740 # ADD BSC32 /nologo
19741 LINK32=link.exe
19742 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19743-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpgetnext.exe" /libpath:"../lib/release"
19744+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpgetnext.exe" /libpath:"../lib/release"
19745
19746 !ELSEIF "$(CFG)" == "snmpgetnext - Win32 Debug"
19747
19748@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19749 # ADD BSC32 /nologo
19750 LINK32=link.exe
19751 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19752-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpgetnext.exe" /pdbtype:sept /libpath:"../lib/debug"
19753+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpgetnext.exe" /pdbtype:sept /libpath:"../lib/debug"
19754
19755 !ENDIF
19756
19757diff --git a/win32/snmpnetstat/snmpnetstat.dsp b/win32/snmpnetstat/snmpnetstat.dsp
19758index 25ec031..35dd7e8 100644
19759--- a/win32/snmpnetstat/snmpnetstat.dsp
19760+++ b/win32/snmpnetstat/snmpnetstat.dsp
19761@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19762 # ADD BSC32 /nologo
19763 LINK32=link.exe
19764 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19765-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpnetstat.exe" /libpath:"../lib/release"
19766+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpnetstat.exe" /libpath:"../lib/release"
19767
19768 !ELSEIF "$(CFG)" == "snmpnetstat - Win32 Debug"
19769
19770@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19771 # ADD BSC32 /nologo
19772 LINK32=link.exe
19773 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19774-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpnetstat.exe" /pdbtype:sept /libpath:"../lib/debug"
19775+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpnetstat.exe" /pdbtype:sept /libpath:"../lib/debug"
19776
19777 !ENDIF
19778
19779diff --git a/win32/snmpset/snmpset.dsp b/win32/snmpset/snmpset.dsp
19780index fdeca30..ad0f509 100644
19781--- a/win32/snmpset/snmpset.dsp
19782+++ b/win32/snmpset/snmpset.dsp
19783@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19784 # ADD BSC32 /nologo
19785 LINK32=link.exe
19786 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19787-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpset.exe" /libpath:"../lib/release"
19788+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpset.exe" /libpath:"../lib/release"
19789
19790 !ELSEIF "$(CFG)" == "snmpset - Win32 Debug"
19791
19792@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19793 # ADD BSC32 /nologo
19794 LINK32=link.exe
19795 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19796-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpset.exe" /pdbtype:sept /libpath:"../lib/debug"
19797+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpset.exe" /pdbtype:sept /libpath:"../lib/debug"
19798
19799 !ENDIF
19800
19801diff --git a/win32/snmpstatus/snmpstatus.dsp b/win32/snmpstatus/snmpstatus.dsp
19802index 1b68373..e6a4100 100644
19803--- a/win32/snmpstatus/snmpstatus.dsp
19804+++ b/win32/snmpstatus/snmpstatus.dsp
19805@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19806 # ADD BSC32 /nologo
19807 LINK32=link.exe
19808 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19809-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpstatus.exe" /libpath:"../lib/release"
19810+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpstatus.exe" /libpath:"../lib/release"
19811
19812 !ELSEIF "$(CFG)" == "snmpstatus - Win32 Debug"
19813
19814@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19815 # ADD BSC32 /nologo
19816 LINK32=link.exe
19817 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19818-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpstatus.exe" /pdbtype:sept /libpath:"../lib/debug"
19819+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpstatus.exe" /pdbtype:sept /libpath:"../lib/debug"
19820
19821 !ENDIF
19822
19823diff --git a/win32/snmptable/snmptable.dsp b/win32/snmptable/snmptable.dsp
19824index 75f964f..1dfc138 100644
19825--- a/win32/snmptable/snmptable.dsp
19826+++ b/win32/snmptable/snmptable.dsp
19827@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19828 # ADD BSC32 /nologo
19829 LINK32=link.exe
19830 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19831-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmptable.exe" /libpath:"../lib/release"
19832+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmptable.exe" /libpath:"../lib/release"
19833
19834 !ELSEIF "$(CFG)" == "snmptable - Win32 Debug"
19835
19836@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19837 # ADD BSC32 /nologo
19838 LINK32=link.exe
19839 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19840-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmptable.exe" /pdbtype:sept /libpath:"../lib/debug"
19841+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmptable.exe" /pdbtype:sept /libpath:"../lib/debug"
19842
19843 !ENDIF
19844
19845diff --git a/win32/snmptest/snmptest.dsp b/win32/snmptest/snmptest.dsp
19846index dfb0cf1..89c08e9 100644
19847--- a/win32/snmptest/snmptest.dsp
19848+++ b/win32/snmptest/snmptest.dsp
19849@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19850 # ADD BSC32 /nologo
19851 LINK32=link.exe
19852 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19853-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmptest.exe" /libpath:"../lib/release"
19854+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmptest.exe" /libpath:"../lib/release"
19855
19856 !ELSEIF "$(CFG)" == "snmptest - Win32 Debug"
19857
19858@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19859 # ADD BSC32 /nologo
19860 LINK32=link.exe
19861 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19862-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmptest.exe" /pdbtype:sept /libpath:"../lib/debug"
19863+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmptest.exe" /pdbtype:sept /libpath:"../lib/debug"
19864
19865 !ENDIF
19866
19867diff --git a/win32/snmptranslate/snmptranslate.dsp b/win32/snmptranslate/snmptranslate.dsp
19868index a3ebde5..c3eca02 100644
19869--- a/win32/snmptranslate/snmptranslate.dsp
19870+++ b/win32/snmptranslate/snmptranslate.dsp
19871@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19872 # ADD BSC32 /nologo
19873 LINK32=link.exe
19874 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19875-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmptranslate.exe" /libpath:"../lib/release"
19876+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmptranslate.exe" /libpath:"../lib/release"
19877
19878 !ELSEIF "$(CFG)" == "snmptranslate - Win32 Debug"
19879
19880@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19881 # ADD BSC32 /nologo
19882 LINK32=link.exe
19883 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19884-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmptranslate.exe" /pdbtype:sept /libpath:"../lib/debug"
19885+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmptranslate.exe" /pdbtype:sept /libpath:"../lib/debug"
19886
19887 !ENDIF
19888
19889diff --git a/win32/snmptrap/snmptrap.dsp b/win32/snmptrap/snmptrap.dsp
19890index 8d27ee1..c34ffd8 100644
19891--- a/win32/snmptrap/snmptrap.dsp
19892+++ b/win32/snmptrap/snmptrap.dsp
19893@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19894 # ADD BSC32 /nologo
19895 LINK32=link.exe
19896 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19897-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmptrap.exe" /libpath:"../lib/release"
19898+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmptrap.exe" /libpath:"../lib/release"
19899
19900 !ELSEIF "$(CFG)" == "snmptrap - Win32 Debug"
19901
19902@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19903 # ADD BSC32 /nologo
19904 LINK32=link.exe
19905 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19906-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmptrap.exe" /pdbtype:sept /libpath:"../lib/debug"
19907+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmptrap.exe" /pdbtype:sept /libpath:"../lib/debug"
19908
19909 !ENDIF
19910
19911diff --git a/win32/snmptrapd/snmptrapd.dsp b/win32/snmptrapd/snmptrapd.dsp
19912index 503918a..9f49389 100644
19913--- a/win32/snmptrapd/snmptrapd.dsp
19914+++ b/win32/snmptrapd/snmptrapd.dsp
19915@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19916 # ADD BSC32 /nologo
19917 LINK32=link.exe
19918 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19919-# ADD LINK32 netsnmp.lib netsnmpagent.lib netsnmpmibs.lib netsnmptrapd.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmptrapd.exe" /libpath:"../lib/release"
19920+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmptrapd.exe" /libpath:"../lib/release"
19921
19922 !ELSEIF "$(CFG)" == "snmptrapd - Win32 Debug"
19923
19924@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19925 # ADD BSC32 /nologo
19926 LINK32=link.exe
19927 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19928-# ADD LINK32 netsnmp.lib netsnmpagent.lib netsnmpmibs.lib netsnmptrapd.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmptrapd.exe" /pdbtype:sept /libpath:"../lib/debug"
19929+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmptrapd.exe" /pdbtype:sept /libpath:"../lib/debug"
19930
19931 !ENDIF
19932
19933diff --git a/win32/snmpusm/snmpusm.dsp b/win32/snmpusm/snmpusm.dsp
19934index db43f2e..a1c0124 100644
19935--- a/win32/snmpusm/snmpusm.dsp
19936+++ b/win32/snmpusm/snmpusm.dsp
19937@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19938 # ADD BSC32 /nologo
19939 LINK32=link.exe
19940 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19941-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpusm.exe" /libpath:"../lib/release"
19942+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpusm.exe" /libpath:"../lib/release"
19943
19944 !ELSEIF "$(CFG)" == "snmpusm - Win32 Debug"
19945
19946@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19947 # ADD BSC32 /nologo
19948 LINK32=link.exe
19949 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19950-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpusm.exe" /pdbtype:sept /libpath:"../lib/debug"
19951+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpusm.exe" /pdbtype:sept /libpath:"../lib/debug"
19952
19953 !ENDIF
19954
19955diff --git a/win32/snmpvacm/snmpvacm.dsp b/win32/snmpvacm/snmpvacm.dsp
19956index 0856832..2fd53fd 100644
19957--- a/win32/snmpvacm/snmpvacm.dsp
19958+++ b/win32/snmpvacm/snmpvacm.dsp
19959@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19960 # ADD BSC32 /nologo
19961 LINK32=link.exe
19962 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19963-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpvacm.exe" /libpath:"../lib/release"
19964+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpvacm.exe" /libpath:"../lib/release"
19965
19966 !ELSEIF "$(CFG)" == "snmpvacm - Win32 Debug"
19967
19968@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19969 # ADD BSC32 /nologo
19970 LINK32=link.exe
19971 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19972-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpvacm.exe" /pdbtype:sept /libpath:"../lib/debug"
19973+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpvacm.exe" /pdbtype:sept /libpath:"../lib/debug"
19974
19975 !ENDIF
19976
19977diff --git a/win32/snmpwalk/snmpwalk.dsp b/win32/snmpwalk/snmpwalk.dsp
19978index 5d81957..67598f1 100644
19979--- a/win32/snmpwalk/snmpwalk.dsp
19980+++ b/win32/snmpwalk/snmpwalk.dsp
19981@@ -50,7 +50,7 @@ BSC32=bscmake.exe
19982 # ADD BSC32 /nologo
19983 LINK32=link.exe
19984 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386
19985-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpwalk.exe" /libpath:"../lib/release"
19986+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../bin/release/snmpwalk.exe" /libpath:"../lib/release"
19987
19988 !ELSEIF "$(CFG)" == "snmpwalk - Win32 Debug"
19989
19990@@ -74,7 +74,7 @@ BSC32=bscmake.exe
19991 # ADD BSC32 /nologo
19992 LINK32=link.exe
19993 # ADD BASE LINK32 kernel32.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
19994-# ADD LINK32 netsnmp.lib advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpwalk.exe" /pdbtype:sept /libpath:"../lib/debug"
19995+# ADD LINK32 advapi32.lib ws2_32.lib kernel32.lib user32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../bin/debug/snmpwalk.exe" /pdbtype:sept /libpath:"../lib/debug"
19996
19997 !ENDIF
19998