Skip to content

x509asn1: improve encodeOID#21003

Closed
bagder wants to merge 6 commits intomasterfrom
bagder/encodeoid
Closed

x509asn1: improve encodeOID#21003
bagder wants to merge 6 commits intomasterfrom
bagder/encodeoid

Conversation

@bagder
Copy link
Copy Markdown
Member

@bagder bagder commented Mar 19, 2026

  • return error on OOM or doing too large output
  • fix full 32-bit number support
  • fix the broken handling of the first and second numbers
  • support up to 32-bit minus 80 for the second number
  • a field with a leading 0x80 is now considered an error, since it only works as padding and is then no longer the shortest possible version

Add unit tests in 1666

Bonus: removed the last argument to OID2str() as it was always set TRUE.

@bagder bagder marked this pull request as ready for review March 19, 2026 10:31
@bagder bagder requested a review from Copilot March 19, 2026 10:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the ASN.1 OBJECT IDENTIFIER (OID) string encoding logic in lib/vtls/x509asn1.c and adds a new unit test suite to validate edge cases and limits around OID decoding/formatting.

Changes:

  • Reworks encodeOID() to better handle large (32-bit) OID components, add stricter validation, and propagate dynbuf errors (OOM/too large output).
  • Simplifies OID2str() by removing an always-TRUE “symbolic” argument and always performing the symbolic lookup via dotted form.
  • Adds new unit test unit1666 plus build-system wiring to run it.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
lib/vtls/x509asn1.c Updates OID decoding (encodeOID) and simplifies OID2str call sites.
tests/unit/unit1666.c New unit test coverage for encodeOID() behavior and edge cases.
tests/unit/Makefile.inc Registers unit1666.c in the unit test bundle (Autotools).
tests/unit/Makefile.am Adjusts unit test include paths (Autotools).
tests/unit/CMakeLists.txt Adds include path for unit build (CMake).
tests/data/test1666 New test case definition for running unit1666 via the test harness.
tests/data/Makefile.am Registers test1666 in the test data list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread tests/unit/unit1666.c Outdated
Comment thread tests/unit/unit1666.c Outdated
Comment thread tests/unit/unit1666.c Outdated
Comment thread lib/vtls/x509asn1.c
Comment thread lib/vtls/x509asn1.c
Comment thread tests/unit/unit1666.c Outdated
Comment thread tests/unit/unit1666.c Outdated
vszakats pushed a commit to vszakats/curl that referenced this pull request Mar 19, 2026
- return error on OOM or doing too large output
- fix full 32-bit number support
- fix the broken handling of the first and second numbers
- support up to 32-bit minus 80 for the second number
- a field with a leading 0x80 is now considered an error, since it only works as padding and is then no longer the shortest possible version

Add unit tests in 1666

Bonus: removed the last argument to OID2str() as it was always set TRUE.

Closes curl#21003
@bagder bagder force-pushed the bagder/encodeoid branch from 1d4b75e to 5eaa1f2 Compare March 19, 2026 10:51
@bagder
Copy link
Copy Markdown
Member Author

bagder commented Mar 19, 2026

augment review

@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Mar 19, 2026

🤖 Augment PR Summary

Summary: Improves ASN.1 OID decoding/formatting in the X.509 parser and adds a dedicated unit test.

Changes:

  • Reworks encodeOID() to properly decode the first subidentifier (first/second arcs), support full 32-bit subidentifiers, and propagate OOM/too-large-output errors via dynbuf return codes.
  • Tightens validation by rejecting non-minimal base-128 encodings that use leading 0x80 padding and by rejecting overlong/overflowing encodings.
  • Simplifies OID2str() by removing the always-true symbolic argument and always performing symbolic lookup from an intermediate dotted OID string.
  • Adds unit test 1666 (plus build-system wiring and testcase metadata) to exercise valid/invalid OID encodings, boundary values, and size-limit behavior.

Technical Notes: The second arc is effectively limited to UINT32_MAX - 80 by construction; invalid encodings now consistently return CURLE_BAD_FUNCTION_ARGUMENT and oversized output returns CURLE_TOO_LARGE.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 4 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread lib/vtls/x509asn1.c
Comment thread tests/unit/unit1666.c
Comment thread tests/unit/unit1666.c Outdated
Comment thread tests/unit/unit1666.c
Comment thread tests/unit/CMakeLists.txt Outdated
Comment thread tests/unit/Makefile.am Outdated
bagder added 5 commits March 19, 2026 12:55
- return error on OOM or doing too large output
- fix full 32-bit number support
- fix the broken handling of the first and second numbers
- support up to 32-bit minus 80 for the second number
- a field with a leading 0x80 is now considered an error, since it only
  works as padding and is then no longer the shortest possible version

Add unit tests in 1666

Bonus: removed the last argument to OID2str() as it was always set TRUE.
@bagder bagder force-pushed the bagder/encodeoid branch from 2b4dce5 to 6434f2c Compare March 19, 2026 12:00
@bagder
Copy link
Copy Markdown
Member Author

bagder commented Mar 19, 2026

@aisle-analyzer

@aisle-research-bot
Copy link
Copy Markdown

aisle-research-bot bot commented Mar 19, 2026

🔒 Aisle Security Analysis

✅ We scanned this PR and did not find any security vulnerabilities.

Aisle supplements but does not replace security review.


Analyzed PR: #21003 at commit 5fd4d09

Last updated on: 2026-03-19T12:24:11Z

@bagder bagder closed this in 673e14c Mar 19, 2026
@bagder bagder deleted the bagder/encodeoid branch March 19, 2026 12:56
vszakats added a commit that referenced this pull request Mar 19, 2026
Fixing clang-tidy warning:
```
tests/unit/unit1666.c:50:12: error: call to undeclared function 'encodeOID'; ISO C99 and later do not support implicit function declarations [clang-diagnostic-implicit-function-declaration]
   50 |   result = encodeOID(dbuf, oid, oid + spec->size);
      |            ^
```
Ref: https://github.com/curl/curl/actions/runs/23297585235/job/67749144361?pr=21008#step:46:736

Follow-up to 673e14c #21003

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

Development

Successfully merging this pull request may close these issues.

3 participants