]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
libnftables: drop gmp_init() and mp_set_memory_functions()
authorThomas Haller <thaller@redhat.com>
Tue, 19 Sep 2023 12:36:16 +0000 (14:36 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 19 Sep 2023 15:26:27 +0000 (17:26 +0200)
Setting global handles for libgmp via mp_set_memory_functions() is very
ugly. When we don't use mini-gmp, then potentially there are other users
of the library in the same process, and every process fighting about the
allocation functions is not gonna work.

It also means, we must not reset the allocation functions after somebody
already allocated GMP data with them. Which we cannot ensure, as we
don't know what other parts of the process are doing.

It's also unnecessary. The default allocation functions for gmp and
mini-gmp already abort the process on allocation failure ([1], [2]),
just like our xmalloc().

Just don't do this.

[1] https://gmplib.org/repo/gmp/file/8225bdfc499f/memory.c#l37
[2] https://git.netfilter.org/nftables/tree/src/mini-gmp.c?id=6d19a902c1d77cb51b940b1ce65f31b1cad38b74#n286

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/nftables.h
src/gmputil.c
src/libnftables.c

index b9b2b01c26897aedcb7533715cfaa64b4850e953..4b7c335928dadc18a96921453fc53c3f3d3128c4 100644 (file)
@@ -224,7 +224,6 @@ struct input_descriptor {
 
 void ct_label_table_init(struct nft_ctx *ctx);
 void mark_table_init(struct nft_ctx *ctx);
-void gmp_init(void);
 void realm_table_rt_init(struct nft_ctx *ctx);
 void devgroup_table_init(struct nft_ctx *ctx);
 void xt_init(void);
index 7f65630db59c56c6ba433ff515c9e2d9421d35f7..bf472c65de48b251e26c5657d0d33875fb5c88ec 100644 (file)
@@ -197,13 +197,3 @@ int mpz_vfprintf(FILE *fp, const char *f, va_list args)
        return n;
 }
 #endif
-
-static void *gmp_xrealloc(void *ptr, size_t old_size, size_t new_size)
-{
-       return xrealloc(ptr, new_size);
-}
-
-void gmp_init(void)
-{
-       mp_set_memory_functions(xmalloc, gmp_xrealloc, NULL);
-}
index 7d36577dbf5fc1240a50bb5cda104f8477ea742d..cedd710bf898d185f98a658526ff4cc5d230d497 100644 (file)
@@ -196,7 +196,6 @@ struct nft_ctx *nft_ctx_new(uint32_t flags)
 
        if (!init_once) {
                init_once = true;
-               gmp_init();
 #ifdef HAVE_LIBXTABLES
                xt_init();
 #endif