From: Florian Westphal Date: Sun, 19 Feb 2017 21:59:42 +0000 (+0100) Subject: object: fix crash when object ops is null X-Git-Tag: libnftnl-1.0.8~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ef9ba3ecb4323a200015cfb5f91c6eb9972d32e;p=thirdparty%2Flibnftnl.git object: fix crash when object ops is null when debugging nft with invalid object type (during development), this will crash here with null deref. Print (unknown) instead if obj->ops is null. Signed-off-by: Florian Westphal Acked-by: Pablo Neira Ayuso --- diff --git a/src/object.c b/src/object.c index 62fa48af..773eff6a 100644 --- a/src/object.c +++ b/src/object.c @@ -396,10 +396,11 @@ static int nftnl_obj_snprintf_dflt(char *buf, size_t size, const struct nftnl_obj *obj, uint32_t type, uint32_t flags) { + const char *name = obj->ops ? obj->ops->name : "(unknown)"; int ret, len = size, offset = 0; ret = snprintf(buf, size, "table %s name %s use %u [ %s ", - obj->table, obj->name, obj->use, obj->ops->name); + obj->table, obj->name, obj->use, name); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); if (obj->ops) {