Skip to content

Commit f5526b1

Browse files
KuzinAndreybvanassche
authored andcommitted
Fix: Add wrapers on const values to use in hosts_ctl()
To prevent compilation warnings in snmp_agent.c and snmptrapd.c about discard 'const' qualifier: snmp_agent.c:1082:29: warning: passing argument 2 of 'hosts_ctl' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 1082 | if (hosts_ctl(name, STRING_UNKNOWN, sbuf, STRING_UNKNOWN)) { | ^~~~~~~~~~~~~~ In file included from snmp_agent.c:94: /usr/include/tcpd.h:131:42: note: expected 'char *' but argument is of type 'const char *' 131 | extern int hosts_ctl(char *daemon, char *client_name, char *client_addr, | ~~~~~~^~~~~~~~~~~ snmp_agent.c:1082:51: warning: passing argument 4 of 'hosts_ctl' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 1082 | if (hosts_ctl(name, STRING_UNKNOWN, sbuf, STRING_UNKNOWN)) { | ^~~~~~~~~~~~~~ /usr/include/tcpd.h:132:23: note: expected 'char *' but argument is of type 'const char *' 132 | char *client_user); | ~~~~~~^~~~~~~~~~~
1 parent 36fc055 commit f5526b1

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

agent/snmp_agent.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,11 @@ netsnmp_agent_check_packet(netsnmp_session * session,
10371037
char *tcpudpaddr = NULL, *name;
10381038
short not_log_connection;
10391039

1040+
/* 'char *' wrapers on 'const char *' STRING_UNKNOWN value for hosts_ctl */
1041+
char name_unknown[sizeof(STRING_UNKNOWN)] = STRING_UNKNOWN;
1042+
char addr_unknown[sizeof(STRING_UNKNOWN)] = STRING_UNKNOWN;
1043+
char user_unknown[sizeof(STRING_UNKNOWN)] = STRING_UNKNOWN;
1044+
10401045
name = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
10411046
NETSNMP_DS_LIB_APPTYPE);
10421047

@@ -1079,7 +1084,7 @@ netsnmp_agent_check_packet(netsnmp_session * session,
10791084
if (xp)
10801085
*xp = '\0';
10811086

1082-
if (hosts_ctl(name, STRING_UNKNOWN, sbuf, STRING_UNKNOWN)) {
1087+
if (hosts_ctl(name, name_unknown, sbuf, user_unknown)) {
10831088
if (!not_log_connection) {
10841089
snmp_log(allow_severity, "Connection from %s\n", addr_string);
10851090
}
@@ -1096,7 +1101,7 @@ netsnmp_agent_check_packet(netsnmp_session * session,
10961101
*/
10971102
if (0 == strncmp(addr_string, "callback", 8))
10981103
;
1099-
else if (hosts_ctl(name, STRING_UNKNOWN, STRING_UNKNOWN, STRING_UNKNOWN)){
1104+
else if (hosts_ctl(name, name_unknown, addr_unknown, user_unknown)){
11001105
if (!not_log_connection) {
11011106
snmp_log(allow_severity, "Connection from <UNKNOWN> (%s)\n", addr_string);
11021107
};

apps/snmptrapd.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ pre_parse(netsnmp_session * session, netsnmp_transport *transport,
284284
{
285285
#ifdef NETSNMP_USE_LIBWRAP
286286
char *addr_string = NULL;
287+
/* 'char *' wrapers on 'const char *' STRING_UNKNOWN value for hosts_ctl */
288+
char name[sizeof("snmptrapd")] = "snmptrapd";
289+
char name_unknown[sizeof(STRING_UNKNOWN)] = STRING_UNKNOWN;
290+
char addr_unknown[sizeof(STRING_UNKNOWN)] = STRING_UNKNOWN;
291+
char user_unknown[sizeof(STRING_UNKNOWN)] = STRING_UNKNOWN;
287292

288293
if (transport != NULL && transport->f_fmtaddr != NULL) {
289294
/*
@@ -308,17 +313,15 @@ pre_parse(netsnmp_session * session, netsnmp_transport *transport,
308313
if (xp)
309314
*xp = '\0';
310315

311-
if (hosts_ctl("snmptrapd", STRING_UNKNOWN,
312-
sbuf, STRING_UNKNOWN) == 0) {
316+
if (hosts_ctl(name, name_unknown, sbuf, user_unknown) == 0) {
313317
DEBUGMSGTL(("snmptrapd:libwrap", "%s rejected", addr_string));
314318
SNMP_FREE(addr_string);
315319
return 0;
316320
}
317321
}
318322
SNMP_FREE(addr_string);
319323
} else {
320-
if (hosts_ctl("snmptrapd", STRING_UNKNOWN,
321-
STRING_UNKNOWN, STRING_UNKNOWN) == 0) {
324+
if (hosts_ctl(name, name_unknown, addr_unknown, user_unknown) == 0) {
322325
DEBUGMSGTL(("snmptrapd:libwrap", "[unknown] rejected"));
323326
return 0;
324327
}

0 commit comments

Comments
 (0)