mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-26 19:42:33 -06:00
net: tap: replace snprintf with g_strdup_printf calls
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 <pjp@fedoraproject.org> Reviewed-by: Li Qiang <liq3ea@gmail.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
parent
3283dde4b5
commit
389abe1dd1
1 changed files with 11 additions and 8 deletions
19
net/tap.c
19
net/tap.c
|
@ -498,9 +498,9 @@ static int net_bridge_run_helper(const char *helper, const char *bridge,
|
||||||
}
|
}
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
int open_max = sysconf(_SC_OPEN_MAX), i;
|
int open_max = sysconf(_SC_OPEN_MAX), i;
|
||||||
char fd_buf[6+10];
|
char *fd_buf = NULL;
|
||||||
char br_buf[6+IFNAMSIZ] = {0};
|
char *br_buf = NULL;
|
||||||
char helper_cmd[PATH_MAX + sizeof(fd_buf) + sizeof(br_buf) + 15];
|
char *helper_cmd = NULL;
|
||||||
|
|
||||||
for (i = 3; i < open_max; i++) {
|
for (i = 3; i < open_max; i++) {
|
||||||
if (i != sv[1]) {
|
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')) {
|
if (strrchr(helper, ' ') || strrchr(helper, '\t')) {
|
||||||
/* assume helper is a command */
|
/* assume helper is a command */
|
||||||
|
|
||||||
if (strstr(helper, "--br=") == NULL) {
|
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_cmd = g_strdup_printf("%s %s %s %s", helper,
|
||||||
helper, "--use-vnet", fd_buf, br_buf);
|
"--use-vnet", fd_buf, br_buf ? br_buf : "");
|
||||||
|
|
||||||
parg = args;
|
parg = args;
|
||||||
*parg++ = (char *)"sh";
|
*parg++ = (char *)"sh";
|
||||||
|
@ -527,10 +527,11 @@ static int net_bridge_run_helper(const char *helper, const char *bridge,
|
||||||
*parg++ = NULL;
|
*parg++ = NULL;
|
||||||
|
|
||||||
execv("/bin/sh", args);
|
execv("/bin/sh", args);
|
||||||
|
g_free(helper_cmd);
|
||||||
} else {
|
} else {
|
||||||
/* assume helper is just the executable path name */
|
/* 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 = args;
|
||||||
*parg++ = (char *)helper;
|
*parg++ = (char *)helper;
|
||||||
|
@ -541,6 +542,8 @@ static int net_bridge_run_helper(const char *helper, const char *bridge,
|
||||||
|
|
||||||
execv(helper, args);
|
execv(helper, args);
|
||||||
}
|
}
|
||||||
|
g_free(fd_buf);
|
||||||
|
g_free(br_buf);
|
||||||
_exit(1);
|
_exit(1);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue