Hi All,

I am having a doubt BUF_MEM_grow and BUF_MEM_grow_clean. After reallocation of 
buffer we are memsetting the buffer from “str->length” index.

    } else {
        str->data = ret;
        str->max = n;
        memset(&str->data[str->length], 0, len - str->length);
        str->length = len;
    }

I feel we should memset from “str->max”.

1)      One usage of this BUF_MEM is init buffer (s->init_buf) in SSL handshake 
for storing peer’s message and framing response message.

2)      Initially in ssl3_connect and ssl3_accept we are creating this 
s->init_buf of size 16348 bytes.

3)      Later in ssl3_get_message we are using this buffer for receiving peer’s 
handshake message of length “l”. Here we are calling BUF_MEM_grow_clean with 
“(l + 4 + 16)” as length. If (l + 4 +16) is lesser than 16348, then 
“init_buf->length” is set to that.

4)      After parsing the received msg and we are framing the response message 
on the same s->init_buf. For example consider ssl3_send_certificate_request, 
here we are copying Cert types and sign hash algorithm, after that we are 
calling mem grow before copying X509 name of CA cert.

5)      Here, if the data (cert types and sign hash alg) copied before calling 
mem grow is more than (l + 4 + 16) of previously received msg, then it will 
leads to some data loss inside BUF_MEM_grow_clean we are memsetting from 
“data[str->length]”.

In OpenSSL, BUF_MEM is used in many modules like ASN, PEM and SSL. So as per my 
understanding better we should memset from “max” index in case of realloc, like 
below pseudocode.

    } else {
        str->data = ret;
        memset(&str->data[str->max], 0, n �C str->max);
        str->max = n;
        str->length = len;
    }

This we should not do for OPENSSL_malloc, in that case we can memset complete 
buffer.

Regards,
Ashok

________________________________
[Company_logo]

Raja Ashok V K
Huawei Technologies
Bangalore, India
http://www.huawei.com
________________________________
本邮件及其附件含有华为公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁
止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中
的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件!
This e-mail and its attachments contain confidential information from HUAWEI, 
which
is intended only for the person or entity whose address is listed above. Any 
use of the
information contained herein in any way (including, but not limited to, total 
or partial
disclosure, reproduction, or dissemination) by persons other than the intended
recipient(s) is prohibited. If you receive this e-mail in error, please notify 
the sender by
phone or email immediately and delete it!

-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev

Reply via email to