diff mbox series

[2/3] can-host-socketcan: Fix crash when 'if' option is not set

Message ID 20201008202713.1416823-3-ehabkost@redhat.com
State Superseded
Headers show
Series Fix some crashes when using -object | expand

Commit Message

Eduardo Habkost Oct. 8, 2020, 8:27 p.m. UTC
Fix the following crash:

  $ qemu-system-x86_64 -object can-host-socketcan,id=obj0
  Segmentation fault (core dumped)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Cc: Vikram Garhwal <fnu.vikram@xilinx.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: qemu-devel@nongnu.org
---
 net/can/can_socketcan.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Pavel Pisa Oct. 8, 2020, 10:18 p.m. UTC | #1
Thanks for catching missing test

On Thursday 08 of October 2020 22:27:12 Eduardo Habkost wrote:
> Fix the following crash:

>

>   $ qemu-system-x86_64 -object can-host-socketcan,id=obj0

>   Segmentation fault (core dumped)

>

> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>

> ---

> Cc: Pavel Pisa <pisa@cmp.felk.cvut.cz>

> Cc: Vikram Garhwal <fnu.vikram@xilinx.com>

> Cc: Jason Wang <jasowang@redhat.com>

> Cc: qemu-devel@nongnu.org

> ---

>  net/can/can_socketcan.c | 5 +++++

>  1 file changed, 5 insertions(+)

>

> diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c

> index 92b1f79385..4b68f60c6b 100644

> --- a/net/can/can_socketcan.c

> +++ b/net/can/can_socketcan.c

> @@ -194,6 +194,11 @@ static void can_host_socketcan_connect(CanHostState

> *ch, Error **errp) struct sockaddr_can addr;

>      struct ifreq ifr;

>

> +    if (!c->ifname) {

> +        error_setg(errp, "'if' property not set");

> +        return;

> +    }

> +

>      /* open socket */

>      s = qemu_socket(PF_CAN, SOCK_RAW, CAN_RAW);

>      if (s < 0) {


Acked-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>


-- 
                Pavel Pisa
    e-mail:     pisa@cmp.felk.cvut.cz
    Department of Control Engineering FEE CVUT
    Karlovo namesti 13, 121 35, Prague 2
    university: http://dce.fel.cvut.cz/
    personal:   http://cmp.felk.cvut.cz/~pisa
    projects:   https://www.openhub.net/accounts/ppisa
    CAN related:http://canbus.pages.fel.cvut.cz/
Li Qiang Oct. 9, 2020, 3:17 p.m. UTC | #2
Eduardo Habkost <ehabkost@redhat.com> 于2020年10月9日周五 上午4:31写道:
>
> Fix the following crash:
>
>   $ qemu-system-x86_64 -object can-host-socketcan,id=obj0
>   Segmentation fault (core dumped)
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>

Reviewed-by: Li Qiang <liq3ea@gmail.com>

> ---
> Cc: Pavel Pisa <pisa@cmp.felk.cvut.cz>
> Cc: Vikram Garhwal <fnu.vikram@xilinx.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: qemu-devel@nongnu.org
> ---
>  net/can/can_socketcan.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c
> index 92b1f79385..4b68f60c6b 100644
> --- a/net/can/can_socketcan.c
> +++ b/net/can/can_socketcan.c
> @@ -194,6 +194,11 @@ static void can_host_socketcan_connect(CanHostState *ch, Error **errp)
>      struct sockaddr_can addr;
>      struct ifreq ifr;
>
> +    if (!c->ifname) {
> +        error_setg(errp, "'if' property not set");
> +        return;
> +    }
> +
>      /* open socket */
>      s = qemu_socket(PF_CAN, SOCK_RAW, CAN_RAW);
>      if (s < 0) {
> --
> 2.26.2
>
>
Vikram Garhwal Oct. 12, 2020, 4:23 p.m. UTC | #3
On Thu, Oct 08, 2020 at 04:27:12PM -0400, Eduardo Habkost wrote:
> Fix the following crash:
>
>   $ qemu-system-x86_64 -object can-host-socketcan,id=obj0
>   Segmentation fault (core dumped)
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Vikram Garhwal <fnu.vikram@xilinx.com>
> ---
> Cc: Pavel Pisa <pisa@cmp.felk.cvut.cz>
> Cc: Vikram Garhwal <fnu.vikram@xilinx.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: qemu-devel@nongnu.org
> ---
>  net/can/can_socketcan.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c
> index 92b1f79385..4b68f60c6b 100644
> --- a/net/can/can_socketcan.c
> +++ b/net/can/can_socketcan.c
> @@ -194,6 +194,11 @@ static void can_host_socketcan_connect(CanHostState *ch, Error **errp)
>      struct sockaddr_can addr;
>      struct ifreq ifr;
>
> +    if (!c->ifname) {
> +        error_setg(errp, "'if' property not set");
> +        return;
> +    }
> +
>      /* open socket */
>      s = qemu_socket(PF_CAN, SOCK_RAW, CAN_RAW);
>      if (s < 0) {
> --
> 2.26.2
>
diff mbox series

Patch

diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c
index 92b1f79385..4b68f60c6b 100644
--- a/net/can/can_socketcan.c
+++ b/net/can/can_socketcan.c
@@ -194,6 +194,11 @@  static void can_host_socketcan_connect(CanHostState *ch, Error **errp)
     struct sockaddr_can addr;
     struct ifreq ifr;
 
+    if (!c->ifname) {
+        error_setg(errp, "'if' property not set");
+        return;
+    }
+
     /* open socket */
     s = qemu_socket(PF_CAN, SOCK_RAW, CAN_RAW);
     if (s < 0) {