summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-01-28 21:49:12 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-01-28 21:49:12 +0100
commit45827d8a189724c04d11b128624742fdb3a6679b (patch)
tree1d6b13d017ce7eda5e0fc0cba90c431dd4a0661c
parentad29f57f828f72032403c37cd69f5302e99790ec (diff)
downloadfastd-45827d8a189724c04d11b128624742fdb3a6679b.tar
fastd-45827d8a189724c04d11b128624742fdb3a6679b.zip
Remove a few more instances of strcpy
-rw-r--r--src/config.y5
-rw-r--r--src/fastd.h7
-rw-r--r--src/status.c5
3 files changed, 11 insertions, 6 deletions
diff --git a/src/config.y b/src/config.y
index af93864..f2f597f 100644
--- a/src/config.y
+++ b/src/config.y
@@ -491,10 +491,11 @@ peer_remote: maybe_ipv4 TOK_ADDR4 port {
addrlen = strlen(addrbuf);
fastd_remote_t remote = {};
- remote.hostname = fastd_alloc(addrlen + strlen($2.ifname) + 2);
+ size_t ifname_len = strlen($2.ifname);
+ remote.hostname = fastd_alloc(addrlen + ifname_len + 2);
memcpy(remote.hostname, addrbuf, addrlen);
remote.hostname[addrlen] = '%';
- strcpy(remote.hostname+addrlen+1, $2.ifname);
+ memcpy(remote.hostname+addrlen+1, $2.ifname, ifname_len+1);
remote.address.sa.sa_family = AF_INET6;
remote.address.in.sin_port = htons($3);
diff --git a/src/fastd.h b/src/fastd.h
index 3ae856c..f1b2f93 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -464,9 +464,12 @@ static inline fastd_string_stack_t * fastd_string_stack_dupn(const char *str, si
/** Pushes the copy of a string onto the top of a string stack */
static inline fastd_string_stack_t * fastd_string_stack_push(fastd_string_stack_t *stack, const char *str) {
- fastd_string_stack_t *ret = fastd_alloc(alignto(sizeof(fastd_string_stack_t) + strlen(str) + 1, 8));
+ size_t str_len = strlen(str);
+ fastd_string_stack_t *ret = fastd_alloc(alignto(sizeof(fastd_string_stack_t) + str_len + 1, 8));
+
ret->next = stack;
- strcpy(ret->str, str);
+
+ memcpy(ret->str, str, str_len + 1);
return ret;
}
diff --git a/src/status.c b/src/status.c
index 3c82e0c..d0b8511 100644
--- a/src/status.c
+++ b/src/status.c
@@ -220,14 +220,15 @@ void fastd_status_init(void) {
exit_errno("fastd_status_init: socket");
- size_t len = offsetof(struct sockaddr_un, sun_path) + strlen(conf.status_socket) + 1;
+ size_t status_socket_len = strlen(conf.status_socket);
+ size_t len = offsetof(struct sockaddr_un, sun_path) + status_socket_len + 1;
uint8_t buf[len];
memset(buf, 0, len);
struct sockaddr_un *sa = (void*)buf;
sa->sun_family = AF_UNIX;
- strcpy(sa->sun_path, conf.status_socket);
+ memcpy(sa->sun_path, conf.status_socket, status_socket_len+1);
if (bind(ctx.status_fd, (struct sockaddr*)sa, len)) {
switch (errno) {