From 115a84fa3c13eb9524089b48d4fa794222de4bfc Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 11 Jul 2024 13:24:53 +0200 Subject: nl80211: gracefully handle illegal netlink error code Some generic netlink commands, e.g. `HWSIM_CMD_NEW_RADIO` might reply with a bogus netlink error message containing a positive error code, leading to an infinite loop in `uc_nl_request()`. Gracefully deal with such occurrences by remapping the error code to `NLE_RANGE` with a custom message. Signed-off-by: Jo-Philipp Wich --- lib/nl80211.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/nl80211.c b/lib/nl80211.c index fcaffb7..1cd7534 100644 --- a/lib/nl80211.c +++ b/lib/nl80211.c @@ -65,6 +65,9 @@ __attribute__((format(printf, 2, 3))) static void set_error(int errcode, const char *fmt, ...) { va_list ap; + if (errcode == -(NLE_MAX + 1)) + return; + free(last_error.msg); last_error.code = errcode; @@ -2080,7 +2083,15 @@ cb_errno(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg) { int *ret = arg; - *ret = err->error; + if (err->error > 0) { + set_error(NLE_RANGE, + "Illegal error code %d in netlink reply", err->error); + + *ret = -(NLE_MAX + 1); + } + else { + *ret = -nl_syserr2nlerr(err->error); + } return NL_STOP; } -- cgit v1.2.3