summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2024-03-07 13:25:31 +0100
committerPhil Sutter <phil@nwl.cc>2024-04-11 01:27:07 +0200
commit410c245e4811d7888daa456547af58d93d1c63b4 (patch)
tree2fcc85873745dfe6df575fabaa29da81c085a411 /src
parentdf4e259c0537fff58ecdc7b3ec1546fb2da93968 (diff)
obj: Call obj_ops::set with legal attributes only
Refer to obj_ops::nftnl_max_attr field value for the maximum supported attribute value to reject invalid ones upfront. Consequently drop default cases from callbacks' switches which handle all supported attributes. Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'src')
-rw-r--r--src/obj/counter.c2
-rw-r--r--src/obj/ct_expect.c2
-rw-r--r--src/obj/ct_helper.c2
-rw-r--r--src/obj/ct_timeout.c2
-rw-r--r--src/obj/limit.c2
-rw-r--r--src/obj/quota.c2
-rw-r--r--src/obj/secmark.c2
-rw-r--r--src/obj/synproxy.c2
-rw-r--r--src/obj/tunnel.c2
-rw-r--r--src/object.c4
10 files changed, 3 insertions, 19 deletions
diff --git a/src/obj/counter.c b/src/obj/counter.c
index 76a1b20..982da2c 100644
--- a/src/obj/counter.c
+++ b/src/obj/counter.c
@@ -34,8 +34,6 @@ nftnl_obj_counter_set(struct nftnl_obj *e, uint16_t type,
case NFTNL_OBJ_CTR_PKTS:
memcpy(&ctr->pkts, data, sizeof(ctr->pkts));
break;
- default:
- return -1;
}
return 0;
}
diff --git a/src/obj/ct_expect.c b/src/obj/ct_expect.c
index 7e9c5e1..60014dc 100644
--- a/src/obj/ct_expect.c
+++ b/src/obj/ct_expect.c
@@ -35,8 +35,6 @@ static int nftnl_obj_ct_expect_set(struct nftnl_obj *e, uint16_t type,
case NFTNL_OBJ_CT_EXPECT_SIZE:
memcpy(&exp->size, data, sizeof(exp->size));
break;
- default:
- return -1;
}
return 0;
}
diff --git a/src/obj/ct_helper.c b/src/obj/ct_helper.c
index f8aa734..b8b05fd 100644
--- a/src/obj/ct_helper.c
+++ b/src/obj/ct_helper.c
@@ -37,8 +37,6 @@ static int nftnl_obj_ct_helper_set(struct nftnl_obj *e, uint16_t type,
case NFTNL_OBJ_CT_HELPER_L4PROTO:
memcpy(&helper->l4proto, data, sizeof(helper->l4proto));
break;
- default:
- return -1;
}
return 0;
}
diff --git a/src/obj/ct_timeout.c b/src/obj/ct_timeout.c
index ee86231..011d928 100644
--- a/src/obj/ct_timeout.c
+++ b/src/obj/ct_timeout.c
@@ -162,8 +162,6 @@ static int nftnl_obj_ct_timeout_set(struct nftnl_obj *e, uint16_t type,
memcpy(timeout->timeout, data,
sizeof(uint32_t) * NFTNL_CTTIMEOUT_ARRAY_MAX);
break;
- default:
- return -1;
}
return 0;
}
diff --git a/src/obj/limit.c b/src/obj/limit.c
index 1c54bbc..83cb193 100644
--- a/src/obj/limit.c
+++ b/src/obj/limit.c
@@ -42,8 +42,6 @@ static int nftnl_obj_limit_set(struct nftnl_obj *e, uint16_t type,
case NFTNL_OBJ_LIMIT_FLAGS:
memcpy(&limit->flags, data, sizeof(limit->flags));
break;
- default:
- return -1;
}
return 0;
}
diff --git a/src/obj/quota.c b/src/obj/quota.c
index a39d552..665d7ca 100644
--- a/src/obj/quota.c
+++ b/src/obj/quota.c
@@ -36,8 +36,6 @@ static int nftnl_obj_quota_set(struct nftnl_obj *e, uint16_t type,
case NFTNL_OBJ_QUOTA_FLAGS:
memcpy(&quota->flags, data, sizeof(quota->flags));
break;
- default:
- return -1;
}
return 0;
}
diff --git a/src/obj/secmark.c b/src/obj/secmark.c
index c78e35f..83cd1dc 100644
--- a/src/obj/secmark.c
+++ b/src/obj/secmark.c
@@ -30,8 +30,6 @@ static int nftnl_obj_secmark_set(struct nftnl_obj *e, uint16_t type,
case NFTNL_OBJ_SECMARK_CTX:
snprintf(secmark->ctx, sizeof(secmark->ctx), "%s", (const char *)data);
break;
- default:
- return -1;
}
return 0;
}
diff --git a/src/obj/synproxy.c b/src/obj/synproxy.c
index d259a51..f7c7762 100644
--- a/src/obj/synproxy.c
+++ b/src/obj/synproxy.c
@@ -27,8 +27,6 @@ static int nftnl_obj_synproxy_set(struct nftnl_obj *e, uint16_t type,
case NFTNL_OBJ_SYNPROXY_FLAGS:
memcpy(&synproxy->flags, data, data_len);
break;
- default:
- return -1;
}
return 0;
}
diff --git a/src/obj/tunnel.c b/src/obj/tunnel.c
index 19a3639..72985ee 100644
--- a/src/obj/tunnel.c
+++ b/src/obj/tunnel.c
@@ -76,8 +76,6 @@ nftnl_obj_tunnel_set(struct nftnl_obj *e, uint16_t type,
case NFTNL_OBJ_TUNNEL_ERSPAN_V2_DIR:
memcpy(&tun->u.tun_erspan.u.v2.dir, data, sizeof(tun->u.tun_erspan.u.v2.dir));
break;
- default:
- return -1;
}
return 0;
}
diff --git a/src/object.c b/src/object.c
index d363725..bd4e51a 100644
--- a/src/object.c
+++ b/src/object.c
@@ -149,7 +149,9 @@ int nftnl_obj_set_data(struct nftnl_obj *obj, uint16_t attr,
obj->user.len = data_len;
break;
default:
- if (!obj->ops)
+ if (!obj->ops ||
+ attr < NFTNL_OBJ_BASE ||
+ attr > obj->ops->nftnl_max_attr)
return -1;
if (obj->ops->set(obj, attr, data, data_len) < 0)