From bbfcd0cac89c9d94c47bdd4c4782b27a8eabe038 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Tue, 21 Dec 2021 10:20:34 -0800 Subject: [PATCH] fix build warning with af_alg --- wolfcrypt/src/port/af_alg/wc_afalg.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/src/port/af_alg/wc_afalg.c b/wolfcrypt/src/port/af_alg/wc_afalg.c index 5e0ad7e39..264e712b7 100644 --- a/wolfcrypt/src/port/af_alg/wc_afalg.c +++ b/wolfcrypt/src/port/af_alg/wc_afalg.c @@ -36,11 +36,20 @@ /* Sets the type of socket address to use */ void wc_Afalg_SockAddr(struct sockaddr_alg* in, const char* type, const char* name) { + int typeSz = (int)XSTRLEN(type) + 1; /* +1 for null terminator */ + int nameSz = (int)XSTRLEN(name) + 1; /* +1 for null terminator */ + + if (typeSz > (int)sizeof(in->salg_type) || + nameSz > (int)sizeof(in->salg_name)) { + WOLFSSL_MSG("type or name was too large"); + return; + } + in->salg_family = AF_ALG; - XSTRNCPY((char*)in->salg_type, type, XSTRLEN(type)); - in->salg_type[XSTRLEN(type)] = '\0'; - XSTRNCPY((char*)in->salg_name, name, XSTRLEN(name)); - in->salg_name[XSTRLEN(name)] = '\0'; + XSTRNCPY((char*)in->salg_type, type, typeSz); + in->salg_type[typeSz - 1] = '\0'; + XSTRNCPY((char*)in->salg_name, name, nameSz); + in->salg_name[nameSz - 1] = '\0'; }