几年前,我刚刚看到这篇关于安全漏洞的分析文章,CVE-2013-2028,作者 vnsecurity .
但是,我对第一点很感兴趣,说这个错误本质上是由整数符号不匹配引起的。
It simply parses the chunked size input as hex and convert it to base of 10. And since ctx->size is defined with size_t, an unsigned type, the value of the variable can be misinterpreted as negative number when casting to signed type, as we will see later.
因为我对此很好奇,所以我去搜索“ctx”的struct
,我遇到了这个:
struct ngx_http_chunked_s {
ngx_uint_t state;
off_t size;
off_t length;
};
据我所知,ctx->size
不是size_t
而是off_t
,它是一个有符号整数。那么,请问我是不是理解错了,还是措辞有误。
可以在这个 repo 中找到较旧的 nginx 版本.
提前致谢!
最佳答案
通过快速阅读,我认为作者对 ngx_http_read_discarded_request_body
有点困惑。的本地size
和 ctx->size
.
输入的路径是:
-
ngx_http_parse_chunked:2011
:ctx->size
是一个带符号的输入。 -
ngx_http_parse_chunked:2183
: 签名ctx->length
根据ctx->size
设置. -
ngx_http_discard_request_body_filter:735
: 签名r->headers_in.content_length_n
设置为ctx->length
. -
ngx_http_read_discarded_request_body:649
:r->headers_in.content_length_n
将转换为size_t
并分配给size
(如果content_length_n < NGX_HTTP_DISCARD_BUFFER_SIZE
,如果0 > content_length_n
则始终为真)。 -
ngx_http_read_discarded_request_body:652
:r->connection->recv
被称为size
作为要读取的字节数。 -
ngx_http_read_discarded_request_body
:size > sizeof (buffer)
(NGX_HTTP_DISCARD_BUFFER_SIZE
)。因此,会出现栈溢出。
我希望这是可以理解的。
关于c++ - Nginx 有符号整数,CVE-2013-2028,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39342233/