Skip to content

ESP32 and IoT-Safe: check the bound before reading in three loops - #12045

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:esp32_iotsafe_bounds
Open

dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:esp32_iotsafe_bounds

Conversation

@dgarske

@dgarske dgarske commented Nov 6, 2026

Copy link
Copy Markdown
Member

Description

Three loops read an element before checking that its index was in range:

  • esp_clean_result() in the ESP32 math port: read one digit past the array, and was bounded by a fixed 128 rather than the number's allocated size. It now uses Z->size with SP math and FP_SIZE with fast math, and checks the bound first.
  • show_macro() in the ESP32 utilities: checked the bound last. No out-of-bounds access was possible here, as the input is a terminated string.
  • _write() in the IoT-Safe example: read one byte past a buffer with no terminator.

Fixes ZD22754. Reported by Md. Raisul Islam Mobin (https://mobin.tech | @mobin2021).

Testing

The reporter's harness under AddressSanitizer reports each read with the old conditions and none with the new ones. Not built for ESP32 or the IoT-Safe target: no toolchain for either was available.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@dgarske dgarske self-assigned this Nov 6, 2026
Copilot AI balanced review requested due to automatic review settings November 6, 2026 17:51

Copilot AI left a comment

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.

🟢 Approval recommended

No active review issues are recorded for the bounds-check ordering and ESP32 cleanup-limit changes.

No open issues 🎉

What changed in this PR

This PR fixes bounds-check ordering in the ESP32 port and IoT-Safe example, preventing reads past numeric and output buffers.

Changes:

  • Check array and buffer bounds before reading elements in three loops.
  • Bound ESP32 math cleanup by the number’s capacity rather than a fixed 128-digit limit.
  • Reorder the ESP32 string-loop checks defensively; terminated inputs were already safe.
File Description
wolfcrypt/​src/​port/​Espressif/​esp32_util.c Check the string-copy limit before reading characters.
wolfcrypt/​src/​port/​Espressif/​esp32_mp.c Use the digit capacity and check bounds before reading during cleanup.
IDE/​iotsafe/​devices.c Check the output-buffer boundary before dereferencing the pointer.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12045

Scan targets checked: wolfcrypt-port-bugs
Not reviewed (no scan target covers them): IDE/iotsafe/devices.c
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

@dgarske dgarske assigned mattia-moffa and wolfSSL-Bot and unassigned dgarske Nov 6, 2026
@dgarske
dgarske requested a review from mattia-moffa November 6, 2026 22:37
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.

5 participants