if (message) {
g_variant_get(message, "(a(oa{sv}))", &iter);
- while (g_variant_iter_loop(iter, "(oa{sv})", &key, &value)) {
+ if (g_variant_iter_loop(iter, "(oa{sv})", &key, &value))
profile = strdup(key);
- break;
- }
if (value)
g_variant_iter_free(value);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN_FROM_NAT,
iptables_cmd, iptables_nat_chain_name);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_DEL_CHAIN_FROM_NAT,
iptables_cmd, iptables_nat_chain_name);
if (netconfig_execute_cmd(buf))
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_DROP_RULE,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_RETURN_RULE,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_INSERT_RULE,
iptables_cmd, filter, iptables_filter_prefix, filter);
filter = iptables_filter_in;
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_CREATE_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_DROP_RULE,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_RETURN_RULE,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_INSERT_RULE,
iptables_cmd, filter, iptables_filter_prefix, filter);
}
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_DEL_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
filter = iptables_filter_in;
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_DEL_RULE,
iptables_cmd, filter, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_DEL_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_ACCEPT_RULE,
iptables_cmd, c, iptables_filter_prefix,
iptables_filter_in, 's', addr, mask);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_ACCEPT_RULE_WITH_INTF,
iptables_cmd, c, iptables_filter_prefix, iptables_filter_in,
'i', interface, 's', addr, mask);
memset(&ifr, 0, sizeof(ifr));
if (*iface_name)
- strncpy(ifr.ifr_name, iface_name, IFNAMSIZ);
+ strncpy(ifr.ifr_name, iface_name, IFNAMSIZ - 1);
/* get an interface name by ifindex */
if (ioctl(sk, SIOCGIFINDEX, &ifr) < 0) {
int vpn_service_init(const char* iface_name, size_t iface_name_len, int fd, vpnsvc_tun_s *handle_s)
{
struct ifreq ifr;
- size_t len = 0;
char buf[BUF_SIZE_FOR_ERR] = { 0 };
- DBG("enter vpn_daemon_init, iface_name : %s, iface_name_len : %d, fd : %d\n", iface_name, iface_name_len, fd);
+ DBG("enter vpn_daemon_init, iface_name : %s, iface_name_len : %zd, fd : %d\n", iface_name, iface_name_len, fd);
memset(&ifr, 0, sizeof(ifr));
if (*iface_name)
strncpy(ifr.ifr_name, iface_name, iface_name_len);
+ ifr.ifr_name[iface_name_len] = '\0';
DBG("before init, ifindex : %d", ifr.ifr_ifindex);
handle_s->fd = 0; /* server fd does not meaning */
handle_s->index = get_interface_index(iface_name);
- len = strlen(ifr.ifr_name);
- strncpy(handle_s->name, ifr.ifr_name, len);
- handle_s->name[len] = '\0';
+ g_strlcpy(handle_s->name, ifr.ifr_name, VPNSVC_VPN_IFACE_NAME_LEN);
return VPNSVC_ERROR_NONE;
}