diff --git a/include/villas/advio.h b/include/villas/advio.h index a1741a9f9..afbf3b14b 100644 --- a/include/villas/advio.h +++ b/include/villas/advio.h @@ -39,7 +39,7 @@ struct advio { unsigned char hash[SHA_DIGEST_LENGTH]; - char mode[2]; + char mode[3]; char *uri; }; diff --git a/lib/advio.c b/lib/advio.c index 9a9d2f738..872f6176c 100644 --- a/lib/advio.c +++ b/lib/advio.c @@ -193,7 +193,7 @@ AFILE * afopen(const char *uri, const char *mode) AFILE *af = alloc(sizeof(AFILE)); - strncpy(af->mode, mode, sizeof(af->mode)); + snprintf(af->mode, sizeof(af->mode), "%s", mode); sep = strstr(uri, "://"); if (sep) { diff --git a/lib/kernel/kernel.c b/lib/kernel/kernel.c index e1421c95c..27dcfdcbd 100644 --- a/lib/kernel/kernel.c +++ b/lib/kernel/kernel.c @@ -151,7 +151,7 @@ int kernel_get_cmdline_param(const char *param, char *buf, size_t len) if (strcmp(param, key) == 0) { if (ret >= 2 && buf) - strncpy(buf, value, len); + snprintf(buf, len, "%s", value); return 0; /* found */ } diff --git a/lib/nodes/socket.c b/lib/nodes/socket.c index 584762860..15e0412f2 100644 --- a/lib/nodes/socket.c +++ b/lib/nodes/socket.c @@ -626,7 +626,10 @@ int socket_parse_addr(const char *addr, struct sockaddr *saddr, enum socket_laye if (layer == SOCKET_LAYER_UNIX) { /* Format: "/path/to/socket" */ sa->sun.sun_family = AF_UNIX; - strncpy(sa->sun.sun_path, addr, sizeof(sa->sun.sun_path)); + if (strlen(addr) > sizeof(sa->sun.sun_path)-1) + error("Length of unix socket path is too long!"); + + memcpy(sa->sun.sun_path, addr, strlen(sa->sun.sun_path)+1); ret = 0; } diff --git a/lib/nodes/zeromq.c b/lib/nodes/zeromq.c index c0a6e63dd..fc81934a2 100644 --- a/lib/nodes/zeromq.c +++ b/lib/nodes/zeromq.c @@ -174,8 +174,8 @@ int zeromq_parse(struct node *n, json_t *cfg) if (strlen(public_key) != 40) error("Setting 'curve.public_key' of node %s must be a Z85 encoded CurveZMQ key", node_name(n)); - strncpy(z->curve.server.public_key, public_key, 41); - strncpy(z->curve.server.secret_key, secret_key, 41); + memcpy(z->curve.server.public_key, public_key, 41); + memcpy(z->curve.server.secret_key, secret_key, 41); } /** @todo We should fix this. Its mostly done. */ diff --git a/lib/super_node.c b/lib/super_node.c index 3c14d45e7..eb08a7515 100644 --- a/lib/super_node.c +++ b/lib/super_node.c @@ -201,8 +201,10 @@ int super_node_parse_json(struct super_node *sn, json_t *cfg) if (ret) jerror(&err, "Failed to parse global configuration"); - if (name) - strncpy(sn->name, name, 128); + if (name) { + sn->name = realloc(sn->name, strlen(name)+1); + sprintf(sn->name, "%s", name); + } #ifdef WITH_WEB if (json_web)