From: Samuel Ortiz Date: Thu, 28 Oct 2010 22:58:08 +0000 (+0200) Subject: iptables: Use printf format for iptables_command argument X-Git-Tag: 2.0_alpha~2259 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6d7b6f02efe6db2895af2d9ecd75d16a04a2294d;p=framework%2Fconnectivity%2Fconnman.git iptables: Use printf format for iptables_command argument --- diff --git a/src/connman.h b/src/connman.h index 2fa1129..adca4d3 100644 --- a/src/connman.h +++ b/src/connman.h @@ -590,5 +590,5 @@ int __connman_stats_get(struct connman_service *service, int __connman_iptables_init(void); void __connman_iptables_cleanup(void); -int __connman_iptables_command(char *command); -int __connman_iptables_commit(char *table_name); +int __connman_iptables_command(const char *format, ...); +int __connman_iptables_commit(const char *table_name); diff --git a/src/iptables.c b/src/iptables.c index dcb1b8d..b5ce893 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -918,14 +918,24 @@ out: return ret; } -int __connman_iptables_command(char *command) +int __connman_iptables_command(const char *format, ...) { - char **argv, **arguments; + char **argv, **arguments, *command; int argc, i, ret; + va_list args; - if (command == NULL) + if (format == NULL) return -EINVAL; + va_start(args, format); + + command = g_strdup_vprintf(format, args); + + va_end(args); + + if (command == NULL) + return -ENOMEM; + arguments = g_strsplit_set(command, " ", -1); for (argc = 0; arguments[argc]; argc++); @@ -934,6 +944,7 @@ int __connman_iptables_command(char *command) argv = g_try_malloc0(argc * sizeof(char *)); if (argv == NULL) { + g_free(command); g_strfreev(arguments); return -ENOMEM; } @@ -944,6 +955,7 @@ int __connman_iptables_command(char *command) ret = iptables_command(argc, argv); + g_free(command); g_strfreev(arguments); g_free(argv); @@ -951,7 +963,7 @@ int __connman_iptables_command(char *command) } -int __connman_iptables_commit(char *table_name) +int __connman_iptables_commit(const char *table_name) { struct connman_iptables *table; struct ipt_replace *repl;