diff mbox

netlink: do not SIGSEGV when socket() fails

Message ID 1386184340-74134-1-git-send-email-shawn@churchofgit.com
State Changes Requested
Headers show

Commit Message

Shawn Landden Dec. 4, 2013, 7:12 p.m. UTC
---
 src/netlink.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Arturo Borrero Dec. 4, 2013, 7:30 p.m. UTC | #1
On 4 December 2013 20:12, Shawn Landden <shawn@churchofgit.com> wrote:
> ---
>  src/netlink.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>

Hi!

I would suggest to provide a description and a Signed-off-by line
within the patch.
Also, a small trace may help others (like me) to understand the situation.

> diff --git a/src/netlink.c b/src/netlink.c
> index 533634a..664487d 100644
> --- a/src/netlink.c
> +++ b/src/netlink.c
> @@ -33,8 +33,11 @@ static struct mnl_socket *nf_sock;
>  static void __init netlink_open_sock(void)
>  {
>         nf_sock = mnl_socket_open(NETLINK_NETFILTER);
> -       if (nf_sock == NULL)
> +       if (nf_sock == NULL) {
> +                fprintf(fdopen(STDERR_FILENO, "a"), "Could not open AF_NETLINK socket: %s\n",
> +                                        strerror(errno));

In your patch, the code seem indented with spaces. Tabs are used all
around the nft code.
Also, the second line should be aligned with the position+1 of first
'(' character of fprintf.

bonus: please consider adding a tag to the [PATCH] subject, like [nft
PATCH] or [libmnl PATCH].

regards.
diff mbox

Patch

diff --git a/src/netlink.c b/src/netlink.c
index 533634a..664487d 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -33,8 +33,11 @@  static struct mnl_socket *nf_sock;
 static void __init netlink_open_sock(void)
 {
 	nf_sock = mnl_socket_open(NETLINK_NETFILTER);
-	if (nf_sock == NULL)
+	if (nf_sock == NULL) {
+                fprintf(fdopen(STDERR_FILENO, "a"), "Could not open AF_NETLINK socket: %s\n",
+                                        strerror(errno));
 		memory_allocation_error();
+        }
 
 	fcntl(mnl_socket_get_fd(nf_sock), F_SETFL, O_NONBLOCK);
 	mnl_batch_init();
@@ -42,7 +45,8 @@  static void __init netlink_open_sock(void)
 
 static void __exit netlink_close_sock(void)
 {
-	mnl_socket_close(nf_sock);
+        if (nf_sock)
+                mnl_socket_close(nf_sock);
 }
 
 int netlink_io_error(struct netlink_ctx *ctx, const struct location *loc,