summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2015-10-27 12:11:09 +0100
committerTobias Klauser <tklauser@distanz.ch>2015-10-27 12:11:09 +0100
commite3822bdbd11f1546b002f00cc018a612e2f3d3e5 (patch)
tree609b1c3fae9bfd92b44fdb44b5131d2efcbb939a
parentbd031f809422ea88b9619924911aa5112f95b6b3 (diff)
flowtop: Use strlcpy instead of memcpy to copy strings
Make sure we always terminate the strings with '\0'. Also only set the first byte to '\0' instead of memset()ing the entire buffer in case no city/country is returned. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--flowtop.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/flowtop.c b/flowtop.c
index 50ceccb..7573780 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -655,13 +655,11 @@ flow_entry_geo_city_lookup_generic(struct flow_entry *n,
build_bug_on(sizeof(n->city_src) != sizeof(n->city_dst));
- if (city) {
- memcpy(SELFLD(dir, city_src, city_dst), city,
- min(sizeof(n->city_src), strlen(city)));
- } else {
- memset(SELFLD(dir, city_src, city_dst), 0,
- sizeof(n->city_src));
- }
+ if (city)
+ strlcpy(SELFLD(dir, city_src, city_dst), city,
+ sizeof(n->city_src));
+ else
+ SELFLD(dir, city_src, city_dst)[0] = '\0';
}
static void
@@ -689,13 +687,11 @@ flow_entry_geo_country_lookup_generic(struct flow_entry *n,
build_bug_on(sizeof(n->country_src) != sizeof(n->country_dst));
- if (country) {
- memcpy(SELFLD(dir, country_src, country_dst), country,
- min(sizeof(n->country_src), strlen(country)));
- } else {
- memset(SELFLD(dir, country_src, country_dst), 0,
- sizeof(n->country_src));
- }
+ if (country)
+ strlcpy(SELFLD(dir, country_src, country_dst), country,
+ sizeof(n->country_src));
+ else
+ SELFLD(dir, country_src, country_dst)[0] = '\0';
}
static void flow_entry_get_extended_geo(struct flow_entry *n,