You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SSLContext#min_version= and #max_version= silently accept prefix strings and empty strings #1158
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-882for (i=0; i<numberof(map); i++)
if (!strncmp(map[i].name, RSTRING_PTR(str), RSTRING_LEN(str)))
returnmap[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)
returnmap[i].version;
(Discussed with @rhenium on security@ruby-lang.org and agreed to track here as a regular bug.)
Activity
ssl: fix string comparison in SSLContext#{min,max}version=
rhenium commentedon Nov 19, 2026
Thank you for reporting it! I've opened #1160 with the suggested patch and a test.
[ruby/openssl] ssl: fix string comparison in SSLContext#{min,max}vers…