diff options
author | [anp/hsw] <sysop@880.ru> | 2021-03-13 18:43:15 +0700 |
---|---|---|
committer | [anp/hsw] <sysop@880.ru> | 2021-03-13 18:43:15 +0700 |
commit | c914000971063a4500cfb34f4141dfc3c943368d (patch) | |
tree | f96879e115cd1970435d97f466327b391015757b | |
parent | 49ef6cf969f662c44f4be2b82b101273c8c6de71 (diff) | |
download | accel-ppp-c914000971063a4500cfb34f4141dfc3c943368d.tar.gz accel-ppp-c914000971063a4500cfb34f4141dfc3c943368d.zip |
Fix some errors and warnings found by cppcheck
[accel-pppd/ctrl/ipoe/ipoe.c:4054]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not.
[accel-pppd/logs/log_syslog.c:148]: (error) Array 'facility_name[9]' accessed at index 35, which is out of bounds.
[accel-pppd/lua/session.c:274]: (error) Common realloc mistake: 'mods' nulled but not freed upon failure
[accel-pppd/extra/ippool.c:114]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'int *'.
[accel-pppd/extra/ippool.c:114]: (warning) %u in format string (no. 2) requires 'unsigned int *' but the argument type is 'int *'.
[accel-pppd/extra/ippool.c:114]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'int *'.
[accel-pppd/extra/ippool.c:114]: (warning) %u in format string (no. 4) requires 'unsigned int *' but the argument type is 'int *'.
[accel-pppd/extra/ippool.c:114]: (warning) %u in format string (no. 5) requires 'unsigned int *' but the argument type is 'int *'.
[accel-pppd/extra/ippool.c:141]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'int *'.
[accel-pppd/extra/ippool.c:141]: (warning) %u in format string (no. 2) requires 'unsigned int *' but the argument type is 'int *'.
[accel-pppd/extra/ippool.c:141]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'int *'.
[accel-pppd/extra/ippool.c:141]: (warning) %u in format string (no. 4) requires 'unsigned int *' but the argument type is 'int *'.
[accel-pppd/extra/ippool.c:141]: (warning) %u in format string (no. 5) requires 'unsigned int *' but the argument type is 'int *'.
[accel-pppd/main.c:97]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'unsigned int *'.
[accel-pppd/radius/radius.c:687] -> [accel-pppd/radius/radius.c:690]: (warning) Possible null pointer dereference: rpd - otherwise it is redundant to check it against null.
[accel-pppd/radius/serv.c:805] -> [accel-pppd/radius/serv.c:829]: (warning) Possible null pointer dereference: ptr2 - otherwise it is redundant to check it against null.
[accel-pppd/radius/serv.c:813] -> [accel-pppd/radius/serv.c:829]: (warning) Possible null pointer dereference: ptr2 - otherwise it is redundant to check it against null.
[accel-pppd/radius/serv.c:823] -> [accel-pppd/radius/serv.c:829]: (warning) Possible null pointer dereference: ptr2 - otherwise it is redundant to check it against null.
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.c | 2 | ||||
-rw-r--r-- | accel-pppd/extra/ippool.c | 6 | ||||
-rw-r--r-- | accel-pppd/logs/log_syslog.c | 8 | ||||
-rw-r--r-- | accel-pppd/lua/session.c | 12 | ||||
-rw-r--r-- | accel-pppd/main.c | 2 | ||||
-rw-r--r-- | accel-pppd/radius/radius.c | 3 | ||||
-rw-r--r-- | accel-pppd/radius/serv.c | 5 |
7 files changed, 25 insertions, 13 deletions
diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index d91596ae..0649e9c8 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -4051,7 +4051,7 @@ static void load_config(void) opt = conf_get_opt("ipoe", "check-ip"); if (!opt) opt = conf_get_opt("common", "check-ip"); - if (opt && opt >= 0) + if (opt) conf_check_exists = atoi(opt) > 0; #ifdef RADIUS diff --git a/accel-pppd/extra/ippool.c b/accel-pppd/extra/ippool.c index 5e0098ac..2ca8b6f6 100644 --- a/accel-pppd/extra/ippool.c +++ b/accel-pppd/extra/ippool.c @@ -109,7 +109,8 @@ static void parse_gw_ip_address(const char *val) //parses ranges like x.x.x.x/mask static int parse1(const char *str, uint32_t *begin, uint32_t *end) { - int n, f1, f2, f3, f4, m; + int n; + unsigned int f1, f2, f3, f4, m; n = sscanf(str, "%u.%u.%u.%u/%u",&f1, &f2, &f3, &f4, &m); if (n != 5) @@ -136,7 +137,8 @@ static int parse1(const char *str, uint32_t *begin, uint32_t *end) //parses ranges like x.x.x.x-y static int parse2(const char *str, uint32_t *begin, uint32_t *end) { - int n, f1, f2, f3, f4, f5; + int n; + unsigned int f1, f2, f3, f4, f5; n = sscanf(str, "%u.%u.%u.%u-%u",&f1, &f2, &f3, &f4, &f5); if (n != 5) diff --git a/accel-pppd/logs/log_syslog.c b/accel-pppd/logs/log_syslog.c index 562d895f..f06c1cc8 100644 --- a/accel-pppd/logs/log_syslog.c +++ b/accel-pppd/logs/log_syslog.c @@ -138,19 +138,21 @@ static void parse_opt(const char *opt, char **ident, int *facility) int n; const char *facility_name[] = {"daemon", "local0", "local1", "local2", "local3", "local4", "local5", "local6", "local7"}; const int facility_num[] = {LOG_DAEMON, LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7}; + const int facility_total = 9; ptr = strchr(str, ','); if (ptr) { *ptr = 0; n = strtol(ptr + 1, &endptr, 10); if (*endptr) { - for (n = 0; n < sizeof(facility_name); n++) { + for (n = 0; n < facility_total; n++) { if (!strcasecmp(ptr + 1, facility_name[n])) break; } - if (n == sizeof(facility_name)) + if (n == facility_total) { log_emerg("log_syslog: unknown facility name '%s'\n", ptr + 1); - else + *facility = LOG_DAEMON; + } else *facility = facility_num[n]; } else *facility = n; diff --git a/accel-pppd/lua/session.c b/accel-pppd/lua/session.c index bd98911b..131f02f5 100644 --- a/accel-pppd/lua/session.c +++ b/accel-pppd/lua/session.c @@ -268,10 +268,16 @@ static int session_module(lua_State *L) void __export lua_session_module_register(const struct lua_session_module *mod) { + char *mods_new; if (!mods) - mods = malloc(sizeof(void *)); + mods_new = malloc(sizeof(void *)); else - mods = realloc(mods, (mod_cnt + 1) * sizeof(void *)); + mods_new = realloc(mods, (mod_cnt + 1) * sizeof(void *)); - mods[mod_cnt++] = mod; + if (mods_new) { + mods = mods_new; + mods[mod_cnt++] = mod; + } else { + log_emerg("lua: out of memory\n"); + } } diff --git a/accel-pppd/main.c b/accel-pppd/main.c index cb7e1cda..4b52dfcc 100644 --- a/accel-pppd/main.c +++ b/accel-pppd/main.c @@ -94,7 +94,7 @@ static void change_limits(void) f = fopen("/proc/sys/fs/nr_open", "r"); if (f) { - fscanf(f, "%d", &nr_open); + fscanf(f, "%u", &nr_open); fclose(f); } diff --git a/accel-pppd/radius/radius.c b/accel-pppd/radius/radius.c index fd640913..5563c945 100644 --- a/accel-pppd/radius/radius.c +++ b/accel-pppd/radius/radius.c @@ -684,7 +684,6 @@ static void ses_finished(struct ap_session *ses) { struct radius_pd_t *rpd = find_pd(ses); struct ipv6db_addr_t *a; - struct framed_route *fr = rpd->fr; struct framed_ip6_route *fr6; if (!rpd) { @@ -692,6 +691,8 @@ static void ses_finished(struct ap_session *ses) abort(); } + struct framed_route *fr = rpd->fr; + pthread_rwlock_wrlock(&sessions_lock); pthread_mutex_lock(&rpd->lock); list_del(&rpd->entry); diff --git a/accel-pppd/radius/serv.c b/accel-pppd/radius/serv.c index d27d04f8..65af74d3 100644 --- a/accel-pppd/radius/serv.c +++ b/accel-pppd/radius/serv.c @@ -758,6 +758,8 @@ static int parse_server2(const char *_opt, struct rad_server_t *s) goto out; ptr2 = strchr(ptr1 + 1, ','); + if (!ptr2) + goto out; *ptr1 = 0; @@ -826,8 +828,7 @@ static int parse_server2(const char *_opt, struct rad_server_t *s) else s->backup = 0; - if (ptr2) - *ptr2 = 0; + *ptr2 = 0; s->secret = _strdup(ptr1 + 1); |