* [Qemu-devel] [V3 PATCH] net: properly handle illegal fd/vhostfd from command line
@ 2010-10-25 5:39 Jason Wang
2010-10-25 12:52 ` [Qemu-devel] " Luiz Capitulino
2010-10-26 14:58 ` Michael S. Tsirkin
0 siblings, 2 replies; 4+ messages in thread
From: Jason Wang @ 2010-10-25 5:39 UTC (permalink / raw)
To: qemu-devel, mst; +Cc: lcapitulino
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: Jason Wang <jasowang@redhat.com>
---
net.c | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/net.c b/net.c
index ed74c7f..c5e6063 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,
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] Re: [V3 PATCH] net: properly handle illegal fd/vhostfd from command line
2010-10-25 5:39 [Qemu-devel] [V3 PATCH] net: properly handle illegal fd/vhostfd from command line Jason Wang
@ 2010-10-25 12:52 ` Luiz Capitulino
2010-10-25 16:57 ` Michael S. Tsirkin
2010-10-26 14:58 ` Michael S. Tsirkin
1 sibling, 1 reply; 4+ messages in thread
From: Luiz Capitulino @ 2010-10-25 12:52 UTC (permalink / raw)
To: Jason Wang; +Cc: qemu-devel, mst
On Mon, 25 Oct 2010 13:39:59 +0800
Jason Wang <jasowang@redhat.com> wrote:
> 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: Jason Wang <jasowang@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
> net.c | 16 +++++++++++-----
> 1 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/net.c b/net.c
> index ed74c7f..c5e6063 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,
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] Re: [V3 PATCH] net: properly handle illegal fd/vhostfd from command line
2010-10-25 12:52 ` [Qemu-devel] " Luiz Capitulino
@ 2010-10-25 16:57 ` Michael S. Tsirkin
0 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2010-10-25 16:57 UTC (permalink / raw)
To: Luiz Capitulino; +Cc: Jason Wang, qemu-devel
On Mon, Oct 25, 2010 at 10:52:05AM -0200, Luiz Capitulino wrote:
> On Mon, 25 Oct 2010 13:39:59 +0800
> Jason Wang <jasowang@redhat.com> wrote:
>
> > 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: Jason Wang <jasowang@redhat.com>
>
> Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Applied, thanks everyone.
> > ---
> > net.c | 16 +++++++++++-----
> > 1 files changed, 11 insertions(+), 5 deletions(-)
> >
> > diff --git a/net.c b/net.c
> > index ed74c7f..c5e6063 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,
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] Re: [V3 PATCH] net: properly handle illegal fd/vhostfd from command line
2010-10-25 5:39 [Qemu-devel] [V3 PATCH] net: properly handle illegal fd/vhostfd from command line Jason Wang
2010-10-25 12:52 ` [Qemu-devel] " Luiz Capitulino
@ 2010-10-26 14:58 ` Michael S. Tsirkin
1 sibling, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2010-10-26 14:58 UTC (permalink / raw)
To: Jason Wang; +Cc: qemu-devel, lcapitulino
On Mon, Oct 25, 2010 at 01:39:59PM +0800, Jason Wang wrote:
> 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: Jason Wang <jasowang@redhat.com>
Applied.
> ---
> net.c | 16 +++++++++++-----
> 1 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/net.c b/net.c
> index ed74c7f..c5e6063 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,
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-10-26 15:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-25 5:39 [Qemu-devel] [V3 PATCH] net: properly handle illegal fd/vhostfd from command line Jason Wang
2010-10-25 12:52 ` [Qemu-devel] " Luiz Capitulino
2010-10-25 16:57 ` Michael S. Tsirkin
2010-10-26 14:58 ` Michael S. Tsirkin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).