summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2024-07-11 13:24:53 +0200
committerJo-Philipp Wich <jo@mein.io>2024-07-11 14:08:01 +0200
commit115a84fa3c13eb9524089b48d4fa794222de4bfc (patch)
treeb015262d242a155c278f2b19ae066d2063703b13
parent1a8a0bcf725520820802ad433db22d8f64fbed6c (diff)
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 <jo@mein.io>
-rw-r--r--lib/nl80211.c13
1 files changed, 12 insertions, 1 deletions
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;
}