[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] Off by one error in HTTP message handling or documentation error



Hello,

I'm using libevent-2.0.10-stable and have a problem in my libevent based
HTTP client (and service).

I'm using the following construction (pseudo-codish):

evbuffer_add(
        evhttp_request_get_output_buffer(
            evhttp_request_new(polling_callback, NULL)
        ),
        string, strlen(string)
    )

The string is a simple null-terminated string. In my example the string is
never of length 0 or NULL.

When I use this from my libevent based client, the libevent based service
goes nuts and returns part of the HTTP POST info back into my client's
buffer. This is more easily triggered when I restart the service, as the
effect is then easily reproduced.


I came to the following simple solution:

evbuffer_add(
        evhttp_request_get_output_buffer(
            evhttp_request_new(polling_callback, NULL)
        ),
        string, strlen(string) + 1
    )


And now the client and service are rock solid again. No input/output
evbuffer content spill-overs.

When looking at the evbuffer_add() docs, like here:
http://monkey.org/~provos/libevent/doxygen-2.0.1/buffer_8h.html#69c3b8893a49bdd919642c6920c1fcb4

the doc doesn't seem to state that I need to include the '\0' into the
buffer. Perhaps the documentation is OK, and I should have been able to
exclude the '\0' from being included in the buffer. In that latter case I
would look for a bug in the code region that is assembling the HTTP request
messages that go over the wire.

Bottomline:
Did I initially use it wrongly? If so, please state in the docs that I
should have included the '\0'. Did I stumble upon an error?


regards,

	Oscar Koeroo

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature