mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-12-26 03:16:18 +00:00
smtp.c, smtp_set_server_addr: Avoid smtp_server buffer overrun when server name length is SMTP_MAX_SERVERNAME_LEN -> "smtp_server[len] = 0" is an out-of-bound access
This commit is contained in:
parent
4af438916a
commit
3611b583f5
@ -65,7 +65,7 @@
|
||||
#include "lwip/altcp_tcp.h"
|
||||
#include "lwip/altcp_tls.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <string.h> /* strnlen, memcpy */
|
||||
#include <stdlib.h>
|
||||
|
||||
/** TCP poll interval. Unit is 0.5 sec. */
|
||||
@ -346,10 +346,10 @@ smtp_set_server_addr(const char* server)
|
||||
{
|
||||
size_t len = 0;
|
||||
if (server != NULL) {
|
||||
len = strlen(server);
|
||||
len = strnlen(server, SMTP_MAX_SERVERNAME_LEN); /* strnlen: length WITHOUT terminating 0 byte */
|
||||
}
|
||||
if (len > SMTP_MAX_SERVERNAME_LEN) {
|
||||
return ERR_MEM;
|
||||
if (len >= SMTP_MAX_SERVERNAME_LEN) {
|
||||
return ERR_MEM; /* too long or no room for terminating 0 byte */
|
||||
}
|
||||
if (len != 0) {
|
||||
MEMCPY(smtp_server, server, len);
|
||||
|
@ -24,7 +24,7 @@ extern "C" {
|
||||
#define SMTP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
/** Maximum length reserved for server name */
|
||||
/** Maximum length reserved for server name including terminating 0 byte */
|
||||
#ifndef SMTP_MAX_SERVERNAME_LEN
|
||||
#define SMTP_MAX_SERVERNAME_LEN 256
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user