Skip to content

Fixed nullptr crash in ETH IP comparing code - #5796

Open
Tarik2142 wants to merge 1 commit into
wled:mainfrom
Tarik2142:main
Open

Fixed nullptr crash in ETH IP comparing code#5796
Tarik2142 wants to merge 1 commit into
wled:mainfrom
Tarik2142:main

Conversation

@Tarik2142

@Tarik2142 Tarik2142 commented Aug 10, 2026

Copy link
Copy Markdown

This PR fixes a nullptr crash when using ethernet.
The current implementation treats the passed value as a pointer, and since it is 0, it causes a crash.
image
Сomparing with IPAddress() is a more reliable option.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Ethernet static IP configuration validation.
    • Static IP and gateway settings are now applied only when valid network configuration data is available.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: db91c1e4-61fb-47ae-a767-4d74cb8e9cff

📥 Commits

Reviewing files that changed from the base of the PR and between d9b9a84 and c36fd97.

📒 Files selected for processing (1)
  • wled00/network.cpp

Walkthrough

The Ethernet static IP configuration check now requires a multiWiFi entry and non-default IPAddress values for the static IP and gateway before applying ETH.config.

Changes

Ethernet static IP configuration

Layer / File(s) Summary
Validate Ethernet settings
wled00/network.cpp
The static Ethernet configuration check now guards against an empty multiWiFi list and compares staticIP and staticGW with default IPAddress values.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: softhack007

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: fixing a nullptr crash in Ethernet IP comparison code.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@softhack007

softhack007 commented Aug 10, 2026

Copy link
Copy Markdown
Member

@Tarik2142 can you explain a bit more on which build this crash is happening?

  • WLED version
  • using a "V4" build (16.0.1) or a "V5" (17.0.0-devV5) ?

The cast to (uint32_t) was added to enforce that the uint32_t overload of "==" gets used, this overload should also handle nullptr properly - at least in the new framework.

Comment thread wled00/network.cpp

// https://github.com/wled/WLED/issues/5247
if (multiWiFi[0].staticIP != (uint32_t)0x00000000 && multiWiFi[0].staticGW != (uint32_t)0x00000000) {
if (multiWiFi.size() && multiWiFi[0].staticIP != IPAddress() && multiWiFi[0].staticGW != IPAddress()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be that the addition of if (multiWiFi.size() is the actual fix.

@coderabbitai how is IPAddress() defined? Is it the same as 0.0.0.0 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '=== IPAddress declarations/uses ==='
rg -n -C 3 'class IPAddress|IPAddress::IPAddress|IPAddress\(\)' \
  -g '*.{h,hpp,cpp,ino}' .

printf '%s\n' '=== Arduino-ESP32 framework version references ==='
rg -n -C 2 'arduino-esp32|ESP_ARDUINO_VERSION|platform.*espressif32' \
  -g 'platformio.ini' -g 'platformio*.ini' -g 'package.json' -g '*.json' -g '*.md' .

Length of output: 14902


@softhack007, yes. In Arduino-ESP32, a default-constructed IPAddress() has all four IPv4 octets set to zero. It represents 0.0.0.0.

The two changes address different conditions:

  • multiWiFi.size() prevents access to multiWiFi[0] when the vector is empty. This can be the crash fix if no Wi-Fi entry exists.
  • staticIP != IPAddress() and staticGW != IPAddress() compare two IPAddress objects. This selects the IPAddress comparison overload.

The old (uint32_t)0x00000000 value can convert to a null pointer. It then selects the const uint8_t * comparison overload shown in the Comment image. That overload reads the pointer as address bytes, so it can dereference nullptr.

Therefore, IPAddress() is the correct explicit test for 0.0.0.0, and multiWiFi.size() is the required bounds guard. Both changes are valid.
🐇🔍

You are interacting with an AI system.

@Tarik2142

Copy link
Copy Markdown
Author

@Tarik2142 can you explain a bit more on which build this crash is happening?

  • WLED version
  • using a "V4" build (16.0.1) or a "V5" (17.0.0-devV5) ?

The cast to (uint32_t) was added to enforce that the uint32_t overload of "==" gets used, this overload should also handle nullptr properly - at least in the new framework.

I am working on a fork for ESP32-S3 + W5500 ethernet https://github.com/smlight-tech/A1-SLWF-09-WLED
And I found this crash on the S3 variant, I didn't check for the regular ESP32.
Crash dump looks like this:
image

I can say for sure that multiWiFi.size() is not the fix. I added that first but it didn't work. Then I replaced (uint32_t)0x00000000 and it fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants