diff mbox series

[v3] monitor: Fix return type of monitor_fdset_dup_fd_find

Message ID 20190523094433.30297-1-yury-kotov@yandex-team.ru (mailing list archive)
State New, archived
Headers show
Series [v3] monitor: Fix return type of monitor_fdset_dup_fd_find | expand

Commit Message

Yury Kotov May 23, 2019, 9:44 a.m. UTC
monitor_fdset_dup_fd_find_remove() and monitor_fdset_dup_fd_find()
return mon_fdset->id which is int64_t. Downcasting from int64_t to int
leads to a bug with removing fd from fdset with id >= 2^32.
So, fix return types for these function.

Signed-off-by: Yury Kotov <yury-kotov@yandex-team.ru>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
---
 include/monitor/monitor.h | 2 +-
 monitor.c                 | 4 ++--
 stubs/fdset.c             | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

Comments

Yury Kotov May 27, 2019, 8:09 a.m. UTC | #1
Ping

23.05.2019, 12:45, "Yury Kotov" <yury-kotov@yandex-team.ru>:
> monitor_fdset_dup_fd_find_remove() and monitor_fdset_dup_fd_find()
> return mon_fdset->id which is int64_t. Downcasting from int64_t to int
> leads to a bug with removing fd from fdset with id >= 2^32.
> So, fix return types for these function.
>
> Signed-off-by: Yury Kotov <yury-kotov@yandex-team.ru>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> ---
>  include/monitor/monitor.h | 2 +-
>  monitor.c | 4 ++--
>  stubs/fdset.c | 2 +-
>  3 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
> index 86656297f1..51f048d61f 100644
> --- a/include/monitor/monitor.h
> +++ b/include/monitor/monitor.h
> @@ -45,6 +45,6 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
>  int monitor_fdset_get_fd(int64_t fdset_id, int flags);
>  int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
>  void monitor_fdset_dup_fd_remove(int dup_fd);
> -int monitor_fdset_dup_fd_find(int dup_fd);
> +int64_t monitor_fdset_dup_fd_find(int dup_fd);
>
>  #endif /* MONITOR_H */
> diff --git a/monitor.c b/monitor.c
> index 6428eb3b7e..a0e637f7d6 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2602,7 +2602,7 @@ err:
>      return -1;
>  }
>
> -static int monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
> +static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
>  {
>      MonFdset *mon_fdset;
>      MonFdsetFd *mon_fdset_fd_dup;
> @@ -2630,7 +2630,7 @@ err:
>      return -1;
>  }
>
> -int monitor_fdset_dup_fd_find(int dup_fd)
> +int64_t monitor_fdset_dup_fd_find(int dup_fd)
>  {
>      return monitor_fdset_dup_fd_find_remove(dup_fd, false);
>  }
> diff --git a/stubs/fdset.c b/stubs/fdset.c
> index 4f3edf2ea4..a1b8f41f62 100644
> --- a/stubs/fdset.c
> +++ b/stubs/fdset.c
> @@ -7,7 +7,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd)
>      return -1;
>  }
>
> -int monitor_fdset_dup_fd_find(int dup_fd)
> +int64_t monitor_fdset_dup_fd_find(int dup_fd)
>  {
>      return -1;
>  }
> --
> 2.21.0
Markus Armbruster May 28, 2019, 6:08 a.m. UTC | #2
David, got anything queued for the monitor?  If yes, can you stick this
in?  If not, I can handle it.

Yury Kotov <yury-kotov@yandex-team.ru> writes:

> monitor_fdset_dup_fd_find_remove() and monitor_fdset_dup_fd_find()
> return mon_fdset->id which is int64_t. Downcasting from int64_t to int
> leads to a bug with removing fd from fdset with id >= 2^32.
> So, fix return types for these function.
>
> Signed-off-by: Yury Kotov <yury-kotov@yandex-team.ru>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> ---
>  include/monitor/monitor.h | 2 +-
>  monitor.c                 | 4 ++--
>  stubs/fdset.c             | 2 +-
>  3 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
> index 86656297f1..51f048d61f 100644
> --- a/include/monitor/monitor.h
> +++ b/include/monitor/monitor.h
> @@ -45,6 +45,6 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
>  int monitor_fdset_get_fd(int64_t fdset_id, int flags);
>  int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
>  void monitor_fdset_dup_fd_remove(int dup_fd);
> -int monitor_fdset_dup_fd_find(int dup_fd);
> +int64_t monitor_fdset_dup_fd_find(int dup_fd);
>  
>  #endif /* MONITOR_H */
> diff --git a/monitor.c b/monitor.c
> index 6428eb3b7e..a0e637f7d6 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2602,7 +2602,7 @@ err:
>      return -1;
>  }
>  
> -static int monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
> +static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
>  {
>      MonFdset *mon_fdset;
>      MonFdsetFd *mon_fdset_fd_dup;
> @@ -2630,7 +2630,7 @@ err:
>      return -1;
>  }
>  
> -int monitor_fdset_dup_fd_find(int dup_fd)
> +int64_t monitor_fdset_dup_fd_find(int dup_fd)
>  {
>      return monitor_fdset_dup_fd_find_remove(dup_fd, false);
>  }
> diff --git a/stubs/fdset.c b/stubs/fdset.c
> index 4f3edf2ea4..a1b8f41f62 100644
> --- a/stubs/fdset.c
> +++ b/stubs/fdset.c
> @@ -7,7 +7,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd)
>      return -1;
>  }
>  
> -int monitor_fdset_dup_fd_find(int dup_fd)
> +int64_t monitor_fdset_dup_fd_find(int dup_fd)
>  {
>      return -1;
>  }
Dr. David Alan Gilbert May 31, 2019, 7:07 p.m. UTC | #3
* Markus Armbruster (armbru@redhat.com) wrote:
> David, got anything queued for the monitor?  If yes, can you stick this
> in?  If not, I can handle it.

