Skip to contentSkip to conversation

Some minor fixes

PATCH In review Phil Sutter 2 participants 7 messages Nov 21, 2019 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

cover Some minor fixes

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
Signature · 1 line
2.24.0
author reviewer
#1 lore raw

PATCH 1/3 Add .gitignore

Ignore temporary files, created arptables-legacy binary and any present tags file.

---
 .gitignore | 4 ++++
 1 file changed, 4 insertions(+)
 create mode 100644 .gitignore
.gitignore new file +4 -0
new file mode 100644
index 0000000000000..b2ea4a177d410
@@ -0,0 +1,4 @@
+*.a
+*.o
+/arptables-legacy
+/tags
Signature · 1 line
2.24.0
author reviewer
#3 lore raw

PATCH 2/3 Eliminate compiler warning about size passed to strncmp()

In reply to Phil Sutter

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")
---
 arptables.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arptables.c +1 -2
index 09c9ca25217d0..2b6618c2511ef 100644
@@ -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);
Signature · 1 line
2.24.0
maintainer Acked-by on v1 2/3
#4 lore raw

Re: [arptables PATCH 2/3] Eliminate compiler warning about size passed to strncmp()

Quoted 9 lines · Phil Sutter

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")
author reviewer
#5 lore raw

PATCH 3/3 libarptc: Simplify alloc_handle by using calloc()

In reply to Phil Sutter

No need to explicitly set fields to zero when using calloc().

---
 libarptc/libarptc_incl.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
libarptc/libarptc_incl.c +3 -8
index ca23da6474990..c4d5de3f39a15 100644
@@ -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;
 }
Signature · 1 line
2.24.0