Hi
On Mon, Oct 8, 2018 at 9:45 PM Markus Armbruster wrote:
>
> Calling error_report() in a function that takes an Error ** argument
> is suspicious. net_socket_fd_init() does that, and then fails without
> setting an error. Wrong. I didn't analyze how exactly this can
> break. A caller that reports the error on failure would crash.
>
> Broken when commit c37f0bb1d0d (v2.11.0) converted the function to
> Error. Fix by calling error_setg() instead of error_report().
>
> Fixes: c37f0bb1d0d24e3a6b5f4659bb305913dcb798a6
> Cc: Jason Wang
> Signed-off-by: Markus Armbruster
Reviewed-by: Marc-André Lureau
> ---
> net/socket.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/net/socket.c b/net/socket.c
> index 6917fbcbf5..90ef3517be 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -453,8 +453,8 @@ static NetSocketState *net_socket_fd_init(NetClientState
> *peer,
> case SOCK_STREAM:
> return net_socket_fd_init_stream(peer, model, name, fd,
> is_connected);
> default:
> -error_report("socket type=%d for fd=%d must be either"
> - " SOCK_DGRAM or SOCK_STREAM", so_type, fd);
> +error_setg(errp, "socket type=%d for fd=%d must be either"
> + " SOCK_DGRAM or SOCK_STREAM", so_type, fd);
> closesocket(fd);
> }
> return NULL;
> --
> 2.17.1
>
>
--
Marc-André Lureau