Openenclave: OE checks whether a size_t variable is negative

Created on 12 Aug 2020  路  3Comments  路  Source: openenclave/openenclave

On this line, we are checking if a size_t variable bytes_written is <= 0. So even if the function mbedtls_x509write_crt_der returns a negative number to indicate error, we will never detect it.

We are lucky that mbedtls_x509write_crt_der never failed until today when I tried to generate an EEID based certificate and that triggered MBEDTLS_ERR_ASN1_BUF_TOO_SMALL.

bug good first issue triaged

Most helpful comment

It probably will actual complain if the expression is < 0. There is a 1/INT_MAX chance ==0 could catch an error.

All 3 comments

An interesting questions is why the compiler did not complain that <= 0 does not make sense for a size_t variable.

It probably will actual complain if the expression is < 0. There is a 1/INT_MAX chance ==0 could catch an error.

size_t is the wrong type since mbedtls_x509write_crt_der can return a negative value on failure.
Follow up on Anand's question.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dthaler picture dthaler  路  5Comments

manojrupireddy picture manojrupireddy  路  6Comments

maverick-zhn picture maverick-zhn  路  7Comments

wintersteiger picture wintersteiger  路  8Comments

andschwa picture andschwa  路  3Comments