Skip to content

Commit

Permalink
nfnetlink: properly handle nl_recvmsgs() failures
Browse files Browse the repository at this point in the history
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
  • Loading branch information
jow- committed Apr 10, 2020
1 parent 95cced5 commit 33c77cb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions nfnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ nfnetlink_dump(bool allow_insert)
.res_id = 0, //htons(res_id),
};

int err;
int err, ret;

errno = ENOMEM;

Expand Down Expand Up @@ -454,8 +454,20 @@ nfnetlink_dump(bool allow_insert)
if (nl_send_auto_complete(nl, req) < 0)
goto err;

for (err = 1; err > 0; )
nl_recvmsgs(nl, cb);
for (err = 1; err > 0; ) {
ret = nl_recvmsgs(nl, cb);

if (ret <= 0) {
if (ret < 0) {
fprintf(stderr, "Netlink receive failure: %s\n",
nl_geterror(ret));

errno = (-ret == NLE_NOMEM) ? ENOBUFS : EIO;
}

break;
}
}

errno = -err;

Expand Down

0 comments on commit 33c77cb

Please sign in to comment.