From abc042057d9fc237b239948136cb89a4a2ac9a01 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 2 Nov 2014 18:10:55 +0100 Subject: [PATCH] lldpd: use strdup() on arguments that could be changed by lldpcli And add the appropriate "const" modifier for those that don't. The compiler should warn us if we did something wrong. --- src/daemon/lldpd.c | 10 +++++----- src/daemon/lldpd.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 10c5ed79..4ccf4e00 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -1284,9 +1284,9 @@ lldpd_main(int argc, char *argv[], char *envp[]) int ch, debug = 0; #ifdef USE_SNMP int snmp = 0; - char *agentx = NULL; /* AgentX socket */ + const char *agentx = NULL; /* AgentX socket */ #endif - char *ctlname = LLDPD_CTL_SOCKET; + const char *ctlname = LLDPD_CTL_SOCKET; char *mgmtp = NULL; char *cidp = NULL; char *interfaces = NULL; @@ -1353,7 +1353,7 @@ lldpd_main(int argc, char *argv[], char *envp[]) fprintf(stderr, "-m can only be used once\n"); usage(); } - mgmtp = optarg; + mgmtp = strdup(optarg); break; case 'u': if (ctlname) { @@ -1367,14 +1367,14 @@ lldpd_main(int argc, char *argv[], char *envp[]) fprintf(stderr, "-I can only be used once\n"); usage(); } - interfaces = optarg; + interfaces = strdup(optarg); break; case 'C': if (cidp) { fprintf(stderr, "-C can only be used once\n"); usage(); } - cidp = optarg; + cidp = strdup(optarg); break; case 'L': if (strlen(optarg)) lldpcli = optarg; diff --git a/src/daemon/lldpd.h b/src/daemon/lldpd.h index 797623c8..94e16975 100644 --- a/src/daemon/lldpd.h +++ b/src/daemon/lldpd.h @@ -113,7 +113,7 @@ struct lldpd { int g_snmp; struct event *g_snmp_timeout; void *g_snmp_fds; - char *g_snmp_agentx; + const char *g_snmp_agentx; #endif /* USE_SNMP */ /* Unix socket handling */ -- 2.39.5