From 71ae4e960357516c655bda9495db17bc0abea5b3 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sat, 15 Jan 2022 18:50:21 +0100 Subject: libnftables: use xrealloc() Instead of realloc(), so process stops execution in case memory allocation fails. Signed-off-by: Pablo Neira Ayuso --- src/libnftables.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/libnftables.c b/src/libnftables.c index bd71ae9e..dc0932bd 100644 --- a/src/libnftables.c +++ b/src/libnftables.c @@ -128,9 +128,7 @@ int nft_ctx_add_var(struct nft_ctx *ctx, const char *var) if (!separator) return -1; - tmp = realloc(ctx->vars, (pcount + 1) * sizeof(struct nft_vars)); - if (!tmp) - return -1; + tmp = xrealloc(ctx->vars, (pcount + 1) * sizeof(struct nft_vars)); *separator = '\0'; value = separator + 1; @@ -162,9 +160,7 @@ int nft_ctx_add_include_path(struct nft_ctx *ctx, const char *path) char **tmp; int pcount = ctx->num_include_paths; - tmp = realloc(ctx->include_paths, (pcount + 1) * sizeof(char *)); - if (!tmp) - return -1; + tmp = xrealloc(ctx->include_paths, (pcount + 1) * sizeof(char *)); ctx->include_paths = tmp; @@ -465,7 +461,7 @@ static char *stdin_to_buffer(void) consumed += numbytes; if (consumed == bufsiz) { bufsiz *= 2; - buf = realloc(buf, bufsiz); + buf = xrealloc(buf, bufsiz); } numbytes = read(STDIN_FILENO, buf + consumed, bufsiz - consumed); } -- cgit v1.2.3