1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

Subject: ssl: fix source and destination overlap in strcpy

Use memmove instead...

AG add explanation for union name[] member length.

Signed-off-by: Petar Paradzik <petar.paradzik@sartura.hr>
This commit is contained in:
Petar Paradzik 2017-10-26 16:55:20 +02:00 committed by Andy Green
parent 939436b793
commit 2f7bd10487
2 changed files with 15 additions and 3 deletions

View file

@ -5441,7 +5441,19 @@ union lws_tls_cert_info_results {
unsigned int usage;
struct {
int len;
char name[64]; /* KEEP LAST... name[] not allowed in union */
/* KEEP LAST... notice the [64] is only there because
* name[] is not allowed in a union. The actual length of
* name[] is arbitrary and is passed into the api using the
* len parameter. Eg
*
* char big[1024];
* union lws_tls_cert_info_results *buf =
* (union lws_tls_cert_info_results *)big;
*
* lws_tls_peer_cert_info(wsi, type, buf,
* sizeof(big) - sizeof(*buf) + 64);
*/
char name[64];
} ns;
};

View file

@ -552,10 +552,10 @@ lws_tls_openssl_cert_info(X509 *x509, enum lws_tls_cert_info type,
xn = X509_get_subject_name(x509);
if (!xn)
return -1;
X509_NAME_oneline(xn, buf->ns.name, (int)len - 1);
X509_NAME_oneline(xn, buf->ns.name, (int)len - 2);
p = strstr(buf->ns.name, "/CN=");
if (p)
strcpy(buf->ns.name, p + 4);
memmove(buf->ns.name, p + 4, strlen(p + 4) + 1);
buf->ns.len = (int)strlen(buf->ns.name);
return 0;