* [PATCH nft 1/3,v2] src: use malloc() and free() from cli and main
@ 2019-07-04 22:59 Pablo Neira Ayuso
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
0 siblings, 2 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2019-07-04 22:59 UTC (permalink / raw)
To: netfilter-devel; +Cc: phil
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH nft 2/3] main: replace NFT_EXIT_NOMEM by EXIT_FAILURE
2019-07-04 22:59 [PATCH nft 1/3,v2] src: use malloc() and free() from cli and main Pablo Neira Ayuso
@ 2019-07-04 22:59 ` Pablo Neira Ayuso
2019-07-04 22:59 ` [PATCH nft 3/3] cli: remove useless #include headers Pablo Neira Ayuso
1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2019-07-04 22:59 UTC (permalink / raw)
To: netfilter-devel; +Cc: phil
The main.c file always uses either EXIT_FAILURE or EXIT_SUCCESS, replace
this.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/main.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/main.c b/src/main.c
index 694611224d07..9db3d9aa0a15 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,7 +19,6 @@
#include <sys/types.h>
#include <nftables/libnftables.h>
-#include <nftables.h>
#include <utils.h>
#include <cli.h>
@@ -307,7 +306,7 @@ int main(int argc, char * const *argv)
if (buf == NULL) {
fprintf(stderr, "%s:%u: Memory allocation failure\n",
__FILE__, __LINE__);
- exit(NFT_EXIT_NOMEM);
+ exit(EXIT_FAILURE);
}
for (i = optind; i < argc; i++) {
strcat(buf, argv[i]);
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH nft 3/3] cli: remove useless #include headers
2019-07-04 22:59 [PATCH nft 1/3,v2] src: use malloc() and free() from cli and main Pablo Neira Ayuso
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 ` Pablo Neira Ayuso
1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2019-07-04 22:59 UTC (permalink / raw)
To: netfilter-devel; +Cc: phil
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/cli.h | 1 +
src/cli.c | 8 +-------
2 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/include/cli.h b/include/cli.h
index 3780e0917969..c1819d464327 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -1,6 +1,7 @@
#ifndef _NFT_CLI_H_
#define _NFT_CLI_H_
+#include <nftables/libnftables.h>
#include <config.h>
struct parser_state;
diff --git a/src/cli.c b/src/cli.c
index bbdd0fdbeeb8..f1e89926f2bc 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -24,14 +24,8 @@
#include <readline/readline.h>
#include <readline/history.h>
-#include <nftables.h>
-#include <parser.h>
-#include <erec.h>
-#include <utils.h>
-#include <iface.h>
#include <cli.h>
-
-#include <libmnl/libmnl.h>
+#include <list.h>
#define CMDLINE_HISTFILE ".nft.history"
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-04 22:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-04 22:59 [PATCH nft 1/3,v2] src: use malloc() and free() from cli and main Pablo Neira Ayuso
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
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).