[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 3/3] net: tap: replace snprintf with g_strdup_pri
From: |
P J P |
Subject: |
[Qemu-devel] [PATCH v4 3/3] net: tap: replace snprintf with g_strdup_printf calls |
Date: |
Tue, 23 Jul 2019 16:17:54 +0530 |
From: Prasad J Pandit <address@hidden>
When invoking qemu-bridge-helper in 'net_bridge_run_helper',
instead of using fixed sized buffers, use dynamically allocated
ones initialised and returned by g_strdup_printf().
Signed-off-by: Prasad J Pandit <address@hidden>
---
net/tap.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
Update v4: only replace snprintf with g_strdup_printf calls
-> https://lists.nongnu.org/archive/html/qemu-devel/2019-07/msg00578.html
diff --git a/net/tap.c b/net/tap.c
index e8aadd8d4b..fc38029f41 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -498,9 +498,9 @@ static int net_bridge_run_helper(const char *helper, const
char *bridge,
}
if (pid == 0) {
int open_max = sysconf(_SC_OPEN_MAX), i;
- char fd_buf[6+10];
- char br_buf[6+IFNAMSIZ] = {0};
- char helper_cmd[PATH_MAX + sizeof(fd_buf) + sizeof(br_buf) + 15];
+ char *fd_buf = NULL;
+ char *br_buf = NULL;
+ char *helper_cmd = NULL;
for (i = 3; i < open_max; i++) {
if (i != sv[1]) {
@@ -508,17 +508,17 @@ static int net_bridge_run_helper(const char *helper,
const char *bridge,
}
}
- snprintf(fd_buf, sizeof(fd_buf), "%s%d", "--fd=", sv[1]);
+ fd_buf = g_strdup_printf("%s%d", "--fd=", sv[1]);
if (strrchr(helper, ' ') || strrchr(helper, '\t')) {
/* assume helper is a command */
if (strstr(helper, "--br=") == NULL) {
- snprintf(br_buf, sizeof(br_buf), "%s%s", "--br=", bridge);
+ br_buf = g_strdup_printf("%s%s", "--br=", bridge);
}
- snprintf(helper_cmd, sizeof(helper_cmd), "%s %s %s %s",
- helper, "--use-vnet", fd_buf, br_buf);
+ helper_cmd = g_strdup_printf("%s %s %s %s", helper,
+ "--use-vnet", fd_buf, br_buf ? br_buf : "");
parg = args;
*parg++ = (char *)"sh";
@@ -527,10 +527,11 @@ static int net_bridge_run_helper(const char *helper,
const char *bridge,
*parg++ = NULL;
execv("/bin/sh", args);
+ g_free(helper_cmd);
} else {
/* assume helper is just the executable path name */
- snprintf(br_buf, sizeof(br_buf), "%s%s", "--br=", bridge);
+ br_buf = g_strdup_printf("%s%s", "--br=", bridge);
parg = args;
*parg++ = (char *)helper;
@@ -541,6 +542,8 @@ static int net_bridge_run_helper(const char *helper, const
char *bridge,
execv(helper, args);
}
+ g_free(fd_buf);
+ g_free(br_buf);
_exit(1);
} else {
--
2.21.0
- [Qemu-devel] [PATCH v4 0/3] restrict bridge interface name to IFNAMSIZ, P J P, 2019/07/23
- [Qemu-devel] [PATCH v4 1/3] qemu-bridge-helper: restrict interface name to IFNAMSIZ, P J P, 2019/07/23
- [Qemu-devel] [PATCH v4 2/3] qemu-bridge-helper: move repeating code in parse_acl_file, P J P, 2019/07/23
- [Qemu-devel] [PATCH v4 3/3] net: tap: replace snprintf with g_strdup_printf calls,
P J P <=
- Re: [Qemu-devel] [PATCH v4 3/3] net: tap: replace snprintf with g_strdup_printf calls, Stefan Hajnoczi, 2019/07/23
- Re: [Qemu-devel] [PATCH v4 3/3] net: tap: replace snprintf with g_strdup_printf calls, Li Qiang, 2019/07/23
- Re: [Qemu-devel] [PATCH v4 3/3] net: tap: replace snprintf with g_strdup_printf calls, P J P, 2019/07/24
- Re: [Qemu-devel] [PATCH v4 3/3] net: tap: replace snprintf with g_strdup_printf calls, Stefan Hajnoczi, 2019/07/29
- Re: [Qemu-devel] [PATCH v4 3/3] net: tap: replace snprintf with g_strdup_printf calls, Jason Wang, 2019/07/31
- Re: [Qemu-devel] [PATCH v4 3/3] net: tap: replace snprintf with g_strdup_printf calls, P J P, 2019/07/31
- Re: [Qemu-devel] [PATCH v4 3/3] net: tap: replace snprintf with g_strdup_printf calls, Jason Wang, 2019/07/31
- Re: [Qemu-devel] [PATCH v4 3/3] net: tap: replace snprintf with g_strdup_printf calls, P J P, 2019/07/31
Re: [Qemu-devel] [PATCH v4 3/3] net: tap: replace snprintf with g_strdup_printf calls, Daniel P . Berrangé, 2019/07/23
Re: [Qemu-devel] [PATCH v4 0/3] restrict bridge interface name to IFNAMSIZ, no-reply, 2019/07/23