SSLContext#min_version= and #max_version= silently accept prefix strings and empty strings

Open Beginner friendly
#1,158 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, ruby
Domain
security

Research direction

The issue points to parse_proto_version() in ext/openssl/ossl_ssl.c and shows the current comparison and suggested length check. Read that function and locate its tests for SSLContext#min_version= and #max_version=. Add coverage for empty strings, prefixes, and embedded NUL bytes, and confirm they raise ArgumentError while full version names still work.

Written by the indexing model from the issue text.

Description

Description

parse_proto_version() in ext/openssl/ossl_ssl.c compares the input protocol version name using strncmp(map[i].name, RSTRING_PTR(str), RSTRING_LEN(str)) without verifying that the string lengths match.

// ext/openssl/ossl_ssl.c:879-882
    for (i = 0; i < numberof(map); i++)
        if (!strncmp(map[i].name, RSTRING_PTR(str), RSTRING_LEN(str)))
            return map[i].version;
    rb_raise(rb_eArgError, "unrecognized version %+"PRIsVALUE, str);
Actual Behavior

Because only RSTRING_LEN(str) bytes are compared:

  • "" (empty string), "S", or "SSL" silently matches "SSL2" (SSL2_VERSION)
  • "T", "TLS", or :TLS silently matches "TLS1" (TLS1_VERSION)
  • Strings with embedded NUL bytes (e.g., "TLS1\0_3") silently match "TLS1" (TLS1_VERSION)
Expected Behavior

Empty strings, partial prefixes, and strings containing embedded NUL bytes should raise ArgumentError (unrecognized version).

Suggested Fix

Verify that the string lengths are equal and compare using memcmp():

    for (i = 0; i < numberof(map); i++)
        if ((size_t)RSTRING_LEN(str) == strlen(map[i].name) &&
            memcmp(map[i].name, RSTRING_PTR(str), RSTRING_LEN(str)) == 0)
            return map[i].version;

(Discussed with @rhenium on [email protected] and agreed to track here as a regular bug.)

Dominant language
C
Stars
276
Forks
205
Avg merge
21h 17m
Merged PRs (30d)
17

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/openssl

All issues in ruby/openssl

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.