Even though they were safe, compilers like to warn about them nowadays.
if(!unixsocketname) {
int len = strlen(pidfilename);
unixsocketname = xmalloc(len + 8);
- strcpy(unixsocketname, pidfilename);
+ memcpy(unixsocketname, pidfilename, len);
if(len > 4 && !strcmp(pidfilename + len - 4, ".pid"))
- strcpy(unixsocketname + len - 4, ".socket");
+ strncpy(unixsocketname + len - 4, ".socket", 8);
else
- strcpy(unixsocketname + len, ".socket");
+ strncpy(unixsocketname + len, ".socket", 8);
}
}
for splay_each(node_t, n, node_tree) {
char id[2 * sizeof n->id + 1];
for (size_t c = 0; c < sizeof n->id; ++c)
- sprintf(id + 2 * c, "%02hhx", n->id.x[c]);
+ snprintf(id + 2 * c, 3, "%02hhx", n->id.x[c]);
id[sizeof id - 1] = 0;
send_request(c, "%d %d %s %s %s %d %d %d %d %x %x %s %s %d %hd %hd %hd %ld", CONTROL, REQ_DUMP_NODES,
n->name, id, n->hostname ?: "unknown port unknown",
#ifdef HAVE_MINGW
if(!*scriptextension) {
const char *pathext = getenv("PATHEXT") ?: ".COM;.EXE;.BAT;.CMD";
- char fullname[strlen(scriptname) + strlen(pathext)];
- char *ext = fullname + strlen(scriptname);
- strcpy(fullname, scriptname);
+ size_t pathlen = strlen(pathext);
+ size_t scriptlen = strlen(scriptname);
+ char fullname[scriptlen + pathlen + 1];
+ char *ext = fullname + scriptlen;
+ strncpy(fullname, scriptname, sizeof fullname);
const char *p = pathext;
bool found = false;
ext[q - p] = 0;
q++;
} else {
- strcpy(ext, p);
+ strncpy(ext, p, pathlen + 1);
}
if((found = !access(fullname, F_OK)))
break;
// Create the HMAC seed, which is "key expansion" + session label + server nonce + client nonce
char seed[s->labellen + 64 + 13];
- strcpy(seed, "key expansion");
+ memcpy(seed, "key expansion", 13);
if(s->initiator) {
memcpy(seed + 13, s->mykex + 1, 32);
memcpy(seed + 45, s->hiskex + 1, 32);
const char *winerror(int err) {
static char buf[1024], *ptr;
- ptr = buf + sprintf(buf, "(%d) ", err);
+ ptr = buf + snprintf(buf, sizeof buf, "(%d) ", err);
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), ptr, sizeof(buf) - (ptr - buf), NULL)) {