I've not got anything else, so please take it;
am I right in thinking this supercedes

  'monitor: Fix fdset_id & fd types for corresponding QMP commands'

Thanks,

Dave


> Yury Kotov <yury-kotov@yandex-team.ru> writes:
> 
> > monitor_fdset_dup_fd_find_remove() and monitor_fdset_dup_fd_find()
> > return mon_fdset->id which is int64_t. Downcasting from int64_t to int
> > leads to a bug with removing fd from fdset with id >= 2^32.
> > So, fix return types for these function.
> >
> > Signed-off-by: Yury Kotov <yury-kotov@yandex-team.ru>
> > Reviewed-by: Markus Armbruster <armbru@redhat.com>
> > ---
> >  include/monitor/monitor.h | 2 +-
> >  monitor.c                 | 4 ++--
> >  stubs/fdset.c             | 2 +-
> >  3 files changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
> > index 86656297f1..51f048d61f 100644
> > --- a/include/monitor/monitor.h
> > +++ b/include/monitor/monitor.h
> > @@ -45,6 +45,6 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
> >  int monitor_fdset_get_fd(int64_t fdset_id, int flags);
> >  int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
> >  void monitor_fdset_dup_fd_remove(int dup_fd);
> > -int monitor_fdset_dup_fd_find(int dup_fd);
> > +int64_t monitor_fdset_dup_fd_find(int dup_fd);
> >  
> >  #endif /* MONITOR_H */
> > diff --git a/monitor.c b/monitor.c
> > index 6428eb3b7e..a0e637f7d6 100644
> > --- a/monitor.c
> > +++ b/monitor.c
> > @@ -2602,7 +2602,7 @@ err:
> >      return -1;
> >  }
> >  
> > -static int monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
> > +static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
> >  {
> >      MonFdset *mon_fdset;
> >      MonFdsetFd *mon_fdset_fd_dup;
> > @@ -2630,7 +2630,7 @@ err:
> >      return -1;
> >  }
> >  
> > -int monitor_fdset_dup_fd_find(int dup_fd)
> > +int64_t monitor_fdset_dup_fd_find(int dup_fd)
> >  {
> >      return monitor_fdset_dup_fd_find_remove(dup_fd, false);
> >  }
> > diff --git a/stubs/fdset.c b/stubs/fdset.c
> > index 4f3edf2ea4..a1b8f41f62 100644
> > --- a/stubs/fdset.c
> > +++ b/stubs/fdset.c
> > @@ -7,7 +7,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd)
> >      return -1;
> >  }
> >  
> > -int monitor_fdset_dup_fd_find(int dup_fd)
> > +int64_t monitor_fdset_dup_fd_find(int dup_fd)
> >  {
> >      return -1;
> >  }
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
Markus Armbruster June 3, 2019, 8:15 a.m. UTC | #4
"Dr. David Alan Gilbert" <dgilbert@redhat.com> writes:

> * Markus Armbruster (armbru@redhat.com) wrote:
>> David, got anything queued for the monitor?  If yes, can you stick this
>> in?  If not, I can handle it.
>
> I've not got anything else, so please take it;
> am I right in thinking this supercedes
>
>   'monitor: Fix fdset_id & fd types for corresponding QMP commands'

Correct.

> Thanks,

Queued.  Thanks!
diff mbox series

Patch

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 86656297f1..51f048d61f 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -45,6 +45,6 @@  AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
 int monitor_fdset_get_fd(int64_t fdset_id, int flags);
 int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
 void monitor_fdset_dup_fd_remove(int dup_fd);
-int monitor_fdset_dup_fd_find(int dup_fd);
+int64_t monitor_fdset_dup_fd_find(int dup_fd);
 
 #endif /* MONITOR_H */
diff --git a/monitor.c b/monitor.c
index 6428eb3b7e..a0e637f7d6 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2602,7 +2602,7 @@  err:
     return -1;
 }
 
-static int monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
+static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
 {
     MonFdset *mon_fdset;
     MonFdsetFd *mon_fdset_fd_dup;
@@ -2630,7 +2630,7 @@  err:
     return -1;
 }
 
-int monitor_fdset_dup_fd_find(int dup_fd)
+int64_t monitor_fdset_dup_fd_find(int dup_fd)
 {
     return monitor_fdset_dup_fd_find_remove(dup_fd, false);
 }
diff --git a/stubs/fdset.c b/stubs/fdset.c
index 4f3edf2ea4..a1b8f41f62 100644
--- a/stubs/fdset.c
+++ b/stubs/fdset.c
@@ -7,7 +7,7 @@  int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd)
     return -1;
 }
 
-int monitor_fdset_dup_fd_find(int dup_fd)
+int64_t monitor_fdset_dup_fd_find(int dup_fd)
 {
     return -1;
 }