On 5/2/11 7:20 AM, Rafal Somla wrote:
> Hi Davi,
> On 29/04/2011 21:52, Davi Arnaut wrote:
>> On 4/29/11 12:10 PM, Rafal Somla wrote:
>>> + /*
>>> + Code for testing the logic for sending the first client payload.
>>> + A fake data of length given by environment variable TEST_PACKET_LENGTH
>>> + (or default 255 bytes) is sent to the server. First 2 bytes of the
>>> + payload contain its total length (LSB first). The length of test data
>>> + is limited to 2048 bytes.
>>> + Upon receiving test data, server will check that data is correct and
>>> + refuse connection. If server detects data errors it will crash on
>>> + assertion.
>>> + This code is executed if debug flag "winauth_first_packet_test" is
>>> + set, e.g. using client option:
>>> + --debug="d,winauth_first_packet_test"
>>> + The same debug flag must be enabled in the server, e.g. using
>>> + statement:
>>> + SET GLOBAL debug= '+d,winauth_first_packet_test';
>>> + */
>>> + static byte test_buf;
>> This is made non-reentrant / thread-unsafe on purpose?
> Yes, kind of... This is code intended not for normal usage but for
> testing protocol logic. It is to be executed from tests where the
> execution context is highly controlled anyway. So I think it is
> justified to make it simple and easy and don't bother with dynamic
> allocation and freeing of the memory. So thought the reviewer, apparently.
The problem is that this behavior is not documented anywhere and neither
your nor the reviewer are going to be forever the sole maintainers of
this non-obvious and prone to break code.
On top, you could just make the buffer local to the stack, there is
nothing worth gaining otherwise.