<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Thanks Rich and Michael.</div><div><br></div><div>That was it, I was under the impression that these set functions would behave like those i2d function that would put the actual data inside... as I don't want to deal with the deallocation later (as I am modifying apache's mod_ssl). This seems to work as I can immediately read it back (before I couldn't) with get_ex_data.</div><div><br></div><div><br></div><div>Do I still need to call SSL_set_session to put the updated session back in the SSL?</div><div>According to the documentation:</div><div>"If there is already a session set inside ssl (because it was set with SSL_set_session() before or because the same ssl was already used for a connection), SSL_SESSION_free() will be called for that session."<br></div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> BLAH b;<br>
> b.blah = 12345;<br>
><br>
> SSL_SESSION *session = SSL_get_session(ssl);<br>
> SSL_SESSION_set_ex_data(<wbr>session, my_data_idx, &b);<br>
> SSL_set_session(ssl, sess);<br>
<br>
Is "b" a stack variable?  You should malloc it.<br>
<br>
--<br>
Senior Architect, Akamai Technologies<br>
IM: <a href="mailto:richsalz@jabber.at">richsalz@jabber.at</a> Twitter: RichSalz<br>
<br>
------------------------------<br>
<br><br>
(Top-posting because Outlook still can't handle HTML email correctly.)<br>
<br>
Unless I'm missing something, you're using the OpenSSL functions correctly - though I admit I just looked at them here and didn't check the documentation or my own use of them. Perhaps you're not using C correctly.<br>
<br>
We can't tell what the storage class of "b" is, because we don't have context. Is it static or automatic? If it's automatic, then as soon as it goes out of scope, bang - the pointer you've stored is invalid.<br>
<br>
The pointer you store should be to an object of static or dynamic storage class. Static doesn't generally make sense, unless your sessions need to be associated with one of a handful of objects that don't change after creation. More typically you'd use a dynamic object. For example:<br>
<br>
                static const BLAH blah0 = {0};<br>
                BLAH *bp = malloc(sizeof *bp);<br>
                if (! bp) { error handling }<br>
                *bp = blah0;<br>
                bp->b = 12345;<br>
                ...<br>
                SSL_SESSION_set_ex_data(<wbr>session, my_data_idx, bp);<br>
<br>
If you're using C++, of course, you'd want to create an object instance using operator new, rather than calling malloc. But the principle remains the same - don't use a pointer to an object which will be invalidated when it goes out of scope.<br>
<br>
Michael Wojcik<br>
Distinguished Engineer, Micro Focus<br>
<br><br>
</blockquote></div><br></div></div>