提交 f7c31d63 编写于 作者: J Jason Wang 提交者: Michael S. Tsirkin

net: properly handle illegal fd/vhostfd from command line

When hanlding fd/vhostfd form command line through net_handle_fd_param(),
we need to check mon and return value of strtol() otherwise we could
get segmentation fault or invalid fd when user type an illegal fd/vhostfd.

This patch is based on the suggestions from
Luiz Capitulino <lcapitulino@redhat.com>.
Signed-off-by: NJason Wang <jasowang@redhat.com>
Reviewed-by: NLuiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
上级 258dc7c9
......@@ -774,19 +774,25 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models,
int net_handle_fd_param(Monitor *mon, const char *param)
{
if (!qemu_isdigit(param[0])) {
int fd;
if (!qemu_isdigit(param[0]) && mon) {
fd = monitor_get_fd(mon, param);
if (fd == -1) {
error_report("No file descriptor named %s found", param);
return -1;
}
return fd;
} else {
return strtol(param, NULL, 0);
char *endptr = NULL;
fd = strtol(param, &endptr, 10);
if (*endptr || (fd == 0 && param == endptr)) {
return -1;
}
}
return fd;
}
static int net_init_nic(QemuOpts *opts,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册