|
|
0890d3 |
From 103040a94970a52dde285a24f0fbb5193ea74d84 Mon Sep 17 00:00:00 2001
|
|
|
0890d3 |
From: =?UTF-8?q?Jarom=C3=ADr=20Kon=C4=8Dick=C3=BD?= <jkoncick@redhat.com>
|
|
|
0890d3 |
Date: Tue, 15 Oct 2013 21:55:52 +0200
|
|
|
0890d3 |
Subject: [PATCH] fix potential buffer overflows reported by static analysis
|
|
|
0890d3 |
|
|
|
0890d3 |
(cherry picked from commit 8f586939999e039563fee6bca4685895067a2b77)
|
|
|
0890d3 |
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
|
|
0890d3 |
---
|
|
|
0890d3 |
arptables.c | 9 +++++----
|
|
|
0890d3 |
libarptc/libarptc_incl.c | 16 ++++++++++------
|
|
|
0890d3 |
2 files changed, 15 insertions(+), 10 deletions(-)
|
|
|
0890d3 |
|
|
|
0890d3 |
diff --git a/arptables.c b/arptables.c
|
|
|
0890d3 |
index 8ef445a4700c4..4da6fea980bb9 100644
|
|
|
0890d3 |
--- a/arptables.c
|
|
|
0890d3 |
+++ b/arptables.c
|
|
|
0890d3 |
@@ -1270,7 +1270,7 @@ print_firewall(const struct arpt_entry *fw,
|
|
|
0890d3 |
sprintf(buf, "%s", addr_to_dotted(&(fw->arp.src)));
|
|
|
0890d3 |
else
|
|
|
0890d3 |
sprintf(buf, "%s", addr_to_anyname(&(fw->arp.src)));
|
|
|
0890d3 |
- strcat(buf, mask_to_dotted(&(fw->arp.smsk)));
|
|
|
0890d3 |
+ strncat(buf, mask_to_dotted(&(fw->arp.smsk)), sizeof(buf) - strlen(buf) -1);
|
|
|
0890d3 |
printf("-s %s ", buf);
|
|
|
0890d3 |
}
|
|
|
0890d3 |
|
|
|
0890d3 |
@@ -1294,7 +1294,7 @@ after_devsrc:
|
|
|
0890d3 |
sprintf(buf, "%s", addr_to_dotted(&(fw->arp.tgt)));
|
|
|
0890d3 |
else
|
|
|
0890d3 |
sprintf(buf, "%s", addr_to_anyname(&(fw->arp.tgt)));
|
|
|
0890d3 |
- strcat(buf, mask_to_dotted(&(fw->arp.tmsk)));
|
|
|
0890d3 |
+ strncat(buf, mask_to_dotted(&(fw->arp.tmsk)), sizeof(buf) - strlen(buf) -1);
|
|
|
0890d3 |
printf("-d %s ", buf);
|
|
|
0890d3 |
}
|
|
|
0890d3 |
|
|
|
0890d3 |
@@ -1796,7 +1796,7 @@ int do_command(int argc, char *argv[], char **table, arptc_handle_t *handle)
|
|
|
0890d3 |
*table, arptc_strerror(errno));
|
|
|
0890d3 |
}
|
|
|
0890d3 |
}
|
|
|
0890d3 |
- }
|
|
|
0890d3 |
+ }
|
|
|
0890d3 |
|
|
|
0890d3 |
memset(&fw, 0, sizeof(fw));
|
|
|
0890d3 |
opts = original_opts;
|
|
|
0890d3 |
@@ -2064,7 +2064,8 @@ int do_command(int argc, char *argv[], char **table, arptc_handle_t *handle)
|
|
|
0890d3 |
|
|
|
0890d3 |
target->t = fw_calloc(1, size);
|
|
|
0890d3 |
target->t->u.target_size = size;
|
|
|
0890d3 |
- strcpy(target->t->u.user.name, jumpto);
|
|
|
0890d3 |
+ strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name));
|
|
|
0890d3 |
+ target->t->u.user.name[sizeof(target->t->u.user.name)-1] = '\0';
|
|
|
0890d3 |
/*
|
|
|
0890d3 |
target->init(target->t, &fw.nfcache);
|
|
|
0890d3 |
*/
|
|
|
0890d3 |
diff --git a/libarptc/libarptc_incl.c b/libarptc/libarptc_incl.c
|
|
|
0890d3 |
index 2fa3d43576933..9c1aeac7ca3de 100644
|
|
|
0890d3 |
--- a/libarptc/libarptc_incl.c
|
|
|
0890d3 |
+++ b/libarptc/libarptc_incl.c
|
|
|
0890d3 |
@@ -209,8 +209,10 @@ alloc_handle(const char *tablename, unsigned int size, unsigned int num_rules)
|
|
|
0890d3 |
h->counter_map = (void *)h
|
|
|
0890d3 |
+ sizeof(STRUCT_TC_HANDLE)
|
|
|
0890d3 |
+ size;
|
|
|
0890d3 |
- strcpy(h->info.name, tablename);
|
|
|
0890d3 |
- strcpy(h->entries.name, tablename);
|
|
|
0890d3 |
+ strncpy(h->info.name, tablename, sizeof(h->info.name));
|
|
|
0890d3 |
+ h->info.name[sizeof(h->info.name)-1] = '\0';
|
|
|
0890d3 |
+ strncpy(h->entries.name, tablename, sizeof(h->entries.name));
|
|
|
0890d3 |
+ h->entries.name[sizeof(h->entries.name)-1] = '\0';
|
|
|
0890d3 |
|
|
|
0890d3 |
return h;
|
|
|
0890d3 |
}
|
|
|
0890d3 |
@@ -357,8 +359,9 @@ add_chain(STRUCT_ENTRY *e, TC_HANDLE_T h, STRUCT_ENTRY **prev)
|
|
|
0890d3 |
h->cache_chain_heads[h->cache_num_chains-1].end
|
|
|
0890d3 |
= *prev;
|
|
|
0890d3 |
|
|
|
0890d3 |
- strcpy(h->cache_chain_heads[h->cache_num_chains].name,
|
|
|
0890d3 |
- (const char *)GET_TARGET(e)->data);
|
|
|
0890d3 |
+ strncpy(h->cache_chain_heads[h->cache_num_chains].name,
|
|
|
0890d3 |
+ (const char *)GET_TARGET(e)->data, TABLE_MAXNAMELEN-1);
|
|
|
0890d3 |
+ h->cache_chain_heads[h->cache_num_chains].name[TABLE_MAXNAMELEN-1] = '\0';
|
|
|
0890d3 |
h->cache_chain_heads[h->cache_num_chains].start
|
|
|
0890d3 |
= (void *)e + e->next_offset;
|
|
|
0890d3 |
h->cache_num_chains++;
|
|
|
0890d3 |
@@ -368,8 +371,9 @@ add_chain(STRUCT_ENTRY *e, TC_HANDLE_T h, STRUCT_ENTRY **prev)
|
|
|
0890d3 |
h->cache_chain_heads[h->cache_num_chains-1].end
|
|
|
0890d3 |
= *prev;
|
|
|
0890d3 |
|
|
|
0890d3 |
- strcpy(h->cache_chain_heads[h->cache_num_chains].name,
|
|
|
0890d3 |
- h->hooknames[builtin-1]);
|
|
|
0890d3 |
+ strncpy(h->cache_chain_heads[h->cache_num_chains].name,
|
|
|
0890d3 |
+ h->hooknames[builtin-1], TABLE_MAXNAMELEN-1);
|
|
|
0890d3 |
+ h->cache_chain_heads[h->cache_num_chains].name[TABLE_MAXNAMELEN-1] = '\0';
|
|
|
0890d3 |
h->cache_chain_heads[h->cache_num_chains].start
|
|
|
0890d3 |
= (void *)e;
|
|
|
0890d3 |
h->cache_num_chains++;
|
|
|
0890d3 |
--
|
|
|
0890d3 |
2.21.0
|
|
|
0890d3 |
|