Skip to content

esp_ping session does not stop when count is greater than 65535 (IDFGH-17693) #88

Description

@brabema

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate
  • Read the documentation to confirm the issue is not addressed there and your configuration is set correctly
  • Tested with the latest version to ensure the issue hasn't been fixed

How often does this bug occurs?

always

Expected behavior

A finite ping session should stop after the configured number of ping procedures.

Since esp_ping_config_t::count is a uint32_t and 0 is documented separately as infinite mode, any non-zero count value should be treated as a finite count.

For example, if config.count = 65536, the session should send 65536 ping requests and then call the on_ping_end callback.

If values greater than UINT16_MAX are not intended to be supported, esp_ping_new_session() should reject such configurations with ESP_ERR_INVALID_ARG instead of accepting them and running indefinitely.

Actual behavior (suspected bug)

For config.count >= 65536, the ping session does not appear to stop after the configured number of ping procedures.

The implementation uses the 16-bit ICMP sequence number in the loop condition:

(ep->count == 0) || (ep->packet_hdr->seqno < ep->count)

Steps to reproduce the behavior

  1. Download and extract the attached reproducer project:
    [ping_seqno_wrap_repro_poc.zip](https://github.com/user-attachments/
    files/28095594/ping_seqno_wrap_repro_poc.zip)

  2. Build the attached ESP-IDF project for an ESP32 target.

  3. Flash the built application to an ESP32 device and open the serial monitor.

  4. Wait until the reproducer reaches the 16-bit ICMP sequence number wrap. On the
    tested ESP32 setup.

  5. Confirm that the serial monitor prints the wrap condition and reproduction
    markers:

    seqno wrapped: previous=65535 current=0 transmitted=65536
    REPRODUCED: seqno wrapped while count=65536 was still not reached
    this demonstrates the u16 seqno vs uint32 count loop-condition bug
    
    

The reproducer starts an esp_ping session against 127.0.0.1 with count=65536,
interval_ms=0, and timeout_ms=1. WiFi or external network access is not required,
because the target is the lwIP loopback address. The reproducer stops the ping
session only after observing that the 16-bit sequence number wrapped while the
configured 32-bit count had not been naturally completed.

Project release version

lwIP 2.2.0-esp, ESP-IDF v6.0.1

System architecture

Intel/AMD 64-bit (modern PC, older Mac)

Operating system

Linux

Operating system version

openSUSE Leap 15.6, Linux kernel 6.4.0-150600.23.103-default.

Shell

ZSH

Additional context

The reproducer starts an esp_ping session against 127.0.0.1 with count=65536,
interval_ms=0, and timeout_ms=1. WiFi or external network access is not required,
because the target is the lwIP loopback address. The reproducer stops the ping
session only after observing that the 16-bit sequence number wrapped while the
configured 32-bit count had not been naturally completed.

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions