GCC-8 string fixes

1. Modify wolfSSL_get_ciphers() to limit the XSTRNCPY based on the dst buf length, not the src string.
This commit is contained in:
John Safranek
2018-06-20 15:55:03 -07:00
parent 2e1a1681ec
commit ed208efc4d

View File

@@ -692,30 +692,25 @@ char* wolfSSL_get_cipher_list_ex(WOLFSSL* ssl, int priority)
int wolfSSL_get_ciphers(char* buf, int len) int wolfSSL_get_ciphers(char* buf, int len)
{ {
const CipherSuiteInfo* ciphers = GetCipherNames(); const CipherSuiteInfo* ciphers = GetCipherNames();
int totalInc = 0; int ciphersSz = GetCipherNamesSize();
int step = 0; int i;
char delim = ':'; int cipherNameSz;
int size = GetCipherNamesSize();
int i;
if (buf == NULL || len <= 0) if (buf == NULL || len <= 0)
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
/* Add each member to the buffer delimited by a : */ /* Add each member to the buffer delimited by a : */
for (i = 0; i < size; i++) { for (i = 0; i < ciphersSz; i++) {
step = (int)(XSTRLEN(ciphers[i].name) + 1); /* delimiter */ cipherNameSz = (int)XSTRLEN(ciphers[i].name);
totalInc += step; if (cipherNameSz + 1 < len) {
XSTRNCPY(buf, ciphers[i].name, len);
buf += cipherNameSz;
/* Check to make sure buf is large enough and will not overflow */ if (i < ciphersSz - 1)
if (totalInc < len) { *buf++ = ':';
size_t cipherLen = XSTRLEN(ciphers[i].name); *buf = 0;
XSTRNCPY(buf, ciphers[i].name, cipherLen);
buf += cipherLen;
if (i < size - 1) len -= cipherNameSz + 1;
*buf++ = delim;
else
*buf++ = '\0';
} }
else else
return BUFFER_E; return BUFFER_E;