mirror of
https://github.com/esphome/esphome.git
synced 2026-09-17 01:58:39 +00:00
Address review: add TCP type check and null optval guard
- Check NETCONNTYPE_GROUP is NETCONN_TCP before accessing tcp_pcb - Add optval != nullptr guard before dereferencing in fast path
This commit is contained in:
@@ -59,7 +59,7 @@ class BSDSocketImpl {
|
||||
#if defined(USE_LWIP_FAST_SELECT) && defined(CONFIG_LWIP_TCPIP_CORE_LOCKING)
|
||||
// Fast path for TCP_NODELAY: directly set the pcb flag under the TCPIP core lock,
|
||||
// bypassing lwip_setsockopt overhead (socket lookups, hook, switch cascade, refcounting).
|
||||
if (level == IPPROTO_TCP && optname == TCP_NODELAY && optlen == sizeof(int)) {
|
||||
if (level == IPPROTO_TCP && optname == TCP_NODELAY && optlen == sizeof(int) && optval != nullptr) {
|
||||
LwIPLock lock;
|
||||
if (esphome_lwip_set_nodelay(this->cached_sock_, *reinterpret_cast<const int *>(optval) != 0))
|
||||
return 0;
|
||||
|
||||
@@ -55,7 +55,7 @@ class LwIPSocketImpl {
|
||||
#if defined(USE_LWIP_FAST_SELECT) && defined(CONFIG_LWIP_TCPIP_CORE_LOCKING)
|
||||
// Fast path for TCP_NODELAY: directly set the pcb flag under the TCPIP core lock,
|
||||
// bypassing lwip_setsockopt overhead (socket lookups, hook, switch cascade, refcounting).
|
||||
if (level == IPPROTO_TCP && optname == TCP_NODELAY && optlen == sizeof(int)) {
|
||||
if (level == IPPROTO_TCP && optname == TCP_NODELAY && optlen == sizeof(int) && optval != nullptr) {
|
||||
LwIPLock lock;
|
||||
if (esphome_lwip_set_nodelay(this->cached_sock_, *reinterpret_cast<const int *>(optval) != 0))
|
||||
return 0;
|
||||
|
||||
@@ -220,6 +220,8 @@ void esphome_lwip_hook_socket(struct lwip_sock *sock) {
|
||||
bool esphome_lwip_set_nodelay(struct lwip_sock *sock, bool enable) {
|
||||
if (sock == NULL || sock->conn == NULL || sock->conn->pcb.tcp == NULL)
|
||||
return false;
|
||||
if (NETCONNTYPE_GROUP(sock->conn->type) != NETCONN_TCP)
|
||||
return false;
|
||||
if (enable) {
|
||||
tcp_nagle_disable(sock->conn->pcb.tcp);
|
||||
} else {
|
||||
|
||||
@@ -70,7 +70,7 @@ void esphome_lwip_wake_main_loop_from_isr(int *px_higher_priority_task_woken);
|
||||
/// Must be called with the TCPIP core lock held (LwIPLock in C++).
|
||||
/// This bypasses lwip_setsockopt() overhead (socket lookups, switch cascade,
|
||||
/// hooks, refcounting) — just a direct pcb->flags bit set/clear.
|
||||
/// Returns true if successful, false if sock/conn/pcb is NULL.
|
||||
/// Returns true if successful, false if sock/conn/pcb is NULL or the socket is not TCP.
|
||||
bool esphome_lwip_set_nodelay(struct lwip_sock *sock, bool enable);
|
||||
|
||||
/// Wake the main loop task from any context (ISR, thread, or main loop).
|
||||
|
||||
Reference in New Issue
Block a user