Axel Lin correctly pointed out that there is no buffer overflow because smtp_server[SMTP_MAX_SERVERNAME_LEN + 1] - there is always room for terminating 0 byte

This commit is contained in:
Dirk Ziegelmeier 2017-06-14 14:11:27 +02:00
parent 3611b583f5
commit 3073affaaf

View File

@ -348,13 +348,13 @@ smtp_set_server_addr(const char* server)
if (server != NULL) {
len = strnlen(server, SMTP_MAX_SERVERNAME_LEN); /* strnlen: length WITHOUT terminating 0 byte */
}
if (len >= SMTP_MAX_SERVERNAME_LEN) {
return ERR_MEM; /* too long or no room for terminating 0 byte */
if (len > SMTP_MAX_SERVERNAME_LEN) {
return ERR_MEM;
}
if (len != 0) {
MEMCPY(smtp_server, server, len);
}
smtp_server[len] = 0;
smtp_server[len] = 0; /* always OK because of smtp_server[SMTP_MAX_SERVERNAME_LEN + 1] */
return ERR_OK;
}