summaryrefslogtreecommitdiffstats
path: root/net.c
diff options
context:
space:
mode:
authorJason Wang <[email protected]>2010-10-25 13:39:59 +0800
committerMichael S. Tsirkin <[email protected]>2010-10-27 18:54:02 +0200
commitf7c31d6381f2cbac03e82fc23133f6863606edd8 (patch)
treeac33e75ca51852177093bd88b4d84727cf83f1a9 /net.c
parent258dc7c96bb4b7ca71d5bee811e73933310e168c (diff)
downloadqemu-kvm-f7c31d6381f2cbac03e82fc23133f6863606edd8.tar.gz
qemu-kvm-f7c31d6381f2cbac03e82fc23133f6863606edd8.tar.bz2
qemu-kvm-f7c31d6381f2cbac03e82fc23133f6863606edd8.zip
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 <[email protected]>. Signed-off-by: Jason Wang <[email protected]> Reviewed-by: Luiz Capitulino <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
Diffstat (limited to 'net.c')
-rw-r--r--net.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/net.c b/net.c
index ed74c7f10..c5e6063fc 100644
--- a/net.c
+++ b/net.c
@@ -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;
+ 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,