[gnutls-devel] gnutls_x509_crt_get_extension_by_oid and NULL buf

Kurt Roeckx kurt at roeckx.be
Sun Jan 26 18:27:30 CET 2014


Hi,

The documentation for gnutls_x509_crt_get_extension_by_oid says
that buf can be NULL.  But looking at the code I see this:

        if (output.size > (unsigned int) *buf_size) {
                *buf_size = output.size;
                _gnutls_free_datum(&output);
                return GNUTLS_E_SHORT_MEMORY_BUFFER;
        }

        *buf_size = output.size;

        if (buf)
                memcpy(buf, output.data, output.size);

That is, if buf is NULL, it's still going to check the size of the
buffer and if it's too small update the size and return
GNUTLS_E_SHORT_MEMORY_BUFFER.

At this point I was only interested in checking the existence of
the extension, and so was expecting to get
GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE back, and if it's not
present it works properly, but if it is present I currently
get GNUTLS_E_SHORT_MEMORY_BUFFER back, unless I set buf_size
to some arbitrary high value.

So my question is if this is intentional or not.  Wouldn't it make
more sense to only give this error in case buf is not NULL?



Kurt





More information about the Gnutls-devel mailing list