Skip to content

Bugfix for onion_websocket_vprintf and onion_websocket_write#276

Open
YggdrasiI wants to merge 2 commits into
davidmoreno:masterfrom
YggdrasiI:websocket_bugfix
Open

Bugfix for onion_websocket_vprintf and onion_websocket_write#276
YggdrasiI wants to merge 2 commits into
davidmoreno:masterfrom
YggdrasiI:websocket_bugfix

Conversation

@YggdrasiI

Copy link
Copy Markdown
Contributor

Hello Mr. Moreno,

I've spotted a problem with 'onion_websocket_write'. This function will used it's argument 'va_list args' twice, but the pointer in the second call will be wrong.
I've found a similar function structure in 'onion_response_vprintf' and copied the solution (va_copy) given there.
The remove of '-1' in the first vsnprintf-call is also adapted from there.

The first commit of this pull request resolves the issue and the problem noted in #275.
The second commit just contains changes to trigger the bug with the example application websocket.c

Other double usages of va_list was not found in 'onion/src'.

Regards Olaf Schulz

This commit resolves two bugs:
1. Return value of onion_websocket_write was not correct in all cases.
2. onion_websocket_vprintf uses va_list-variable twice if internal buffer
	 is too small.  (Every variable argument list can only be used one time.)

   My changes are oriented to onion_response_vprintf, which already
   resolves the problem.

The next commit will contain a modification of the websocket-example
which triggers bug 2.
Without the previous commit the line

   onion_websocket_printf(ws, "Long string: %s", long_string)

will trigger access on uninitialised bytes. The va_list argument
points on the wrong position.

==241250== Syscall param write(buf) points to uninitialised byte(s)
==241250==    at 0x54AF2CF: __libc_write (write.c:26)
==241250==    by 0x54AF2CF: write (write.c:24)
==241250==    by 0x165F0759: onion_http_write (http.c:102)
==241250==    by 0x165F0F3D: onion_websocket_write (websocket.c:239)
==241250==    by 0x165F1386: onion_websocket_vprintf (websocket.c:334)
==241250==    by 0x165F1486: onion_websocket_printf (websocket.c:355)
@davidmoreno

Copy link
Copy Markdown
Owner

Hi,

thanks a lot. I had no time to review it yet. As soon as I review it I will tell you something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants