This check shouldn't be necessary, since &error_fatal is given as
argument and will exit() on failure. However, this change should
silence coverity CID 1401761 & 1401705.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
contrib/vhost-user-gpu/main.c | 4 ++++
contrib/vhost-user-input/main.c | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/contrib/vhost-user-gpu/main.c b/contrib/vhost-user-gpu/main.c
index 9614c9422c..e0b6df5b4d 100644
--- a/contrib/vhost-user-gpu/main.c
+++ b/contrib/vhost-user-gpu/main.c
@@ -1160,6 +1160,10 @@ main(int argc, char *argv[])
if (opt_socket_path) {
int lsock = unix_listen(opt_socket_path, &error_fatal);
+ if (lsock < 0) {
+ g_printerr("Failed to listen on %s.\n", opt_socket_path);
+ exit(EXIT_FAILURE);
+ }
fd = accept(lsock, NULL, NULL);
close(lsock);
} else {
diff --git a/contrib/vhost-user-input/main.c b/contrib/vhost-user-input/main.c
index 8d493f598e..8b854117f5 100644
--- a/contrib/vhost-user-input/main.c
+++ b/contrib/vhost-user-input/main.c
@@ -367,6 +367,10 @@ main(int argc, char *argv[])
if (opt_socket_path) {
int lsock = unix_listen(opt_socket_path, &error_fatal);
+ if (lsock < 0) {
+ g_printerr("Failed to listen on %s.\n", opt_socket_path);
+ exit(EXIT_FAILURE);
+ }
fd = accept(lsock, NULL, NULL);
close(lsock);
} else {
--
2.22.0.rc2.384.g1a9a72ea1d
On 6/16/19 4:36 PM, Michael S. Tsirkin wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> This check shouldn't be necessary, since &error_fatal is given as
> argument and will exit() on failure. However, this change should
> silence coverity CID 1401761 & 1401705.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Message-Id: <20190605145829.7674-3-marcandre.lureau@redhat.com>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> contrib/vhost-user-gpu/main.c | 4 ++++
> contrib/vhost-user-input/main.c | 4 ++++
> 2 files changed, 8 insertions(+)
>
> diff --git a/contrib/vhost-user-gpu/main.c b/contrib/vhost-user-gpu/main.c
> index 9614c9422c..e0b6df5b4d 100644
> --- a/contrib/vhost-user-gpu/main.c
> +++ b/contrib/vhost-user-gpu/main.c
> @@ -1160,6 +1160,10 @@ main(int argc, char *argv[])
>
> if (opt_socket_path) {
> int lsock = unix_listen(opt_socket_path, &error_fatal);
> + if (lsock < 0) {
> + g_printerr("Failed to listen on %s.\n", opt_socket_path);
> + exit(EXIT_FAILURE);
> + }
4 lines to appease Coverity; wouldn't the following one-liner also do
the trick?
int lsock = unix_listen(opt_socket_path, &error_fatal);
assert (lsock >= 0);
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
Hi
On Wed, Jun 26, 2019 at 7:56 PM Eric Blake <eblake@redhat.com> wrote:
>
> On 6/16/19 4:36 PM, Michael S. Tsirkin wrote:
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > This check shouldn't be necessary, since &error_fatal is given as
> > argument and will exit() on failure. However, this change should
> > silence coverity CID 1401761 & 1401705.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > Message-Id: <20190605145829.7674-3-marcandre.lureau@redhat.com>
> > Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> > contrib/vhost-user-gpu/main.c | 4 ++++
> > contrib/vhost-user-input/main.c | 4 ++++
> > 2 files changed, 8 insertions(+)
> >
> > diff --git a/contrib/vhost-user-gpu/main.c b/contrib/vhost-user-gpu/main.c
> > index 9614c9422c..e0b6df5b4d 100644
> > --- a/contrib/vhost-user-gpu/main.c
> > +++ b/contrib/vhost-user-gpu/main.c
> > @@ -1160,6 +1160,10 @@ main(int argc, char *argv[])
> >
> > if (opt_socket_path) {
> > int lsock = unix_listen(opt_socket_path, &error_fatal);
> > + if (lsock < 0) {
> > + g_printerr("Failed to listen on %s.\n", opt_socket_path);
> > + exit(EXIT_FAILURE);
> > + }
>
> 4 lines to appease Coverity; wouldn't the following one-liner also do
> the trick?
>
> int lsock = unix_listen(opt_socket_path, &error_fatal);
> assert (lsock >= 0);
Probably, I didn't think too much about it. However looking at it now,
it would be worthwhile to report the error to the user in a friendlier
way than what error_fatal do. So I guess a follow-up patch should
introduce a local Error.
>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc. +1-919-301-3226
> Virtualization: qemu.org | libvirt.org
>
--
Marc-André Lureau
On Wed, 5 Jun 2019 at 16:02, Marc-André Lureau
<marcandre.lureau@redhat.com> wrote:
>
> This check shouldn't be necessary, since &error_fatal is given as
> argument and will exit() on failure. However, this change should
> silence coverity CID 1401761 & 1401705.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> contrib/vhost-user-gpu/main.c | 4 ++++
> contrib/vhost-user-input/main.c | 4 ++++
> 2 files changed, 8 insertions(+)
>
> diff --git a/contrib/vhost-user-gpu/main.c b/contrib/vhost-user-gpu/main.c
> index 9614c9422c..e0b6df5b4d 100644
> --- a/contrib/vhost-user-gpu/main.c
> +++ b/contrib/vhost-user-gpu/main.c
> @@ -1160,6 +1160,10 @@ main(int argc, char *argv[])
>
> if (opt_socket_path) {
> int lsock = unix_listen(opt_socket_path, &error_fatal);
> + if (lsock < 0) {
> + g_printerr("Failed to listen on %s.\n", opt_socket_path);
> + exit(EXIT_FAILURE);
> + }
> fd = accept(lsock, NULL, NULL);
> close(lsock);
> } else {
> diff --git a/contrib/vhost-user-input/main.c b/contrib/vhost-user-input/main.c
> index 8d493f598e..8b854117f5 100644
> --- a/contrib/vhost-user-input/main.c
> +++ b/contrib/vhost-user-input/main.c
> @@ -367,6 +367,10 @@ main(int argc, char *argv[])
>
> if (opt_socket_path) {
> int lsock = unix_listen(opt_socket_path, &error_fatal);
> + if (lsock < 0) {
> + g_printerr("Failed to listen on %s.\n", opt_socket_path);
> + exit(EXIT_FAILURE);
> + }
> fd = accept(lsock, NULL, NULL);
> close(lsock);
> } else {
> --
> 2.22.0.rc2.384.g1a9a72ea1d
>
Maybe better to just assert(lsock >= 0) ?
(I hadn't noticed the &error_fatal -- it means this new code
is unreachable.)
thanks
-- PMM
© 2016 - 2026 Red Hat, Inc.