summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2019-08-14 10:07:22 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2019-08-14 15:17:24 +0200
commit8202d0fb87c540717667bc73aab7461961973b65 (patch)
tree6eb2bc7a017b1b0a9f5efc91a292e0a5d4b14c5a /include
parent877baf9538f66f8f238a3e278a1a994734382678 (diff)
gmputil: assert length is non-zero
Importing, exporting and byteswapping zero length data should not happen. Use macro definition so we know from where the assertion is triggered in the code for easier diagnosing in the future. When importing datatype.h from gmputil.h, it seems gcc complains on missing declarations in json.h. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include')
-rw-r--r--include/gmputil.h33
-rw-r--r--include/json.h4
2 files changed, 30 insertions, 7 deletions
diff --git a/include/gmputil.h b/include/gmputil.h
index ad63d67b..0cb85a7d 100644
--- a/include/gmputil.h
+++ b/include/gmputil.h
@@ -52,12 +52,31 @@ extern uint32_t mpz_get_be32(const mpz_t op);
extern uint16_t mpz_get_be16(const mpz_t op);
enum byteorder;
-extern void *mpz_export_data(void *data, const mpz_t op,
- enum byteorder byteorder,
- unsigned int len);
-extern void mpz_import_data(mpz_t rop, const void *data,
- enum byteorder byteorder,
- unsigned int len);
-extern void mpz_switch_byteorder(mpz_t rop, unsigned int len);
+extern void *__mpz_export_data(void *data, const mpz_t op,
+ enum byteorder byteorder, unsigned int len);
+extern void __mpz_import_data(mpz_t rop, const void *data,
+ enum byteorder byteorder, unsigned int len);
+extern void __mpz_switch_byteorder(mpz_t rop, unsigned int len);
+
+#include <assert.h>
+#include <datatype.h>
+
+#define mpz_export_data(data, op, byteorder, len) \
+{ \
+ assert(len > 0); \
+ __mpz_export_data(data, op, byteorder, len); \
+}
+
+#define mpz_import_data(rop, data, byteorder, len) \
+{ \
+ assert(len > 0); \
+ __mpz_import_data(rop, data, byteorder, len); \
+}
+
+#define mpz_switch_byteorder(rop, len) \
+{ \
+ assert(len > 0); \
+ __mpz_switch_byteorder(rop, len); \
+}
#endif /* NFTABLES_GMPUTIL_H */
diff --git a/include/json.h b/include/json.h
index 7f2df7c8..20d6c2a4 100644
--- a/include/json.h
+++ b/include/json.h
@@ -15,6 +15,10 @@ struct stmt;
struct symbol_table;
struct table;
struct netlink_mon_handler;
+struct nft_ctx;
+struct location;
+struct output_ctx;
+struct list_head;
#ifdef HAVE_LIBJANSSON