diff options
author | [anp/hsw] <sysop@880.ru> | 2021-03-20 21:14:59 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-20 19:14:59 +0500 |
commit | 62f7740033f05053a581e864742575a46ccc6da2 (patch) | |
tree | 4ba9bffb1b3ffe1028b1e150b4bd1fee8122097d | |
parent | 5c6cf3e627b95a76ccdd21b956a9e77f05f250d9 (diff) | |
download | accel-ppp-62f7740033f05053a581e864742575a46ccc6da2.tar.gz accel-ppp-62f7740033f05053a581e864742575a46ccc6da2.zip |
Fixed some errors found by valgrind and pvs-studio (#11)
* Fix errors found by valgrind
==12312== Syscall param sendmsg(msg.msg_iov[0]) points to uninitialised byte(s)
==12312== at 0x486CCF0: sendmsg (in /lib/libpthread-2.22.so)
==12312== by 0x12F57F: rtnl_talk (libnetlink.c:316)
==12312== by 0x132DA3: genl_resolve_mcg (genl.c:52)
==12312== by 0x484E1CB: init (vlan_mon.c:528)
==12312== by 0x484CDC0: vlan_mon_register_proto (vlan_mon.c:48)
==12312== by 0x510B763: load_vlan_mon (pppoe.c:1914)
==12312== by 0x510BFF2: load_config (pppoe.c:2064)
==12312== by 0x510C22A: pppoe_init (pppoe.c:2108)
==12312== by 0x483E9EB: triton_load_modules (triton.c:704)
==12312== by 0x1384B2: main (main.c:339)
==12312== Address 0xbedacdd8 is on thread 1's stack
==12312== in frame #2, created by genl_resolve_mcg (genl.c:23)
==12312== 15 bytes in 1 blocks are definitely lost in loss record 352 of 836
==12312== at 0x482A9A9: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==12312== by 0x4B97524: strdup (in /lib/libc-2.22.so)
==12312== by 0x12C30C: init (telnet.c:769)
==12312== by 0x483E9EB: triton_load_modules (triton.c:704)
==12312== by 0x1384B2: main (main.c:339)
==12312==
==12312== 15 bytes in 1 blocks are definitely lost in loss record 353 of 836
==12312== at 0x482A9A9: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==12312== by 0x4B97524: strdup (in /lib/libc-2.22.so)
==12312== by 0x12D60A: init (tcp.c:392)
==12312== by 0x483E9EB: triton_load_modules (triton.c:704)
==12312== by 0x1384B2: main (main.c:339)
* Fix another warnings by cppcheck
[accel-pppd/ctrl/ipoe/arp.c:256]: (error) Uninitialized variable: n
[accel-pppd/ctrl/pppoe/mac_filter.c:90]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:90]: (warning) %x in format string (no. 2) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:90]: (warning) %x in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:90]: (warning) %x in format string (no. 4) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:90]: (warning) %x in format string (no. 5) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:90]: (warning) %x in format string (no. 6) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:129]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:129]: (warning) %x in format string (no. 2) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:129]: (warning) %x in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:129]: (warning) %x in format string (no. 4) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:129]: (warning) %x in format string (no. 5) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:129]: (warning) %x in format string (no. 6) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:158]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:158]: (warning) %x in format string (no. 2) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:158]: (warning) %x in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:158]: (warning) %x in format string (no. 4) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:158]: (warning) %x in format string (no. 5) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/mac_filter.c:158]: (warning) %x in format string (no. 6) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ctrl/pppoe/pppoe.c:738]: (warning) Possible null pointer dereference
[accel-pppd/ipv6/dhcpv6.c:911]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'int *'.
[accel-pppd/ipv6/dhcpv6.c:911]: (warning) %x in format string (no. 2) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ipv6/dhcpv6.c:911]: (warning) %x in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ipv6/dhcpv6.c:911]: (warning) %x in format string (no. 4) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/libnetlink/libnetlink.c:515]: (warning) Possible null pointer dereference
[accel-pppd/ppp/ipv6cp_opt_intfid.c:185]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ppp/ipv6cp_opt_intfid.c:298]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'int *'.
[accel-pppd/ppp/ipv6cp_opt_intfid.c:298]: (warning) %x in format string (no. 2) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ppp/ipv6cp_opt_intfid.c:298]: (warning) %x in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.
[accel-pppd/ppp/ipv6cp_opt_intfid.c:298]: (warning) %x in format string (no. 4) requires 'unsigned int *' but the argument type is 'signed int *'.
* Suppress compiler warnings
* Fix locking errors
/opt/pvs/accel-ppp/accel-pppd/extra/pppd_compat.c 279 warn V1020 The function exited without calling the 'sigchld_unlock' function. Check lines: 279, 249.
/opt/pvs/accel-ppp/accel-pppd/extra/pppd_compat.c 333 warn V1020 The function exited without calling the 'sigchld_unlock' function. Check lines: 333, 315.
/opt/pvs/accel-ppp/accel-pppd/extra/pppd_compat.c 422 warn V1020 The function exited without calling the 'sigchld_unlock' function. Check lines: 422, 372.
/opt/pvs/accel-ppp/accel-pppd/extra/pppd_compat.c 488 warn V1020 The function exited without calling the 'sigchld_unlock' function. Check lines: 488, 468.
/opt/pvs/accel-ppp/accel-pppd/triton/mempool.c 119 warn V1020 The function exited without calling the 'pthread_spin_unlock' function. Check lines: 119, 116.
* Fix array len errors
/opt/pvs/accel-ppp/accel-pppd/triton/conf_file.c 75 warn V557 Array underrun is possible. The value of 'len - 1' index could reach -1.
/opt/pvs/accel-ppp/accel-pppd/triton/conf_file.c 76 warn V557 Array underrun is possible. The value of '-- len' index could reach -1.
* Fix possible memory leaks
/opt/pvs/accel-ppp/accel-pppd/radius/radius.c 936 err V773 The function was exited without releasing the 'str' pointer. A memory leak is possible.
/opt/pvs/accel-ppp/accel-pppd/radius/serv.c 622 err V773 The function was exited without releasing the 'str' pointer. A memory leak is possible.
/opt/pvs/accel-ppp/accel-pppd/triton/conf_file.c 144 err V773 The function was exited without releasing the 'raw' pointer. A memory leak is possible.
* Fix unsafe code
/opt/pvs/accel-ppp/accel-pppd/cli/tcp.c 364 warn V1004 The 'host' pointer was used unsafely after it was verified against nullptr. Check lines: 338, 364.
/opt/pvs/accel-ppp/accel-pppd/cli/telnet.c 701 warn V1004 The 'host' pointer was used unsafely after it was verified against nullptr. Check lines: 675, 701.
/opt/pvs/accel-ppp/accel-pppd/extra/ippool.c 241 err V614 Potentially uninitialized pointer 'pos' used.
/opt/pvs/accel-ppp/accel-pppd/radius/dict.c 165 err V614 Uninitialized pointer 'parent_items' used.
* Remove duplicate code
/opt/pvs/accel-ppp/accel-pppd/radius/serv.c 202 warn V547 Expression 'ts.tv_sec < req->serv->fail_time' is always false.
* Fix treating signed bool variables as unsigned
* Add nullptr checking
/opt/pvs/accel-ppp/accel-pppd/ipv6/dhcpv6.c 886 err V595 The 'opt->val' pointer was utilized before it was verified against nullptr. Check lines: 886, 890.
/opt/pvs/accel-ppp/accel-pppd/ipv6/nd.c 479 err V595 The 'opt->val' pointer was utilized before it was verified against nullptr. Check lines: 479, 483.
/opt/pvs/accel-ppp/accel-pppd/radius/auth.c 152 err V595 The 'rpd->auth_ctx' pointer was utilized before it was verified against nullptr. Check lines: 152, 154.
/opt/pvs/accel-ppp/accel-pppd/triton/conf_file.c 114 err V595 The 'cur_sect' pointer was utilized before it was verified against nullptr. Check lines: 114, 117.
* Add logging of exit conditions
* Clarify calculation
[accel-pppd/ppp/ccp_mppe.c:281]: (style) Clarify calculation precedence for '&' and '?'.
[accel-pppd/ppp/ccp_mppe.c:282]: (style) Clarify calculation precedence for '&' and '?'.
[accel-pppd/ppp/ccp_mppe.c:283]: (style) Clarify calculation precedence for '&' and '?'.
[accel-pppd/ppp/ccp_mppe.c:284]: (style) Clarify calculation precedence for '&' and '?'.
[accel-pppd/ppp/ccp_mppe.c:285]: (style) Clarify calculation precedence for '&' and '?'.
[accel-pppd/ppp/ccp_mppe.c:286]: (style) Clarify calculation precedence for '&' and '?'.
[drivers/ipoe/ipoe.c:307]: (style) Clarify calculation precedence for '&' and '?'.
* Fix void calculations
[accel-pppd/ctrl/pppoe/disc.c:211]: (portability) 'pkt' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/ctrl/pptp/pptp.c:150]: (portability) 'buf' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/radius/acct.c:37]: (portability) 'req.pack.buf' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/radius/auth.c:35]: (portability) 'req.pack.buf' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/radius/auth.c:79]: (portability) 'req.pack.buf' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/radius/dm_coa.c:43]: (portability) 'pack.buf' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/radius/dm_coa.c:47]: (portability) 'pack.buf' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/radius/dm_coa.c:57]: (portability) 'pack.buf' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/radius/dm_coa.c:65]: (portability) 'req.buf' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/radius/dm_coa.c:97]: (portability) 'req.buf' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/radius/serv.c:364]: (portability) 'req.pack.buf' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/triton/mempool.c:115]: (portability) 'mmap_ptr' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/triton/mempool.c:122]: (portability) 'mmap_ptr' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/triton/mempool.c:276]: (portability) 'ptr' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
* Fix void part 2
[accel-pppd/ipv6/dhcpv6.c:844]: (portability) 'conf_dnssl' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/ipv6/nd.c:199]: (portability) '(void*)dnsslinfo' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[accel-pppd/ipv6/nd.c:432]: (portability) 'conf_dnssl' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
* Fix null pointer dereference
[accel-pppd/ctrl/ipoe/ipoe.c:2048]: (warning) Possible null pointer dereference: eth
[accel-pppd/ctrl/ipoe/ipoe.c:2049]: (warning) Possible null pointer dereference: iph
* Remove redundant check
/opt/pvs/accel-ppp/accel-pppd/ctrl/l2tp/packet.c 656 warn V547 Expression 'attr->length <= 16' is always false.
* PR fixes
* PR fixes 2
52 files changed, 186 insertions, 152 deletions
diff --git a/accel-pppd/auth/auth_chap_md5.c b/accel-pppd/auth/auth_chap_md5.c index 87d5eda..c0d78c8 100644 --- a/accel-pppd/auth/auth_chap_md5.c +++ b/accel-pppd/auth/auth_chap_md5.c @@ -73,7 +73,7 @@ struct chap_auth_data { int failure; char *name; char *mschap_error; - int started:1; + unsigned int started:1; }; static void chap_send_challenge(struct chap_auth_data *ad, int new); diff --git a/accel-pppd/auth/auth_mschap_v1.c b/accel-pppd/auth/auth_mschap_v1.c index a55082e..bddaabf 100644 --- a/accel-pppd/auth/auth_mschap_v1.c +++ b/accel-pppd/auth/auth_mschap_v1.c @@ -72,7 +72,7 @@ struct chap_auth_data { int failure; char *name; char *mschap_error; - int started:1; + unsigned int started:1; }; static void chap_send_challenge(struct chap_auth_data *ad, int new); diff --git a/accel-pppd/auth/auth_mschap_v2.c b/accel-pppd/auth/auth_mschap_v2.c index 635cb28..3e94450 100644 --- a/accel-pppd/auth/auth_mschap_v2.c +++ b/accel-pppd/auth/auth_mschap_v2.c @@ -75,7 +75,7 @@ struct chap_auth_data { char *mschap_error; char *reply_msg; int failure; - int started:1; + unsigned int started:1; }; static void chap_send_challenge(struct chap_auth_data *ad, int new); diff --git a/accel-pppd/auth/auth_pap.c b/accel-pppd/auth/auth_pap.c index 7becc47..4092101 100644 --- a/accel-pppd/auth/auth_pap.c +++ b/accel-pppd/auth/auth_pap.c @@ -42,7 +42,7 @@ struct pap_auth_data { struct triton_timer_t timeout; char *peer_id; int req_id; - int started:1; + unsigned int started:1; }; struct pap_hdr { diff --git a/accel-pppd/backup/backup.h b/accel-pppd/backup/backup.h index 106303e..d50ec55 100644 --- a/accel-pppd/backup/backup.h +++ b/accel-pppd/backup/backup.h @@ -40,7 +40,7 @@ struct backup_data struct ap_session *ses; struct backup_storage *storage; struct list_head mod_list; - int internal:1; + unsigned int internal:1; }; struct backup_module diff --git a/accel-pppd/cli/tcp.c b/accel-pppd/cli/tcp.c index 87633cb..8952661 100644 --- a/accel-pppd/cli/tcp.c +++ b/accel-pppd/cli/tcp.c @@ -30,8 +30,8 @@ struct tcp_client_t { uint8_t *cmdline; int xmit_pos; int recv_pos; - int auth:1; - int disconnect:1; + unsigned int auth:1; + unsigned int disconnect:1; }; struct buffer_t { @@ -357,10 +357,6 @@ static void start_server(const char *host, int port) return; } - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - addr.sin_addr.s_addr = inet_addr(host); - triton_context_register(&serv_ctx, NULL); triton_context_set_priority(&serv_ctx, 0); triton_md_register_handler(&serv_ctx, &serv_hnd); @@ -407,6 +403,7 @@ static void init(void) triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); + free(host); return; err_fmt: log_emerg("cli: tcp: invalid format\n"); diff --git a/accel-pppd/cli/telnet.c b/accel-pppd/cli/telnet.c index 4ea1839..7d5009c 100644 --- a/accel-pppd/cli/telnet.c +++ b/accel-pppd/cli/telnet.c @@ -47,11 +47,11 @@ struct telnet_client_t { int cmdline_pos; int cmdline_pos2; int cmdline_len; - int auth:1; - int echo:1; - int telcmd:1; - int esc:1; - int disconnect:1; + unsigned int auth:1; + unsigned int echo:1; + unsigned int telcmd:1; + unsigned int esc:1; + unsigned int disconnect:1; }; struct buffer_t { @@ -694,10 +694,6 @@ static void start_server(const char *host, int port) return; } - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - addr.sin_addr.s_addr = inet_addr(host); - triton_context_register(&serv_ctx, NULL); triton_context_set_priority(&serv_ctx, 0); triton_md_register_handler(&serv_ctx, &serv_hnd); @@ -793,6 +789,7 @@ static void init(void) triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); + free(host); return; err_fmt: log_emerg("cli: telnet: invalid format\n"); diff --git a/accel-pppd/ctrl/ipoe/arp.c b/accel-pppd/ctrl/ipoe/arp.c index 1979c76..4f9669b 100644 --- a/accel-pppd/ctrl/ipoe/arp.c +++ b/accel-pppd/ctrl/ipoe/arp.c @@ -231,7 +231,7 @@ static int arp_read(struct triton_md_handler_t *h) void *arpd_start(struct ipoe_serv *ipoe) { struct rb_node **p, *parent = NULL; - struct arp_node *n; + struct arp_node *n = NULL; struct arp_tree *t; int fd, ifindex = ipoe->ifindex, i; char fname[1024]; diff --git a/accel-pppd/ctrl/ipoe/ipoe.h b/accel-pppd/ctrl/ipoe/ipoe.h index 7c585a2..933a2c9 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.h +++ b/accel-pppd/ctrl/ipoe/ipoe.h @@ -59,17 +59,17 @@ struct ipoe_serv { char *opt_lua_username_func; #endif int opt_weight; - int opt_shared:1; - int opt_dhcpv4:1; - int opt_up:1; - int opt_auto:1; - int opt_ifcfg:1; - int opt_nat:1; - int opt_ipv6:1; - int opt_ip_unnumbered:1; - int need_close:1; - int active:1; - int vlan_mon:1; + unsigned int opt_shared:1; + unsigned int opt_dhcpv4:1; + unsigned int opt_up:1; + unsigned int opt_auto:1; + unsigned int opt_ifcfg:1; + unsigned int opt_nat:1; + unsigned int opt_ipv6:1; + unsigned int opt_ip_unnumbered:1; + unsigned int need_close:1; + unsigned int active:1; + unsigned int vlan_mon:1; }; struct ipoe_session { @@ -110,15 +110,15 @@ struct ipoe_session { #ifdef RADIUS struct rad_plugin_t radius; #endif - int started:1; - int terminating:1; - int dhcp_addr:1; - int relay_addr:1; - int l4_redirect:1; - int l4_redirect_set:1; - int terminate:1; - int UP:1; - int wait_start:1; + unsigned int started:1; + unsigned int terminating:1; + unsigned int dhcp_addr:1; + unsigned int relay_addr:1; + unsigned int l4_redirect:1; + unsigned int l4_redirect_set:1; + unsigned int terminate:1; + unsigned int UP:1; + unsigned int wait_start:1; }; struct ipoe_session_info { diff --git a/accel-pppd/ctrl/l2tp/dict.c b/accel-pppd/ctrl/l2tp/dict.c index b636c87..4e4378d 100644 --- a/accel-pppd/ctrl/l2tp/dict.c +++ b/accel-pppd/ctrl/l2tp/dict.c @@ -266,8 +266,10 @@ static void dict_init(void) if (!opt) opt = DICTIONARY; - if (l2tp_dict_load(opt)) + if (l2tp_dict_load(opt)) { + log_emerg("l2tp:dict_init:l2tp_dict_load: failed\n"); _exit(EXIT_FAILURE); + } } DEFINE_INIT(20, dict_init); diff --git a/accel-pppd/ctrl/l2tp/l2tp.h b/accel-pppd/ctrl/l2tp/l2tp.h index 12a2dbf..76de867 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.h +++ b/accel-pppd/ctrl/l2tp/l2tp.h @@ -55,8 +55,8 @@ struct l2tp_attr_t { struct list_head entry; struct l2tp_dict_attr_t *attr; - int M:1; - int H:1; + unsigned int M:1; + unsigned int H:1; int length; l2tp_value_t val; }; diff --git a/accel-pppd/ctrl/pppoe/disc.c b/accel-pppd/ctrl/pppoe/disc.c index b1119eb..8a82e1d 100644 --- a/accel-pppd/ctrl/pppoe/disc.c +++ b/accel-pppd/ctrl/pppoe/disc.c @@ -202,7 +202,7 @@ void pppoe_disc_stop(struct pppoe_serv_t *serv) free_net(n); } -static int forward(struct disc_net *net, int ifindex, void *pkt, int len) +static int forward(struct disc_net *net, int ifindex, uint8_t *pkt, int len) { struct pppoe_serv_t *n; struct tree *t = &net->tree[ifindex & HASH_BITS]; diff --git a/accel-pppd/ctrl/pppoe/mac_filter.c b/accel-pppd/ctrl/pppoe/mac_filter.c index d1e104e..ba78df6 100644 --- a/accel-pppd/ctrl/pppoe/mac_filter.c +++ b/accel-pppd/ctrl/pppoe/mac_filter.c @@ -52,7 +52,7 @@ static int mac_filter_load(const char *opt) char *c; char *name = _strdup(opt); char *buf = _malloc(1024); - int n[ETH_ALEN]; + unsigned int n[ETH_ALEN]; int i, line = 0; c = strstr(name, ","); @@ -122,7 +122,7 @@ err: static void mac_filter_add(const char *addr, void *client) { - int n[ETH_ALEN]; + unsigned int n[ETH_ALEN]; struct mac_t *mac; int i; @@ -149,7 +149,7 @@ static void mac_filter_add(const char *addr, void *client) static void mac_filter_del(const char *addr, void *client) { - int n[ETH_ALEN]; + unsigned int n[ETH_ALEN]; uint8_t a[ETH_ALEN]; struct mac_t *mac; int i; diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c index 6d87649..18aac8b 100644 --- a/accel-pppd/ctrl/pppoe/pppoe.c +++ b/accel-pppd/ctrl/pppoe/pppoe.c @@ -46,7 +46,7 @@ struct pppoe_conn_t { struct pppoe_serv_t *serv; uint16_t sid; uint8_t addr[ETH_ALEN]; - int ppp_started:1; + unsigned int ppp_started:1; struct pppoe_tag *relay_sid; struct pppoe_tag *host_uniq; @@ -735,7 +735,8 @@ static int add_tag(uint8_t *pack, size_t pack_size, int type, const void *data, tag->tag_type = htons(type); tag->tag_len = htons(len); - memcpy(tag->tag_data, data, len); + if (data && len) + memcpy(tag->tag_data, data, len); hdr->length = htons(ntohs(hdr->length) + sizeof(*tag) + len); return 0; diff --git a/accel-pppd/ctrl/pppoe/pppoe.h b/accel-pppd/ctrl/pppoe/pppoe.h index 1ea7b07..7ba4ac6 100644 --- a/accel-pppd/ctrl/pppoe/pppoe.h +++ b/accel-pppd/ctrl/pppoe/pppoe.h @@ -97,8 +97,8 @@ struct pppoe_serv_t int padi_limit; time_t last_padi_limit_warn; - int stopping:1; - int vlan_mon:1; + unsigned int stopping:1; + unsigned int vlan_mon:1; }; extern int conf_verbose; diff --git a/accel-pppd/ctrl/pptp/pptp.c b/accel-pppd/ctrl/pptp/pptp.c index 881fa9a..a5bcaca 100644 --- a/accel-pppd/ctrl/pptp/pptp.c +++ b/accel-pppd/ctrl/pptp/pptp.c @@ -147,7 +147,7 @@ again: } if ( n<size ) { - memcpy(conn->out_buf, buf + n, size - n); + memcpy(conn->out_buf, (uint8_t *)buf + n, size - n); triton_md_enable_handler(&conn->hnd, MD_MODE_WRITE); } diff --git a/accel-pppd/ctrl/sstp/sstp.c b/accel-pppd/ctrl/sstp/sstp.c index 8c4e55d..4b15400 100644 --- a/accel-pppd/ctrl/sstp/sstp.c +++ b/accel-pppd/ctrl/sstp/sstp.c @@ -128,7 +128,7 @@ struct sstp_conn_t { int hello_sent; int hello_interval; -// int bypass_auth:1; +// unsigned int bypass_auth:1; // char *http_cookie; uint8_t *nonce; uint8_t *hlak_key; diff --git a/accel-pppd/extra/ippool.c b/accel-pppd/extra/ippool.c index 2ca8b6f..00f22f1 100644 --- a/accel-pppd/extra/ippool.c +++ b/accel-pppd/extra/ippool.c @@ -206,7 +206,7 @@ static void generate_pool_p2p(struct ippool_t *p) struct ippool_item_t *it; struct ipaddr_t *addr = NULL; struct ipaddr_t *peer_addr; - struct list_head *pos, *pos1 = p->tunnel_list.next, *pos2 = p->tunnel_list.prev; + struct list_head *pos = NULL, *pos1 = p->tunnel_list.next, *pos2 = p->tunnel_list.prev; uint8_t r, t = 0; while (1) { diff --git a/accel-pppd/extra/pppd_compat.c b/accel-pppd/extra/pppd_compat.c index 421c598..663e545 100644 --- a/accel-pppd/extra/pppd_compat.c +++ b/accel-pppd/extra/pppd_compat.c @@ -56,9 +56,9 @@ struct pppd_compat_pd struct sigchld_handler_t ip_up_hnd; #ifdef RADIUS char *tmp_fname; - int radattr_saved:1; + unsigned int radattr_saved:1; #endif - int started:1; + unsigned int started:1; int res; in_addr_t ipv4_addr; in_addr_t ipv4_peer_addr; diff --git a/accel-pppd/include/ap_session.h b/accel-pppd/include/ap_session.h index 2af2f04..a48b860 100644 --- a/accel-pppd/include/ap_session.h +++ b/accel-pppd/include/ap_session.h @@ -51,8 +51,8 @@ struct ap_ctrl { int mppe; char *calling_station_id; char *called_station_id; - int dont_ifcfg:1; - int ppp:1; + unsigned int dont_ifcfg:1; + unsigned int ppp:1; int ppp_npmode:2; void (*started)(struct ap_session*); void (*finished)(struct ap_session *); @@ -98,9 +98,9 @@ struct ap_session struct triton_context_t *wakeup; - int terminating:1; - int terminated:1; - int down:1; + unsigned int terminating:1; + unsigned int terminated:1; + unsigned int down:1; int terminate_cause; struct list_head pd_list; diff --git a/accel-pppd/ipdb.h b/accel-pppd/ipdb.h index 2565c92..6ec9163 100644 --- a/accel-pppd/ipdb.h +++ b/accel-pppd/ipdb.h @@ -17,9 +17,9 @@ struct ipv6db_addr_t struct list_head entry; struct in6_addr addr; int prefix_len; - int flag_onlink:1; - int flag_auto:1; - int installed:1; + unsigned int flag_onlink:1; + unsigned int flag_auto:1; + unsigned int installed:1; }; struct ipv6db_item_t diff --git a/accel-pppd/ipv6/dhcpv6.c b/accel-pppd/ipv6/dhcpv6.c index 471e0a0..cc7f1f3 100644 --- a/accel-pppd/ipv6/dhcpv6.c +++ b/accel-pppd/ipv6/dhcpv6.c @@ -43,7 +43,7 @@ static int conf_route_via_gw = 1; static struct in6_addr conf_dns[MAX_DNS_COUNT]; static int conf_dns_count; -static void *conf_dnssl; +static uint8_t *conf_dnssl; static int conf_dnssl_size; struct dhcpv6_pd { @@ -53,7 +53,7 @@ struct dhcpv6_pd { struct dhcpv6_opt_clientid *clientid; uint32_t addr_iaid; uint32_t dp_iaid; - int dp_active:1; + unsigned int dp_active:1; }; static void *pd_key; @@ -908,14 +908,14 @@ static uint64_t parse_serverid(const char *opt) uint16_t u16[4]; } __packed u; - int n[4]; + unsigned int n[4]; int i; if (sscanf(opt, "%x:%x:%x:%x", &n[0], &n[1], &n[2], &n[3]) != 4) goto err; for (i = 0; i < 4; i++) { - if (n[i] < 0 || n[i] > 0xffff) + if (n[i] > 0xffff) goto err; u.u16[i] = htons(n[i]); } diff --git a/accel-pppd/ipv6/dhcpv6.h b/accel-pppd/ipv6/dhcpv6.h index 669155a..32ee715 100644 --- a/accel-pppd/ipv6/dhcpv6.h +++ b/accel-pppd/ipv6/dhcpv6.h @@ -182,7 +182,7 @@ struct dhcpv6_packet { struct list_head relay_list; - int rapid_commit:1; + unsigned int rapid_commit:1; struct list_head opt_list; void *endptr; diff --git a/accel-pppd/ipv6/nd.c b/accel-pppd/ipv6/nd.c index a4233b5..943ed6d 100644 --- a/accel-pppd/ipv6/nd.c +++ b/accel-pppd/ipv6/nd.c @@ -28,7 +28,7 @@ static int conf_init_ra_interval = 3; static int conf_rdnss_lifetime; static struct in6_addr conf_dns[MAX_DNS_COUNT]; static int conf_dns_count; -static void *conf_dnssl; +static uint8_t *conf_dnssl; static int conf_dnssl_size; static int conf_MaxRtrAdvInterval = 600; @@ -196,7 +196,7 @@ static void ipv6_nd_send_ra(struct ipv6_nd_handler_t *h, struct sockaddr_in6 *ds dnsslinfo->nd_opt_dnssli_lifetime = htonl(conf_rdnss_lifetime); memcpy(dnsslinfo->nd_opt_dnssli, conf_dnssl, conf_dnssl_size); memset(dnsslinfo->nd_opt_dnssli + conf_dnssl_size, 0, (dnsslinfo->nd_opt_dnssli_len - 1) * 8 - conf_dnssl_size); - endptr = (void *)dnsslinfo + dnsslinfo->nd_opt_dnssli_len * 8; + endptr = (uint8_t *)dnsslinfo + dnsslinfo->nd_opt_dnssli_len * 8; } else endptr = rdnss_addr; diff --git a/accel-pppd/libnetlink/genl.c b/accel-pppd/libnetlink/genl.c index b8cb2fc..0c75807 100644 --- a/accel-pppd/libnetlink/genl.c +++ b/accel-pppd/libnetlink/genl.c @@ -39,6 +39,7 @@ int __export genl_resolve_mcg(const char *family, const char *name, int *fam_id) return -1; } + memset(&req, 0, sizeof(req)); nlh = &req.n; nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; diff --git a/accel-pppd/libnetlink/libnetlink.c b/accel-pppd/libnetlink/libnetlink.c index aca16af..0ab83a3 100644 --- a/accel-pppd/libnetlink/libnetlink.c +++ b/accel-pppd/libnetlink/libnetlink.c @@ -512,7 +512,8 @@ int __export addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *dat rta = NLMSG_TAIL(n); rta->rta_type = type; rta->rta_len = len; - memcpy(RTA_DATA(rta), data, alen); + if (data && alen) + memcpy(RTA_DATA(rta), data, alen); n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len); return 0; } diff --git a/accel-pppd/log.c b/accel-pppd/log.c index 3105e57..e4a1e6e 100644 --- a/accel-pppd/log.c +++ b/accel-pppd/log.c @@ -33,7 +33,7 @@ struct log_pd_t struct ap_session *ses; struct list_head msgs; struct log_msg_t *msg; - int authorized:1; + unsigned int authorized:1; }; struct _log_msg_t diff --git a/accel-pppd/logs/log_file.c b/accel-pppd/logs/log_file.c index 6eafd42..216ff5a 100644 --- a/accel-pppd/logs/log_file.c +++ b/accel-pppd/logs/log_file.c @@ -31,8 +31,8 @@ struct log_file_t { struct list_head entry; struct list_head msgs; spinlock_t lock; - int need_free:1; - int queued:1; + unsigned int need_free:1; + unsigned int queued:1; struct log_file_pd_t *lpd; int fd; @@ -669,6 +669,7 @@ static void init(void) memset(log_file, 0, sizeof(*log_file)); log_file_init(log_file); if (log_file_open(log_file, opt)) { + log_emerg("log_file:init:log_file_open: failed\n"); free(log_file); _exit(EXIT_FAILURE); } @@ -680,6 +681,7 @@ static void init(void) memset(fail_log_file, 0, sizeof(*fail_log_file)); log_file_init(fail_log_file); if (log_file_open(fail_log_file, opt)) { + log_emerg("log_file:init:log_file_open: failed\n"); free(fail_log_file); _exit(EXIT_FAILURE); } diff --git a/accel-pppd/logs/log_tcp.c b/accel-pppd/logs/log_tcp.c index 85edf70..ad508e4 100644 --- a/accel-pppd/logs/log_tcp.c +++ b/accel-pppd/logs/log_tcp.c @@ -30,8 +30,8 @@ struct tcp_target_t spinlock_t lock; struct list_head queue; int queue_len; - int connected:1; - int wait:1; + unsigned int connected:1; + unsigned int wait:1; }; static int conf_connect_interval = 5; diff --git a/accel-pppd/lua/session.c b/accel-pppd/lua/session.c index 131f02f..a6ce2b0 100644 --- a/accel-pppd/lua/session.c +++ b/accel-pppd/lua/session.c @@ -12,6 +12,8 @@ #include "utils.h" #include "luasupp.h" +#include "log.h" + static int mod_cnt; static const struct lua_session_module **mods; @@ -268,7 +270,7 @@ static int session_module(lua_State *L) void __export lua_session_module_register(const struct lua_session_module *mod) { - char *mods_new; + void *mods_new; if (!mods) mods_new = malloc(sizeof(void *)); else diff --git a/accel-pppd/main.c b/accel-pppd/main.c index c8e5104..4af14f0 100644 --- a/accel-pppd/main.c +++ b/accel-pppd/main.c @@ -202,16 +202,20 @@ static void sigsegv(int num) printf("starting gdb...\n"); sprintf(dump, "dump-%u", t); fd = open(dump, O_CREAT|O_TRUNC|O_WRONLY,0600); - if (fd == -1) + if (fd == -1) { + log_emerg("main: sigsegv: open failed: %s\n", strerror(errno)); _exit(0); + } dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); close(fd); f = fopen(cmd, "w"); - if (!f) + if (!f) { + log_emerg("main: sigsegv: open failed: %s\n", strerror(errno)); _exit(0); + } fprintf(f, "info shared\nthread apply all bt full\ngenerate-core-file core-%u\ndetach\nquit\n", t); fclose(f); @@ -353,8 +357,10 @@ int main(int _argc, char **_argv) srandom(time(NULL)); - if (triton_init(conf_file)) + if (triton_init(conf_file)) { + log_emerg("main: triton_init: conf_file failed\n"); _exit(EXIT_FAILURE); + } if (goto_daemon && pid != getpid()) { /*pid_t pid = fork(); @@ -393,8 +399,10 @@ int main(int _argc, char **_argv) triton_register_init(0, log_version); - if (triton_load_modules("modules")) + if (triton_load_modules("modules")) { + log_emerg("main: triton_load_modules: failed\n"); return EXIT_FAILURE; + } triton_run(); diff --git a/accel-pppd/ppp/ccp_mppe.c b/accel-pppd/ppp/ccp_mppe.c index 456fe82..cb41c0d 100644 --- a/accel-pppd/ppp/ccp_mppe.c +++ b/accel-pppd/ppp/ccp_mppe.c @@ -278,12 +278,12 @@ static void mppe_print(void (*print)(const char *fmt,...),struct ccp_option_t *o bits = 0; print("<mppe %sH %sM %sS %sL %sD %sC>", - bits & MPPE_H ? "+" : "-", - bits & MPPE_M ? "+" : "-", - bits & MPPE_S ? "+" : "-", - bits & MPPE_L ? "+" : "-", - bits & MPPE_D ? "+" : "-", - bits & MPPE_C ? "+" : "-" + (bits & MPPE_H) ? "+" : "-", + (bits & MPPE_M) ? "+" : "-", + (bits & MPPE_S) ? "+" : "-", + (bits & MPPE_L) ? "+" : "-", + (bits & MPPE_D) ? "+" : "-", + (bits & MPPE_C) ? "+" : "-" ); } diff --git a/accel-pppd/ppp/ipcp_opt_ipaddr.c b/accel-pppd/ppp/ipcp_opt_ipaddr.c index 6354bf1..c10ddd2 100644 --- a/accel-pppd/ppp/ipcp_opt_ipaddr.c +++ b/accel-pppd/ppp/ipcp_opt_ipaddr.c @@ -31,7 +31,7 @@ struct ipaddr_option_t { struct ipcp_option_t opt; struct ppp_t *ppp; - int started:1; + unsigned int started:1; }; static struct ipcp_option_handler_t ipaddr_opt_hnd = { diff --git a/accel-pppd/ppp/ipv6cp_opt_intfid.c b/accel-pppd/ppp/ipv6cp_opt_intfid.c index bc7fae8..fff7416 100644 --- a/accel-pppd/ppp/ipv6cp_opt_intfid.c +++ b/accel-pppd/ppp/ipv6cp_opt_intfid.c @@ -42,7 +42,7 @@ static void put_ipv6_item(struct ap_session *ses, struct ipv6db_item_t *ip6); struct ipaddr_option_t { struct ipv6cp_option_t opt; - int started:1; + unsigned int started:1; struct ppp_t *ppp; }; @@ -163,7 +163,8 @@ static uint64_t generate_intf_id(struct ppp_t *ppp) static uint64_t generate_peer_intf_id(struct ppp_t *ppp) { char str[4]; - int i, n; + int i; + unsigned int n; union { uint64_t intf_id; uint16_t addr16[4]; @@ -292,14 +293,14 @@ static uint64_t parse_intfid(const char *opt) uint16_t u16[4]; } u; - int n[4]; + unsigned int n[4]; int i; if (sscanf(opt, "%x:%x:%x:%x", &n[0], &n[1], &n[2], &n[3]) != 4) goto err; for (i = 0; i < 4; i++) { - if (n[i] < 0 || n[i] > 0xffff) + if (n[i] > 0xffff) goto err; u.u16[i] = htons(n[i]); } diff --git a/accel-pppd/ppp/lcp_opt_mru.c b/accel-pppd/ppp/lcp_opt_mru.c index ac4ce7f..74b107e 100644 --- a/accel-pppd/ppp/lcp_opt_mru.c +++ b/accel-pppd/ppp/lcp_opt_mru.c @@ -35,8 +35,8 @@ struct mru_option_t struct lcp_option_t opt; int mru; int mtu; - int naked:1; - int rejected:1; + unsigned int naked:1; + unsigned int rejected:1; }; static struct lcp_option_handler_t mru_opt_hnd= diff --git a/accel-pppd/ppp/ppp.h b/accel-pppd/ppp/ppp.h index f0fbcd3..2efa061 100644 --- a/accel-pppd/ppp/ppp.h +++ b/accel-pppd/ppp/ppp.h @@ -70,11 +70,11 @@ struct ppp_layer_data_t struct list_head entry; struct ppp_layer_t *layer; struct layer_node_t *node; - int passive:1; - int optional:1; - int starting:1; - int started:1; - int finished:1; + unsigned int passive:1; + unsigned int optional:1; + unsigned int starting:1; + unsigned int started:1; + unsigned int finished:1; }; struct ppp_layer_t diff --git a/accel-pppd/ppp/ppp_auth.c b/accel-pppd/ppp/ppp_auth.c index ab5200a..f30c6b9 100644 --- a/accel-pppd/ppp/ppp_auth.c +++ b/accel-pppd/ppp/ppp_auth.c @@ -38,7 +38,7 @@ struct auth_option_t struct lcp_option_t opt; struct list_head auth_list; struct auth_data_t *auth; - int started:1; + unsigned int started:1; }; struct auth_layer_data_t diff --git a/accel-pppd/ppp/ppp_ccp.h b/accel-pppd/ppp/ppp_ccp.h index cb5b164..243a4b5 100644 --- a/accel-pppd/ppp/ppp_ccp.h +++ b/accel-pppd/ppp/ppp_ccp.h @@ -84,8 +84,8 @@ struct ppp_ccp_t int ropt_len; int conf_req_len; - int starting:1; - int started:1; + unsigned int starting:1; + unsigned int started:1; }; int ccp_option_register(struct ccp_option_handler_t *h); diff --git a/accel-pppd/ppp/ppp_ipcp.h b/accel-pppd/ppp/ppp_ipcp.h index a46d9b6..036f0a4 100644 --- a/accel-pppd/ppp/ppp_ipcp.h +++ b/accel-pppd/ppp/ppp_ipcp.h @@ -60,7 +60,7 @@ struct ipcp_option_t int id; int len; int state; - int print:1; + unsigned int print:1; struct ipcp_option_handler_t *h; }; @@ -93,9 +93,9 @@ struct ppp_ipcp_t int ropt_len; int conf_req_len; - int starting:1; - int started:1; - int delay_ack:1; + unsigned int starting:1; + unsigned int started:1; + unsigned int delay_ack:1; }; int ipcp_option_register(struct ipcp_option_handler_t *h); diff --git a/accel-pppd/ppp/ppp_ipv6cp.h b/accel-pppd/ppp/ppp_ipv6cp.h index 57bb73b..6f1789e 100644 --- a/accel-pppd/ppp/ppp_ipv6cp.h +++ b/accel-pppd/ppp/ppp_ipv6cp.h @@ -66,7 +66,7 @@ struct ipv6cp_option_t int id; int len; int state; - int print:1; + unsigned int print:1; struct ipv6cp_option_handler_t *h; }; @@ -99,9 +99,9 @@ struct ppp_ipv6cp_t int ropt_len; int conf_req_len; - int starting:1; - int started:1; - int delay_ack:1; + unsigned int starting:1; + unsigned int started:1; + unsigned int delay_ack:1; }; int ipv6cp_option_register(struct ipv6cp_option_handler_t *h); diff --git a/accel-pppd/ppp/ppp_lcp.h b/accel-pppd/ppp/ppp_lcp.h index 10c55b0..39693d4 100644 --- a/accel-pppd/ppp/ppp_lcp.h +++ b/accel-pppd/ppp/ppp_lcp.h @@ -92,7 +92,7 @@ struct lcp_option_t int id; int len; int state; - int print:1; + unsigned int print:1; struct lcp_option_handler_t *h; }; @@ -129,7 +129,7 @@ struct ppp_lcp_t int ropt_len; int conf_req_len; - int started:1; + unsigned int started:1; }; int lcp_option_register(struct lcp_option_handler_t *h); diff --git a/accel-pppd/radius/auth.c b/accel-pppd/radius/auth.c index 8665867..10d0454 100644 --- a/accel-pppd/radius/auth.c +++ b/accel-pppd/radius/auth.c @@ -147,9 +147,9 @@ static void rad_auth_finalize(struct radius_pd_t *rpd, int r) { hold_pd(rpd); - rpd->auth_ctx->cb(rpd->auth_ctx->cb_arg, r); - if (rpd->auth_ctx) { + rpd->auth_ctx->cb(rpd->auth_ctx->cb_arg, r); + if (r == PWDB_SUCCESS) { rpd->auth_reply = rpd->auth_ctx->req->reply; rpd->auth_ctx->req->reply = NULL; diff --git a/accel-pppd/radius/dict.c b/accel-pppd/radius/dict.c index cb1fb28..4924c89 100644 --- a/accel-pppd/radius/dict.c +++ b/accel-pppd/radius/dict.c @@ -76,7 +76,7 @@ static int dict_load(const char *fname) struct rad_dict_value_t *val; struct rad_dict_vendor_t *vendor; struct list_head *items; - struct list_head *parent_items; + struct list_head *parent_items = NULL; f = fopen(fname, "r"); if (!f) { diff --git a/accel-pppd/radius/radius.c b/accel-pppd/radius/radius.c index 139b8b8..9137f61 100644 --- a/accel-pppd/radius/radius.c +++ b/accel-pppd/radius/radius.c @@ -930,15 +930,19 @@ static int parse_server(const char *opt, in_addr_t *addr, int *port, char **secr *p1 = 0; if (p2) *p2 = 0; - else + else { + _free(str); return -1; + } *addr = inet_addr(str); if (p1) { *port = atoi(p1 + 1); - if (*port <=0 ) + if (*port <=0) { + _free(str); return -1; + } } p1 = _strdup(p2 + 1); @@ -1042,28 +1046,35 @@ static void radius_init(void) const char *dict = NULL; struct conf_sect_t *s = conf_get_section("radius"); - if (!s) + if (!s) { + log_emerg("radius: config section not found\n"); _exit(EXIT_FAILURE); + } struct conf_option_t *opt1; rpd_pool = mempool_create(sizeof(struct radius_pd_t)); auth_ctx_pool = mempool_create(sizeof(struct radius_auth_ctx)); - if (load_config()) + if (load_config()) { + log_emerg("radius: config load failed\n"); _exit(EXIT_FAILURE); - + } list_for_each_entry(opt1, &s->items, entry) { if (strcmp(opt1->name, "dictionary") || !opt1->val) continue; dict = opt1->val; - if (rad_dict_load(dict)) + if (rad_dict_load(dict)) { + log_emerg("radius: dictionary load failed\n"); _exit(0); + } } - if (!dict && rad_dict_load(DICTIONARY)) + if (!dict && rad_dict_load(DICTIONARY)) { + log_emerg("radius: default dictionary load failed\n"); _exit(0); + } pwdb_register(&pwdb); ipdb_register(&ipdb); diff --git a/accel-pppd/radius/radius.h b/accel-pppd/radius/radius.h index 9fc8869..6ca94fb 100644 --- a/accel-pppd/radius/radius.h +++ b/accel-pppd/radius/radius.h @@ -80,7 +80,7 @@ struct rad_dict_attr_t const char *name; int id; int type:30; - int array:1; + unsigned int array:1; int size; struct list_head values; struct list_head tlv; @@ -94,7 +94,7 @@ struct rad_attr_t //struct rad_dict_value_t *val; int len; int cnt; - int alloc:1; + unsigned int alloc:1; void *raw; rad_value_t val; }; @@ -106,7 +106,7 @@ struct rad_packet_t int len; struct timespec tv; struct list_head attrs; - void *buf; + uint8_t *buf; }; struct rad_plugin_t diff --git a/accel-pppd/radius/radius_p.h b/accel-pppd/radius/radius_p.h index 0c185d2..14c1fb2 100644 --- a/accel-pppd/radius/radius_p.h +++ b/accel-pppd/radius/radius_p.h @@ -47,10 +47,10 @@ struct radius_pd_t { struct ap_session *ses; pthread_mutex_t lock; int refs:8; - int authenticated:1; - int acct_started:1; - int ipv6_dp_assigned:1; - int ipv6_dp_sent:1; + unsigned int authenticated:1; + unsigned int acct_started:1; + unsigned int ipv6_dp_assigned:1; + unsigned int ipv6_dp_sent:1; struct rad_packet_t *auth_reply; @@ -101,8 +101,8 @@ struct rad_req_t { int prio; int try; - int active:1; - int async:1; + unsigned int active:1; + unsigned int async:1; time_t ts; diff --git a/accel-pppd/radius/serv.c b/accel-pppd/radius/serv.c index 65af74d..6d1eb4c 100644 --- a/accel-pppd/radius/serv.c +++ b/accel-pppd/radius/serv.c @@ -197,6 +197,8 @@ int rad_server_req_enter(struct rad_req_t *req) pthread_mutex_lock(&req->serv->lock); + clock_gettime(CLOCK_MONOTONIC, &ts); + if (ts.tv_sec < req->serv->fail_time) { pthread_mutex_unlock(&req->serv->lock); return -1; @@ -616,15 +618,19 @@ static int parse_server_old(const char *opt, in_addr_t *addr, int *port, char ** *p1 = 0; if (p2) *p2 = 0; - else + else { + _free(str); return -1; + } *addr = inet_addr(str); if (p1) { *port = atoi(p1 + 1); - if (*port <=0 ) + if (*port <=0) { + _free(str); return -1; + } } *secret = _strdup(p2 + 1); diff --git a/accel-pppd/triton/conf_file.c b/accel-pppd/triton/conf_file.c index e1d9650..b5c650e 100644 --- a/accel-pppd/triton/conf_file.c +++ b/accel-pppd/triton/conf_file.c @@ -56,21 +56,21 @@ static int __conf_load(struct conf_ctx *ctx, const char *fname) static int load_file(struct conf_ctx *ctx) { - char *str2, *raw; + char *str2; char buf[1024] = {0}; static struct conf_sect_t *cur_sect = NULL; while(1) { int len; - char *str; + char *str, *raw; if (!fgets(buf, 1024, ctx->file)) break; ctx->line++; len = strlen(buf); - if (buf[len - 1] == '\n') + if (len && buf[len - 1] == '\n') buf[--len] = 0; while (len && (buf[len - 1] == ' ' || buf[len - 1] == '\t')) @@ -109,14 +109,14 @@ static int load_file(struct conf_ctx *ctx) continue; } - if (*str == '}' && ctx->items != &cur_sect->items) - return 0; - if (!cur_sect) { fprintf(stderr, "conf_file:%s:%i: no section opened\n", ctx->fname, ctx->line); return -1; } + if (*str == '}' && ctx->items != &cur_sect->items) + return 0; + raw = _strdup(str); str2 = skip_word(str); if (*str2 == ' ') { @@ -139,6 +139,7 @@ static int load_file(struct conf_ctx *ctx) opt = find_item(cur_sect, str2); if (!opt) { fprintf(stderr, "conf_file:%s:%i: parent option not found\n", ctx->fname, ctx->line); + _free(raw); return -1; } str2 = opt->val; diff --git a/accel-pppd/triton/mempool.c b/accel-pppd/triton/mempool.c index 923119a..ea6d1e6 100644 --- a/accel-pppd/triton/mempool.c +++ b/accel-pppd/triton/mempool.c @@ -32,7 +32,7 @@ struct _mempool_t uint64_t magic; #endif spinlock_t lock; - int mmap:1; + unsigned int mmap:1; int objects; }; @@ -55,8 +55,8 @@ struct _item_t static LIST_HEAD(pools); static spinlock_t pools_lock; static spinlock_t mmap_lock; -static void *mmap_ptr; -static void *mmap_endptr; +static uint8_t *mmap_ptr; +static uint8_t *mmap_endptr; static int mmap_grow(void); static void mempool_clean(void); @@ -113,8 +113,10 @@ void __export *mempool_alloc(mempool_t *pool) if (p->mmap) { spin_lock(&mmap_lock); if (mmap_ptr + size >= mmap_endptr) { - if (mmap_grow()) + if (mmap_grow()) { + spin_unlock(&mmap_lock); return NULL; + } } it = (struct _item_t *)mmap_ptr; mmap_ptr += size; @@ -256,7 +258,7 @@ static void sigclean(int num) static int mmap_grow(void) { int size = sysconf(_SC_PAGESIZE) * (1 << PAGE_ORDER); - void *ptr; + uint8_t *ptr; if (mmap_endptr) { ptr = mmap(mmap_endptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); diff --git a/accel-pppd/triton/triton.c b/accel-pppd/triton/triton.c index 7cd7055..a881910 100644 --- a/accel-pppd/triton/triton.c +++ b/accel-pppd/triton/triton.c @@ -742,8 +742,10 @@ void __export triton_run() for(i = 0; i < thread_count; i++) { t = create_thread(); - if (!t) + if (!t) { + triton_log_error("triton_run:create_thread: %s", strerror(errno)); _exit(-1); + } list_add_tail(&t->entry, &threads); pthread_mutex_unlock(&t->sleep_lock); diff --git a/accel-pppd/triton/triton_p.h b/accel-pppd/triton/triton_p.h index a727e62..bc39d62 100644 --- a/accel-pppd/triton/triton_p.h +++ b/accel-pppd/triton/triton_p.h @@ -61,9 +61,9 @@ struct _triton_md_handler_t struct epoll_event epoll_event; uint32_t trig_epoll_events; int pending; - int trig_level:1; - int armed:1; - int mod:1; + unsigned int trig_level:1; + unsigned int armed:1; + unsigned int mod:1; struct triton_md_handler_t *ud; }; @@ -74,7 +74,7 @@ struct _triton_timer_t struct epoll_event epoll_event; struct _triton_context_t *ctx; int fd; - int pending:1; + unsigned int pending:1; struct triton_timer_t *ud; }; diff --git a/drivers/ipoe/ipoe.c b/drivers/ipoe/ipoe.c index 32c9a52..5e220e9 100644 --- a/drivers/ipoe/ipoe.c +++ b/drivers/ipoe/ipoe.c @@ -304,7 +304,7 @@ static int ipoe_do_nat(struct sk_buff *skb, __be32 new_addr, int to_peer) ihl = iph->ihl * 4; - switch (iph->frag_off & htons(IP_OFFSET) ? 0 : iph->protocol) { + switch ((iph->frag_off & htons(IP_OFFSET)) ? 0 : iph->protocol) { case IPPROTO_TCP: { struct tcphdr *tcph; |