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

未关闭 适合新手
#1,158 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c, ruby
领域
security

调研方向

Issue 指向 ext/openssl/ossl_ssl.c 中的 parse_proto_version(),并展示了当前的比较方式和建议的长度检查。阅读该函数,并找到 SSLContext#min_version= 和 #max_version= 的测试。补充对空字符串、前缀和嵌入 NUL 字节的测试,并确认它们会引发 ArgumentError,而完整的版本名称仍能正常工作。

由索引模型根据 Issue 内容生成。

描述

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.)

主要语言
C
星标
276
派生
205
平均合并
21 小时 17 分钟
30 天内合并 PR
17

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ruby/openssl 的其他 Issue

查看 ruby/openssl 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。