- strcpy(barrier->name, name);
+ strncpy(barrier->name, name, MAX_BARRIER_NAME_LEN - 1);
barrier->flags = 0;
barrier->expected_nodes = nodes;
barrier->got_nodes = 0;
@@ -268,7 +268,7 @@ static int barrier_setattr_enabled(struct cl_barrier *barrier,
/* Send it to the rest of the cluster */
bmsg.cmd = CLUSTER_MSG_BARRIER;
bmsg.subcmd = BARRIER_WAIT;
- strcpy(bmsg.name, barrier->name);
+ strncpy(bmsg.name, barrier->name, MAX_BARRIER_NAME_LEN - 1);
barrier->waitsent = 1;
barrier->phase = 1;
diff --git a/cman/daemon/cman-preconfig.c b/cman/daemon/cman-preconfig.c
index d632c17..baf94df 100644
--- a/cman/daemon/cman-preconfig.c
+++ b/cman/daemon/cman-preconfig.c
@@ -302,14 +302,14 @@ static int add_ifaddr(struct objdb_iface_ver0 *objdb, char *mcast, char *ifaddr,
/* Check the families match */
if (address_family(mcast, &mcast_addr, 0) !=
address_family(ifaddr, &if_addr, mcast_addr.ss_family)) {
- sprintf(error_reason, "Node address family does not match multicast address family");
+ snprintf(error_reason, sizeof(error_reason) - 1, "Node address family does not match multicast address family");
return -1;
}
/* Check it's not bound to localhost, sigh */
get_localhost(if_addr.ss_family, &localhost);
if (ipaddr_equal(&localhost, &if_addr)) {
- sprintf(error_reason, "Node name resolves to localhost, please check /etc/hosts and assign this node a network IP address");
+ snprintf(error_reason, sizeof(error_reason) - 1, "Node name resolves to localhost, please check /etc/hosts and assign this node a network IP address");
return -1;
}
@@ -325,7 +325,7 @@ static int add_ifaddr(struct objdb_iface_ver0 *objdb, char *mcast, char *ifaddr,
objdb->object_key_create_typed(totem_object_handle, "transport",
tx_mech_to_str[transport], strlen(tx_mech_to_str[transport]) + 1, OBJDB_VALUETYPE_STRING);
} else {
- sprintf(error_reason, "Transport should not be specified within <totem .../>, use <cman transport="..." /> instead");
+ snprintf(error_reason, sizeof(error_reason) - 1, "Transport should not be specified within <totem .../>, use <cman transport="..." /> instead");
return -1;
}
}
@@ -336,7 +336,7 @@ static int add_ifaddr(struct objdb_iface_ver0 *objdb, char *mcast, char *ifaddr,
struct sockaddr_in6 *in6= (struct sockaddr_in6 *)&if_addr;
void *addrptr;
/* paranoia check. corosync already does it */
if ((ttl < 0) || (ttl > 255)) {
- sprintf(error_reason, "TTL value (%u) out of range (0 - 255)", ttl);
+ snprintf(error_reason, sizeof(error_reason) - 1, "TTL value (%u) out of range (0 - 255)", ttl);
return -1;
}
/* add the key to the objdb only if value is not default */
if (ttl != 1) {
- sprintf(tmp, "%d", ttl);
+ snprintf(tmp, sizeof(tmp) - 1, "%d", ttl);
objdb->object_key_create_typed(interface_object_handle , "ttl",
tmp, strlen(tmp)+1, OBJDB_VALUETYPE_STRING);
}
@@ -412,7 +412,7 @@ static char *default_mcast(char *node, int altiface)
default a multicast address */
ret = getaddrinfo(node, NULL, &ahints, &ainfo);
if (ret) {
- sprintf(error_reason, "Can't determine address family of nodename %s
", node);
+ snprintf(error_reason, sizeof(error_reason) - 1, "Can't determine address family of nodename %s
", node);
write_cman_pipe("Can't determine address family of nodename");
return NULL;
}
@@ -448,13 +448,13 @@ static int verify_nodename(struct objdb_iface_ver0 *objdb, char *node)
return 0;
/* If nodename was from uname, try a domain-less version of it */
- strcpy(nodename2, node);
+ strncpy(nodename2, node, sizeof(nodename2) - 1);
dot = strchr(nodename2, '.');
if (dot) {
*dot = ' ';
if (!(node_object_handle = nodelist_byname(objdb, cluster_parent_handle, nodename))) {
- sprintf(error_reason, "Overridden node name %s is not in CCS", nodename);
+ snprintf(error_reason, sizeof(error_reason) - 1, "Overridden node name %s is not in CCS", nodename);
write_cman_pipe("Overridden node name is not in CCS");
error = -1;
goto out;
@@ -646,20 +646,20 @@ static int get_nodename(struct objdb_iface_ver0 *objdb)
error = uname(&utsname);
if (error) {
- sprintf(error_reason, "cannot get node name, uname failed");
+ snprintf(error_reason, sizeof(error_reason) - 1, "cannot get node name, uname failed");
write_cman_pipe("Can't determine local node name, uname failed");
error = -1;
goto out;
}
if (strlen(utsname.nodename) >= sizeof(nodename)) {
- sprintf(error_reason, "node name from uname is too long");
+ snprintf(error_reason, sizeof(error_reason) - 1, "node name from uname is too long");
write_cman_pipe("local node name is too long");
error = -1;
goto out;
}
- strcpy(nodename, utsname.nodename);
+ strncpy(nodename, utsname.nodename, sizeof(nodename) - 1);
}
if (verify_nodename(objdb, nodename)) {
write_cman_pipe("Cannot find node name in cluster.conf");
@@ -671,7 +671,7 @@ static int get_nodename(struct objdb_iface_ver0 *objdb)
/* Add <cman> bits to pass down to the main module*/
if ( (node_object_handle = nodelist_byname(objdb, cluster_parent_handle, nodename))) {
if (objdb_get_string(objdb, node_object_handle, "nodeid", &nodeid_str)) {
- sprintf(error_reason, "This node has no nodeid in cluster.conf");
+ snprintf(error_reason, sizeof(error_reason) - 1, "This node has no nodeid in cluster.conf");
write_cman_pipe("This node has no nodeid in cluster.conf");
return -1;
}
@@ -711,7 +711,7 @@ static int get_nodename(struct objdb_iface_ver0 *objdb)
objdb->object_find_destroy(find_handle);
if (!nodeid_str) {
- sprintf(error_reason, "This node has no nodeid in cluster.conf");
+ snprintf(error_reason, sizeof(error_reason) - 1, "This node has no nodeid in cluster.conf");
write_cman_pipe("This node has no nodeid in cluster.conf");
return -1;
}
@@ -746,7 +746,7 @@ static int get_nodename(struct objdb_iface_ver0 *objdb)
if (transport != TX_MECH_UDPB) {
transport = TX_MECH_UDPU;
} else {
- sprintf(error_reason, "Transport and broadcast option are mutually exclusive");
+ snprintf(error_reason, sizeof(error_reason) - 1, "Transport and broadcast option are mutually exclusive");
write_cman_pipe("Transport and broadcast option are mutually exclusive");
return -1;
}
@@ -754,12 +754,12 @@ static int get_nodename(struct objdb_iface_ver0 *objdb)
if (transport != TX_MECH_UDPB) {
transport = TX_MECH_RDMA;
} else {
- sprintf(error_reason, "Transport and broadcast option are mutually exclusive");
+ snprintf(error_reason, sizeof(error_reason) - 1, "Transport and broadcast option are mutually exclusive");
write_cman_pipe("Transport and broadcast option are mutually exclusive");
return -1;
}
} else {
- sprintf(error_reason, "Transport option value can be one of udp, udpb, udpu, rdma");
+ snprintf(error_reason, sizeof(error_reason) - 1, "Transport option value can be one of udp, udpb, udpu, rdma");
write_cman_pipe("Transport option value can be one of udp, udpb, udpu, rdma");
return -1;
}
@@ -931,7 +931,7 @@ static void add_cman_overrides(struct objdb_iface_ver0 *objdb)
objdb->object_key_create_typed(object_handle, "version",
"2", 2, OBJDB_VALUETYPE_STRING);
if (!cluster_name) {
- sprintf(error_reason, "cannot allocate memory for cluster_name");
+ snprintf(error_reason, sizeof(error_reason) - 1, "cannot allocate memory for cluster_name");
write_cman_pipe("cannot allocate memory for cluster_name");
return -1;
}
@@ -1138,7 +1138,7 @@ static int set_noccs_defaults(struct objdb_iface_ver0 *objdb)
else
cluster_id = generate_cluster_id(cluster_name);
- sprintf(error_reason, "Generated cluster id for '%s' is %d
", cluster_name, cluster_id);
+ snprintf(error_reason, sizeof(error_reason) - 1, "Generated cluster id for '%s' is %d
", cluster_name, cluster_id);
}
if (!nodename_env) {
@@ -1147,14 +1147,14 @@ static int set_noccs_defaults(struct objdb_iface_ver0 *objdb)
error = uname(&utsname);
if (error) {
- sprintf(error_reason, "cannot get node name, uname failed");
+ snprintf(error_reason, sizeof(error_reason) - 1, "cannot get node name, uname failed");
write_cman_pipe("Can't determine local node name");
return -1;
}
@@ -1310,13 +1310,13 @@ static int get_cman_globals(struct objdb_iface_ver0 *objdb)
objdb_get_string(objdb, cluster_parent_handle, "name", &cluster_name);
if (!cluster_name) {
- sprintf(error_reason, "Unable to determine cluster name.
");
+ snprintf(error_reason, sizeof(error_reason) - 1, "Unable to determine cluster name.
");
write_cman_pipe("Unable to determine cluster name.
");
return -1;
}
if (strlen(cluster_name) > 15) {
- sprintf(error_reason, "%s
", "Invalid cluster name. It must be 15 characters or fewer
");
+ snprintf(error_reason, sizeof(error_reason) - 1, "Invalid cluster name. It must be 15 characters or fewer
");
write_cman_pipe("Invalid cluster name. It must be 15 characters or fewer
");
return -1;
}
@@ -1345,7 +1345,7 @@ static int get_cman_globals(struct objdb_iface_ver0 *objdb)
else
cluster_id = generate_cluster_id(cluster_name);
- sprintf(error_reason, "Generated cluster id for '%s' is %d
", cluster_name, cluster_id);
+ snprintf(error_reason, sizeof(error_reason) - 1, "Generated cluster id for '%s' is %d
", cluster_name, cluster_id);
}
}
objdb->object_find_destroy(find_handle);
@@ -1363,7 +1363,7 @@ static int cmanpre_reloadconfig(struct objdb_iface_ver0 *objdb, int flush, const
/* don't reload if we've been told to run configless */
if (getenv("CMAN_NOCONFIG")) {
- sprintf(error_reason, "Config not updated because we were run with cman_tool -X");
+ snprintf(error_reason, sizeof(error_reason) - 1, "Config not updated because we were run with cman_tool -X");
ret = 0;
goto err;
}
@@ -1372,12 +1372,12 @@ static int cmanpre_reloadconfig(struct objdb_iface_ver0 *objdb, int flush, const
objdb->object_find_create(OBJECT_PARENT_HANDLE, "cluster", strlen("cluster"), &find_handle);
objdb->object_find_next(find_handle, &cluster_parent_handle);
if (!cluster_parent_handle) {
- sprintf (error_reason, "%s", "Cannot find old /cluster/ key in configuration
");
+ snprintf (error_reason, sizeof(error_reason) - 1, "Cannot find old /cluster/ key in configuration
");
goto err;
}
objdb->object_find_next(find_handle, &cluster_parent_handle_new);
if (!cluster_parent_handle_new) {
- sprintf (error_reason, "%s", "Cannot find new /cluster/ key in configuration
");
+ snprintf (error_reason, sizeof(error_reason) - 1, "Cannot find new /cluster/ key in configuration
");
goto err;
}
objdb->object_find_destroy(find_handle);
@@ -1387,7 +1387,7 @@ static int cmanpre_reloadconfig(struct objdb_iface_ver0 *objdb, int flush, const
config_version = atoi(config_value);
} else {
/* it should never ever happen.. */
- sprintf (error_reason, "%s", "Cannot find old /cluster/config_version key in configuration
");
+ snprintf (error_reason, sizeof(error_reason) - 1, "Cannot find old /cluster/config_version key in configuration
");
goto err;
}
}
@@ -1399,14 +1399,14 @@ static int cmanpre_reloadconfig(struct objdb_iface_ver0 *objdb, int flush, const
config_version_new = atoi(config_value);
} else {
objdb->object_destroy(cluster_parent_handle_new);
- sprintf (error_reason, "%s", "Cannot find new /cluster/config_version key in configuration
");
+ snprintf (error_reason, sizeof(error_reason) - 1,"Cannot find new /cluster/config_version key in configuration
");
goto err;
}
}
if (config_version_new <= config_version) {
objdb->object_destroy(cluster_parent_handle_new);
- sprintf (error_reason, "%s", "New configuration version has to be newer than current running configuration
");
+ snprintf (error_reason, sizeof(error_reason) - 1, "New configuration version has to be newer than current running configuration
");
goto err;
}