for (; n--; ts++) {
char name[OFP_MAX_TABLE_NAME_LEN + 1];
- strncpy(name, ts->name, sizeof name);
- name[OFP_MAX_TABLE_NAME_LEN] = '\0';
+ ovs_strlcpy(name, ts->name, sizeof name);
ds_put_format(string, " %d: %-8s: ", ts->table_id, name);
ds_put_format(string, "wild=0x%05"PRIx32", ", ntohl(ts->wildcards));
nn = name_node_lookup(ifindex);
if (nn) {
- strncpy(name, nn->ifname, IFNAMSIZ);
+ ovs_strlcpy(name, nn->ifname, IFNAMSIZ);
return true;
}
}
nn = xzalloc(sizeof *nn);
nn->ifi_index = change.ifi_index;
- strncpy(nn->ifname, change.ifname, IFNAMSIZ);
- nn->ifname[IFNAMSIZ - 1] = '\0';
+ ovs_strlcpy(nn->ifname, change.ifname, IFNAMSIZ);
hmap_insert(&name_map, &nn->node, hash_int(nn->ifi_index, 0));
}
}
return s;
}
+/* Similar to strlcpy() from OpenBSD, but it never reads more than 'size - 1'
+ * bytes from 'src' and doesn't return anything. */
void
ovs_strlcpy(char *dst, const char *src, size_t size)
{
if (size > 0) {
- size_t n = strlen(src);
- size_t n_copy = MIN(n, size - 1);
- memcpy(dst, src, n_copy);
- dst[n_copy] = '\0';
+ size_t len = strnlen(src, size - 1);
+ memcpy(dst, src, len);
+ dst[len] = '\0';
}
}