* limitations under the License.
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
GVariant *parameters;
GError *error = NULL;
guint result;
- char cmd[MAX_BUF_SIZE] = { 0, };
char *list = NULL;
+ int ret;
__tethering_h *th = (__tethering_h *)tethering;
g_variant_unref(parameters);
if (allow)
- snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
+ ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
else
- snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
-
- DBG("cmd:%s", cmd);
+ ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
- list = strdup(cmd);
- if (list == NULL) {
- ERR("strdup failed\n"); //LCOV_EXCL_LINE
+ if (ret == -1 || list == NULL) {
+ ERR("asprintf failed\n"); //LCOV_EXCL_LINE
return TETHERING_ERROR_OUT_OF_MEMORY;
}
+ DBG("cmd:%s", list);
+
port_filtering = g_slist_append(port_filtering, list);
return TETHERING_ERROR_NONE;
GVariant *parameters;
GError *error = NULL;
guint result;
- char cmd[MAX_BUF_SIZE] = { 0, };
char *list = NULL;
+ int ret;
__tethering_h *th = (__tethering_h *)tethering;
g_variant_unref(parameters);
if (allow)
- snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
+ ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
else
- snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
-
- DBG("cmd:%s", cmd);
+ ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
- list = strdup(cmd);
- if (list == NULL) {
- ERR("strdup failed\n"); //LCOV_EXCL_LINE
+ if (ret == -1 || list == NULL) {
+ ERR("asprintf failed\n"); //LCOV_EXCL_LINE
return TETHERING_ERROR_OUT_OF_MEMORY;
}
+ DBG("cmd:%s", list);
+
custom_port_filtering = g_slist_append(custom_port_filtering, list);
return TETHERING_ERROR_NONE;