Skip to content

Fix error handling in wolfTPM examples - #598

Merged
dgarske merged 9 commits into
wolfSSL:masterfrom
aidangarske:examples-fixes-11902
Sep 10, 2026
Merged

Fix error handling in wolfTPM examples#598
dgarske merged 9 commits into
wolfSSL:masterfrom
aidangarske:examples-fixes-11902

Conversation

@aidangarske

Copy link
Copy Markdown
Member
F-11902, F-11904, F-11905, F-11906, F-11907, F-13455, F-13458, F-13528

@aidangarske aidangarske self-assigned this Sep 9, 2026
Copilot AI lite review requested due to automatic review settings September 9, 2026 00:54

Copilot AI 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.

🟡 Changes recommended

There are a few correctness/debuggability gaps in the updated error handling (including a potential UINT64 wrap in clock_set.c) that should be addressed before merge.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR tightens error handling and correctness in several wolfTPM example programs, reducing “silent success/failure” cases and avoiding insecure example behavior (notably certificate verification override).

Changes:

  • TLS verify callback now honors preverify instead of always overriding certificate failures.
  • Example utilities improve file I/O error handling (open/write/read) and propagate failures via rc/goto exit.
  • Timestamp and PCR examples adjust time/digest handling for more correct behavior across build configurations.
File summaries
File Description
examples/tls/tls_common.h Stop overriding certificate verification failures; return preverify.
examples/timestamp/clock_set.c Treat CLI argument as a forward increment (adds to current clock).
examples/pkcs7/pkcs7.c Fail fast on output file open failure in two code paths.
examples/pcr/quote.c Add explicit open/write failure handling when saving quote output.
examples/pcr/extend.c Improve file read loop error handling; add “digest-from-file” path when wolfCrypt is disabled.
examples/attestation/make_credential.c Check wolfTPM2_GetRandom result; harden file write handling for output blob/secret.
Review details

Suppressed comments (1)

examples/pkcs7/pkcs7.c:314

  • On file open failure, this now returns -1 but doesn't print any error, which makes it hard to diagnose why the example failed. Emit a message that includes the output path before exiting.
    else {
        rc = -1; goto exit;
    }
  • Files reviewed: 6/6 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread examples/pcr/extend.c
Comment thread examples/timestamp/clock_set.c
Comment thread examples/pkcs7/pkcs7.c
@aidangarske
aidangarske marked this pull request as ready for review September 9, 2026 16:28
@aidangarske
aidangarske requested a review from dgarske September 9, 2026 18:52
Comment thread examples/tls/tls_common.h
dgarske
dgarske previously approved these changes Sep 9, 2026
dgarske
dgarske previously approved these changes Sep 9, 2026
@dgarske
dgarske merged commit 338f56f into wolfSSL:master Sep 10, 2026
217 checks passed
@aidangarske
aidangarske deleted the examples-fixes-11902 branch September 10, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants