Blame SOURCES/arptables-0.0.4-covscan_fix02_buf_overflow.patch

29ecbd
commit fea55b0930d7cb67a3359185e53ef6b856b7721d
29ecbd
Author: Jaromír Končický <jkoncick@redhat.com>
29ecbd
Date:   Tue Oct 15 21:55:52 2013 +0200
29ecbd
29ecbd
    fix potential buffer overflows reported by static analysis
29ecbd
29ecbd
diff --git a/userspace/arptables/arptables.c b/userspace/arptables/arptables.c
29ecbd
index 8ef445a..4da6fea 100644
29ecbd
--- a/userspace/arptables/arptables.c
29ecbd
+++ b/userspace/arptables/arptables.c
29ecbd
@@ -1270,7 +1270,7 @@ print_firewall(const struct arpt_entry *fw,
29ecbd
 			sprintf(buf, "%s", addr_to_dotted(&(fw->arp.src)));
29ecbd
 		else
29ecbd
 			sprintf(buf, "%s", addr_to_anyname(&(fw->arp.src)));
29ecbd
-		strcat(buf, mask_to_dotted(&(fw->arp.smsk)));
29ecbd
+		strncat(buf, mask_to_dotted(&(fw->arp.smsk)), sizeof(buf) - strlen(buf) -1);
29ecbd
 		printf("-s %s ", buf);
29ecbd
 	}
29ecbd
 
29ecbd
@@ -1294,7 +1294,7 @@ after_devsrc:
29ecbd
 			sprintf(buf, "%s", addr_to_dotted(&(fw->arp.tgt)));
29ecbd
 		else
29ecbd
 			sprintf(buf, "%s", addr_to_anyname(&(fw->arp.tgt)));
29ecbd
-		strcat(buf, mask_to_dotted(&(fw->arp.tmsk)));
29ecbd
+		strncat(buf, mask_to_dotted(&(fw->arp.tmsk)),  sizeof(buf) - strlen(buf) -1);
29ecbd
 		printf("-d %s ", buf);
29ecbd
 	}
29ecbd
 
29ecbd
@@ -1796,7 +1796,7 @@ int do_command(int argc, char *argv[], char **table, arptc_handle_t *handle)
29ecbd
 				*table, arptc_strerror(errno));
29ecbd
 			}
29ecbd
 		}
29ecbd
-        }
29ecbd
+	}
29ecbd
 
29ecbd
 	memset(&fw, 0, sizeof(fw));
29ecbd
 	opts = original_opts;
29ecbd
@@ -2064,7 +2064,8 @@ int do_command(int argc, char *argv[], char **table, arptc_handle_t *handle)
29ecbd
 
29ecbd
 				target->t = fw_calloc(1, size);
29ecbd
 				target->t->u.target_size = size;
29ecbd
-				strcpy(target->t->u.user.name, jumpto);
29ecbd
+				strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name));
29ecbd
+				target->t->u.user.name[sizeof(target->t->u.user.name)-1] = '\0';
29ecbd
 /*
29ecbd
 				target->init(target->t, &fw.nfcache);
29ecbd
 */
29ecbd
diff --git a/userspace/arptables/libarptc/libarptc_incl.c b/userspace/arptables/libarptc/libarptc_incl.c
29ecbd
index 2fa3d43..9c1aeac 100644
29ecbd
--- a/userspace/arptables/libarptc/libarptc_incl.c
29ecbd
+++ b/userspace/arptables/libarptc/libarptc_incl.c
29ecbd
@@ -209,8 +209,10 @@ alloc_handle(const char *tablename, unsigned int size, unsigned int num_rules)
29ecbd
 	h->counter_map = (void *)h
29ecbd
 		+ sizeof(STRUCT_TC_HANDLE)
29ecbd
 		+ size;
29ecbd
-	strcpy(h->info.name, tablename);
29ecbd
-	strcpy(h->entries.name, tablename);
29ecbd
+	strncpy(h->info.name, tablename, sizeof(h->info.name));
29ecbd
+	h->info.name[sizeof(h->info.name)-1] = '\0';
29ecbd
+	strncpy(h->entries.name, tablename, sizeof(h->entries.name));
29ecbd
+	h->entries.name[sizeof(h->entries.name)-1] = '\0';
29ecbd
 
29ecbd
 	return h;
29ecbd
 }
29ecbd
@@ -357,8 +359,9 @@ add_chain(STRUCT_ENTRY *e, TC_HANDLE_T h, STRUCT_ENTRY **prev)
29ecbd
 		h->cache_chain_heads[h->cache_num_chains-1].end
29ecbd
 			= *prev;
29ecbd
 
29ecbd
-		strcpy(h->cache_chain_heads[h->cache_num_chains].name,
29ecbd
-		       (const char *)GET_TARGET(e)->data);
29ecbd
+		strncpy(h->cache_chain_heads[h->cache_num_chains].name,
29ecbd
+		       (const char *)GET_TARGET(e)->data, TABLE_MAXNAMELEN-1);
29ecbd
+		h->cache_chain_heads[h->cache_num_chains].name[TABLE_MAXNAMELEN-1] = '\0';
29ecbd
 		h->cache_chain_heads[h->cache_num_chains].start
29ecbd
 			= (void *)e + e->next_offset;
29ecbd
 		h->cache_num_chains++;
29ecbd
@@ -368,8 +371,9 @@ add_chain(STRUCT_ENTRY *e, TC_HANDLE_T h, STRUCT_ENTRY **prev)
29ecbd
 			h->cache_chain_heads[h->cache_num_chains-1].end
29ecbd
 				= *prev;
29ecbd
 
29ecbd
-		strcpy(h->cache_chain_heads[h->cache_num_chains].name,
29ecbd
-		       h->hooknames[builtin-1]);
29ecbd
+		strncpy(h->cache_chain_heads[h->cache_num_chains].name,
29ecbd
+		       h->hooknames[builtin-1], TABLE_MAXNAMELEN-1);
29ecbd
+		h->cache_chain_heads[h->cache_num_chains].name[TABLE_MAXNAMELEN-1] = '\0';
29ecbd
 		h->cache_chain_heads[h->cache_num_chains].start
29ecbd
 			= (void *)e;
29ecbd
 		h->cache_num_chains++;