summaryrefslogtreecommitdiffstats
path: root/src/internal.h
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2014-04-05 20:31:37 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2014-04-07 10:48:55 +0200
commite7ff8bab1f72c5b45ead02a0e5302359616e5cdc (patch)
treeebf1c2ee0f3143539f142492c7d4e1c046970f2a /src/internal.h
parenta6d9aeb52e3c40bf064c49d869b71a27506c080a (diff)
src: fix bogus assertion for unset attributes
If you try to obtain an unset attribute, you hit an assertion error that should not happen. Fix this by checking if the attribute is unset, otherwise skip the assertion checking. Now that we have that nft_assert takes the data parameter, we can also validate if someone is using the setter passing NULL, which is illegal. So let's add an assertion for that as well. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/internal.h')
-rw-r--r--src/internal.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/internal.h b/src/internal.h
index 3216bc6..ba994c8 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -189,15 +189,17 @@ struct nft_set_elem {
void __nft_assert_fail(uint16_t attr, const char *filename, int line);
-#define nft_assert(attr, expr) \
- ((expr) \
+#define nft_assert(val, attr, expr) \
+ ((!val || expr) \
? (void)0 \
: __nft_assert_fail(attr, __FILE__, __LINE__))
-#define nft_assert_validate(_validate_array, _attr, _data_len) \
-({ \
- if (_validate_array[_attr]) \
- nft_assert(attr, _validate_array[_attr] == _data_len); \
+#define nft_assert_validate(data, _validate_array, _attr, _data_len) \
+({ \
+ if (!data) \
+ __nft_assert_fail(attr, __FILE__, __LINE__); \
+ if (_validate_array[_attr]) \
+ nft_assert(data, attr, _validate_array[_attr] == _data_len); \
})
#endif