netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: phil@nwl.cc
Subject: [PATCH nft 1/3,v2] src: use malloc() and free() from cli and main
Date: Fri,  5 Jul 2019 00:59:18 +0200	[thread overview]
Message-ID: <20190704225920.3671-1-pablo@netfilter.org> (raw)

xmalloc() and xfree() are internal symbols of the library, do not use
them.

Fixes: 16543a0136c0 ("libnftables: export public symbols only")
Reported-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v2: exit() in case of OOM from cli

 src/cli.c  | 12 +++++++++---
 src/main.c |  2 +-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/cli.c b/src/cli.c
index ca3869abe335..bbdd0fdbeeb8 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -63,9 +63,15 @@ static char *cli_append_multiline(char *line)
 		rl_set_prompt(".... ");
 	} else {
 		len += strlen(multiline);
-		s = xmalloc(len + 1);
+		s = malloc(len + 1);
+		if (!s) {
+			fprintf(stderr, "%s:%u: Memory allocation failure\n",
+				__FILE__, __LINE__);
+			cli_exit();
+			exit(EXIT_FAILURE);
+		}
 		snprintf(s, len + 1, "%s%s", multiline, line);
-		xfree(multiline);
+		free(multiline);
 		multiline = s;
 	}
 	line = NULL;
@@ -111,7 +117,7 @@ static void cli_complete(char *line)
 		add_history(line);
 
 	nft_run_cmd_from_buffer(cli_nft, line);
-	xfree(line);
+	free(line);
 }
 
 static char **cli_completion(const char *text, int start, int end)
diff --git a/src/main.c b/src/main.c
index 8e6c897cdd36..694611224d07 100644
--- a/src/main.c
+++ b/src/main.c
@@ -329,7 +329,7 @@ int main(int argc, char * const *argv)
 		exit(EXIT_FAILURE);
 	}
 
-	xfree(buf);
+	free(buf);
 	nft_ctx_free(nft);
 
 	return rc;
-- 
2.11.0


             reply	other threads:[~2019-07-04 22:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-04 22:59 Pablo Neira Ayuso [this message]
2019-07-04 22:59 ` [PATCH nft 2/3] main: replace NFT_EXIT_NOMEM by EXIT_FAILURE Pablo Neira Ayuso
2019-07-04 22:59 ` [PATCH nft 3/3] cli: remove useless #include headers Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190704225920.3671-1-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=phil@nwl.cc \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).