* [arptables PATCH 0/3] Some minor fixes
@ 2019-11-21 11:15 Phil Sutter
2019-11-21 11:15 ` [arptables PATCH 1/3] Add .gitignore Phil Sutter
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Phil Sutter @ 2019-11-21 11:15 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: netfilter-devel
These are some patches I found while cleaning up the attic. They add a
gitignore file, fix for a compiler warning and simplify code in libarptc
a bit.
Phil Sutter (3):
Add .gitignore
Eliminate compiler warning about size passed to strncmp()
libarptc: Simplify alloc_handle by using calloc()
.gitignore | 4 ++++
arptables.c | 3 +--
libarptc/libarptc_incl.c | 11 +++--------
3 files changed, 8 insertions(+), 10 deletions(-)
create mode 100644 .gitignore
--
2.24.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [arptables PATCH 1/3] Add .gitignore
2019-11-21 11:15 [arptables PATCH 0/3] Some minor fixes Phil Sutter
@ 2019-11-21 11:15 ` Phil Sutter
2019-11-21 13:45 ` Pablo Neira Ayuso
2019-11-21 11:15 ` [arptables PATCH 2/3] Eliminate compiler warning about size passed to strncmp() Phil Sutter
2019-11-21 11:15 ` [arptables PATCH 3/3] libarptc: Simplify alloc_handle by using calloc() Phil Sutter
2 siblings, 1 reply; 7+ messages in thread
From: Phil Sutter @ 2019-11-21 11:15 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: netfilter-devel
Ignore temporary files, created arptables-legacy binary and any present
tags file.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
.gitignore | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 .gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000..b2ea4a177d410
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.a
+*.o
+/arptables-legacy
+/tags
--
2.24.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [arptables PATCH 2/3] Eliminate compiler warning about size passed to strncmp()
2019-11-21 11:15 [arptables PATCH 0/3] Some minor fixes Phil Sutter
2019-11-21 11:15 ` [arptables PATCH 1/3] Add .gitignore Phil Sutter
@ 2019-11-21 11:15 ` Phil Sutter
2019-11-21 13:45 ` Pablo Neira Ayuso
2019-11-21 11:15 ` [arptables PATCH 3/3] libarptc: Simplify alloc_handle by using calloc() Phil Sutter
2 siblings, 1 reply; 7+ messages in thread
From: Phil Sutter @ 2019-11-21 11:15 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: netfilter-devel
Gcc complains about the size being equal to destination size, despite
the nul character being explicitly set in following line.
Reduce size by one to make gcc happy. While being at it, drop the
explicit nul character assignment - it is not needed as the buffer was
allocated by calloc().
Fixes: 8f586939999e0 ("fix potential buffer overflows reported by static analysis")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
arptables.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arptables.c b/arptables.c
index 09c9ca25217d0..2b6618c2511ef 100644
--- a/arptables.c
+++ b/arptables.c
@@ -2065,8 +2065,7 @@ int do_command(int argc, char *argv[], char **table, arptc_handle_t *handle)
target->t = fw_calloc(1, size);
target->t->u.target_size = size;
- strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name));
- target->t->u.user.name[sizeof(target->t->u.user.name)-1] = '\0';
+ strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name) - 1);
target->t->u.user.revision = target->revision;
/*
target->init(target->t, &fw.nfcache);
--
2.24.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [arptables PATCH 3/3] libarptc: Simplify alloc_handle by using calloc()
2019-11-21 11:15 [arptables PATCH 0/3] Some minor fixes Phil Sutter
2019-11-21 11:15 ` [arptables PATCH 1/3] Add .gitignore Phil Sutter
2019-11-21 11:15 ` [arptables PATCH 2/3] Eliminate compiler warning about size passed to strncmp() Phil Sutter
@ 2019-11-21 11:15 ` Phil Sutter
2019-11-21 13:46 ` Pablo Neira Ayuso
2 siblings, 1 reply; 7+ messages in thread
From: Phil Sutter @ 2019-11-21 11:15 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: netfilter-devel
No need to explicitly set fields to zero when using calloc().
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
libarptc/libarptc_incl.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/libarptc/libarptc_incl.c b/libarptc/libarptc_incl.c
index ca23da6474990..c4d5de3f39a15 100644
--- a/libarptc/libarptc_incl.c
+++ b/libarptc/libarptc_incl.c
@@ -191,21 +191,16 @@ alloc_handle(const char *tablename, unsigned int size, unsigned int num_rules)
+ size
+ num_rules * sizeof(struct counter_map);
- if ((h = malloc(len)) == NULL) {
+ if ((h = calloc(1, len)) == NULL) {
errno = ENOMEM;
return NULL;
}
- h->changed = 0;
- h->cache_num_chains = 0;
- h->cache_chain_heads = NULL;
h->counter_map = (void *)h
+ sizeof(STRUCT_TC_HANDLE)
+ size;
- strncpy(h->info.name, tablename, sizeof(h->info.name));
- h->info.name[sizeof(h->info.name)-1] = '\0';
- strncpy(h->entries.name, tablename, sizeof(h->entries.name));
- h->entries.name[sizeof(h->entries.name)-1] = '\0';
+ strncpy(h->info.name, tablename, sizeof(h->info.name) - 1);
+ strncpy(h->entries.name, tablename, sizeof(h->entries.name) - 1);
return h;
}
--
2.24.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [arptables PATCH 2/3] Eliminate compiler warning about size passed to strncmp()
2019-11-21 11:15 ` [arptables PATCH 2/3] Eliminate compiler warning about size passed to strncmp() Phil Sutter
@ 2019-11-21 13:45 ` Pablo Neira Ayuso
0 siblings, 0 replies; 7+ messages in thread
From: Pablo Neira Ayuso @ 2019-11-21 13:45 UTC (permalink / raw)
To: Phil Sutter; +Cc: netfilter-devel
On Thu, Nov 21, 2019 at 12:15:58PM +0100, Phil Sutter wrote:
> Gcc complains about the size being equal to destination size, despite
> the nul character being explicitly set in following line.
>
> Reduce size by one to make gcc happy. While being at it, drop the
> explicit nul character assignment - it is not needed as the buffer was
> allocated by calloc().
>
> Fixes: 8f586939999e0 ("fix potential buffer overflows reported by static analysis")
> Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [arptables PATCH 1/3] Add .gitignore
2019-11-21 11:15 ` [arptables PATCH 1/3] Add .gitignore Phil Sutter
@ 2019-11-21 13:45 ` Pablo Neira Ayuso
0 siblings, 0 replies; 7+ messages in thread
From: Pablo Neira Ayuso @ 2019-11-21 13:45 UTC (permalink / raw)
To: Phil Sutter; +Cc: netfilter-devel
On Thu, Nov 21, 2019 at 12:15:57PM +0100, Phil Sutter wrote:
> Ignore temporary files, created arptables-legacy binary and any present
> tags file.
>
> Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [arptables PATCH 3/3] libarptc: Simplify alloc_handle by using calloc()
2019-11-21 11:15 ` [arptables PATCH 3/3] libarptc: Simplify alloc_handle by using calloc() Phil Sutter
@ 2019-11-21 13:46 ` Pablo Neira Ayuso
0 siblings, 0 replies; 7+ messages in thread
From: Pablo Neira Ayuso @ 2019-11-21 13:46 UTC (permalink / raw)
To: Phil Sutter; +Cc: netfilter-devel
On Thu, Nov 21, 2019 at 12:15:59PM +0100, Phil Sutter wrote:
> No need to explicitly set fields to zero when using calloc().
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-11-21 13:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-21 11:15 [arptables PATCH 0/3] Some minor fixes Phil Sutter
2019-11-21 11:15 ` [arptables PATCH 1/3] Add .gitignore Phil Sutter
2019-11-21 13:45 ` Pablo Neira Ayuso
2019-11-21 11:15 ` [arptables PATCH 2/3] Eliminate compiler warning about size passed to strncmp() Phil Sutter
2019-11-21 13:45 ` Pablo Neira Ayuso
2019-11-21 11:15 ` [arptables PATCH 3/3] libarptc: Simplify alloc_handle by using calloc() Phil Sutter
2019-11-21 13:46 ` 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).