Skip to content

Guard vdata_make() against strdup(NULL) for DATA_FORMAT#213

Merged
NorthernMan54 merged 1 commit into
NorthernMan54:mainfrom
1technophile:fix/2317-vdata-make-null-strdup
Jun 19, 2026
Merged

Guard vdata_make() against strdup(NULL) for DATA_FORMAT#213
NorthernMan54 merged 1 commit into
NorthernMan54:mainfrom
1technophile:fix/2317-vdata-make-null-strdup

Conversation

@1technophile

Copy link
Copy Markdown
Contributor

A decoder passing a NULL format to data_make/data_int/data_dbl reaches vdata_make()'s DATA_FORMAT case, which calls strdup() on the argument unconditionally. strdup(NULL) is undefined and dereferences a null pointer, crashing the decoder task with a LoadProhibited exception (EXCVADDR 0x0) and rebooting the gateway.

This is reachable from normal operation: digitech_xc0324_decode() emits its 'message_num' field with a NULL format
(data_int(data, "message_num", "Message repeat count", NULL, events)), so any successful XC-0324 decode -- including the false-positive decodes that ambient RF noise produces every few hours -- crashes the device. Captured on an ESP32 as:

Guru Meditation Error: Core 1 panic'ed (LoadProhibited)
... strlen <- _strdup_r <- strdup <- vdata_make <- data_int
<- digitech_xc0324_decode <- pulse_slicer_ppm <- run_ook_demods

Read the format into a temporary and only strdup() it when non-NULL, leaving format NULL otherwise. A NULL format is legitimate and widely used; the output backends already treat it as optional (the JSON string formatter does UNUSED(format)).

Fixes the reboots reported in 1technophile/OpenMQTTGateway#2317.

A decoder passing a NULL format to data_make/data_int/data_dbl reaches
vdata_make()'s DATA_FORMAT case, which calls strdup() on the argument
unconditionally. strdup(NULL) is undefined and dereferences a null
pointer, crashing the decoder task with a LoadProhibited exception
(EXCVADDR 0x0) and rebooting the gateway.

This is reachable from normal operation: digitech_xc0324_decode() emits
its 'message_num' field with a NULL format
(data_int(data, "message_num", "Message repeat count", NULL, events)),
so any successful XC-0324 decode -- including the false-positive decodes
that ambient RF noise produces every few hours -- crashes the device.
Captured on an ESP32 as:

  Guru Meditation Error: Core 1 panic'ed (LoadProhibited)
  ... strlen <- _strdup_r <- strdup <- vdata_make <- data_int
      <- digitech_xc0324_decode <- pulse_slicer_ppm <- run_ook_demods

Read the format into a temporary and only strdup() it when non-NULL,
leaving format NULL otherwise. A NULL format is legitimate and widely
used; the output backends already treat it as optional (the JSON string
formatter does UNUSED(format)).

Fixes the reboots reported in 1technophile/OpenMQTTGateway#2317.
@NorthernMan54 NorthernMan54 merged commit 84cb023 into NorthernMan54:main Jun 19, 2026
2 checks passed
@NorthernMan54

Copy link
Copy Markdown
Owner

@1technophile Caught me at the desktop, published as 0.5.1

Tks very much

@1technophile 1technophile deleted the fix/2317-vdata-make-null-strdup branch June 20, 2026 01:06
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