The function may return -1 (and set errno). Assume it will leave addr_len value unchanged, so checking is necessary to not hide the error. Fixes: 4248314d40187 ("nfnl: fix compilation warning with gcc-4.7") Signed-off-by: Phil Sutter <phil@xxxxxx> --- src/libnfnetlink.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libnfnetlink.c b/src/libnfnetlink.c index 1cb6a820fee3d..667e5ef8f82a5 100644 --- a/src/libnfnetlink.c +++ b/src/libnfnetlink.c @@ -210,7 +210,8 @@ struct nfnl_handle *nfnl_open(void) nfnlh->peer.nl_family = AF_NETLINK; addr_len = sizeof(nfnlh->local); - getsockname(nfnlh->fd, (struct sockaddr *)&nfnlh->local, &addr_len); + if (getsockname(nfnlh->fd, (struct sockaddr *)&nfnlh->local, &addr_len)) + goto err_close; if (addr_len != sizeof(nfnlh->local)) { errno = EINVAL; goto err_close; @@ -231,7 +232,8 @@ struct nfnl_handle *nfnl_open(void) /* use getsockname to get the netlink pid that the kernel assigned us */ addr_len = sizeof(nfnlh->local); - getsockname(nfnlh->fd, (struct sockaddr *)&nfnlh->local, &addr_len); + if (getsockname(nfnlh->fd, (struct sockaddr *)&nfnlh->local, &addr_len)) + goto err_close; if (addr_len != sizeof(nfnlh->local)) { errno = EINVAL; goto err_close; -- 2.34.1