The allocated buffer needs to be sizeof(char *). What's happening is the address of the buffer (&buffer[0]) gets written to the pointer-to-pointer-to-char, data. If data == NULL, you're asking to write the address of the buffer to unallocated memory.
It's done this way because the return value of the function is the number of valid bytes you can read from that location, and the address must go somewhere for you to get the data from it. I'm sorry this is probably difficult to understand, I don't know if I can explain it more easily. -Kyle H On September 8, 2014 9:19:09 AM PST, "Iñaki Baz Castillo" <i...@aliax.net> wrote: >2014-09-08 16:08 GMT+02:00 Richard Levitte <rich...@levitte.org>: >> Sorry, BIO_flush() isn't what you want (it doesn't reset the buffer >to >> empty), BIO_reset() is. >> >> However, you need to be careful... if I were you, I would use the >> read data before resetting, as BIO_get_mem_data() gives you the >> pointer to the internal BIO_s_mem buffer, not to a duplicate of it. > > >Thanks, it does work. However... I do not understand how... > >This works fine: > >----------------------------------- >long read; >// myBuffer is an already allocated buffer. >char** data = (char**)&myBuffer; > >read = BIO_get_mem_data(bio, data); > >// Use data and read values. > >BIO_reset(bio); >----------------------------------- > >This crashes: > >----------------------------------- >long read; >char** data = NULL; > >read = BIO_get_mem_data(bio, data); > >// Use data and read values. > >BIO_reset(bio); >----------------------------------- > > >Why do I need to provide BIO_get_mem_data() with an already allocated >buffer? I've checked the function and I do not understand what it >does). The only I want is to get the pointer to the BIO's buffer in >which SSL_write() wrote. Why should I provide an allocated buffer? The >BIO already has a buffer and the data is already in there after >calling SSL_write(). Why do I need to pass an allocated buffer? > >Thanks a lot. > >-- >Iñaki Baz Castillo ><i...@aliax.net> >______________________________________________________________________ >OpenSSL Project http://www.openssl.org >User Support Mailing List openssl-users@openssl.org >Automated List Manager majord...@openssl.org -- Sent from my Android device with K-9 Mail. Please excuse my brevity.