lib: remove the final strncpy() calls
wolfssl: use strcpy() as the target buffer is > 40 bytes gethostname: return failure if the buffer is too small instead Closes #14830
This commit is contained in:
parent
eb8ad66f6c
commit
344a177aac
@ -59,7 +59,10 @@ int Curl_gethostname(char * const name, GETHOSTNAME_TYPE_ARG2 namelen)
|
|||||||
/* Override hostname when environment variable CURL_GETHOSTNAME is set */
|
/* Override hostname when environment variable CURL_GETHOSTNAME is set */
|
||||||
const char *force_hostname = getenv("CURL_GETHOSTNAME");
|
const char *force_hostname = getenv("CURL_GETHOSTNAME");
|
||||||
if(force_hostname) {
|
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;
|
err = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@ -1176,15 +1176,15 @@ wolfssl_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data)
|
|||||||
static char *wolfssl_strerror(unsigned long error, char *buf,
|
static char *wolfssl_strerror(unsigned long error, char *buf,
|
||||||
unsigned long size)
|
unsigned long size)
|
||||||
{
|
{
|
||||||
DEBUGASSERT(size);
|
DEBUGASSERT(size > 40);
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
|
|
||||||
wolfSSL_ERR_error_string_n(error, buf, size);
|
wolfSSL_ERR_error_string_n(error, buf, size);
|
||||||
|
|
||||||
if(!*buf) {
|
if(!*buf) {
|
||||||
const char *msg = error ? "Unknown error" : "No error";
|
const char *msg = error ? "Unknown error" : "No error";
|
||||||
strncpy(buf, msg, size - 1);
|
/* the string fits because the assert above assures this */
|
||||||
buf[size - 1] = '\0';
|
strcpy(buf, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user