wolfssl: use strcpy() as the target buffer is > 40 bytes
gethostname: return failure if the buffer is too small instead
Closes #14830
/* Override hostname when environment variable CURL_GETHOSTNAME is set */
const char *force_hostname = getenv("CURL_GETHOSTNAME");
if(force_hostname) {
- strncpy(name, force_hostname, namelen - 1);
+ if(strlen(force_hostname) < (size_t)namelen)
+ strcpy(name, force_hostname);
+ else
+ return 1; /* can't do it */
err = 0;
}
else {
static char *wolfssl_strerror(unsigned long error, char *buf,
unsigned long size)
{
- DEBUGASSERT(size);
+ DEBUGASSERT(size > 40);
*buf = '\0';
wolfSSL_ERR_error_string_n(error, buf, size);
if(!*buf) {
const char *msg = error ? "Unknown error" : "No error";
- strncpy(buf, msg, size - 1);
- buf[size - 1] = '\0';
+ /* the string fits because the assert above assures this */
+ strcpy(buf, msg);
}
return buf;