Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AES_encrypt crash #31

Closed
rmprosser opened this issue Dec 11, 2014 · 11 comments
Closed

AES_encrypt crash #31

rmprosser opened this issue Dec 11, 2014 · 11 comments

Comments

@rmprosser
Copy link

Our app has crashed a number of times with this stack trace:

AES_encrypt + 452
MumbleClient::CryptState::ocb_encrypt(unsigned char const*, unsigned char*, unsigned int, unsigned char const*, unsigned char*) + 66
MumbleClient::CryptState::encrypt(unsigned char const*, unsigned char*, unsigned int) + 72
-[MKCryptState encryptData:] + 166 
-[MKConnection _sendUDPMessage:] + 90

I believe it is triggered by a poor internet connection but haven't been able to reproduce. Any insights appreciated.

@wtmoose
Copy link

wtmoose commented Jul 26, 2017

@0xABC Little late to the party, but did you (or anyone else) ever find a resolution to this crash?

@rmprosser
Copy link
Author

@wtmoose unfortunately nope

@wtmoose
Copy link

wtmoose commented Jul 27, 2017

I'm not a C++ guy, but I believe the issue is that the CryptState variable is never initialized:

struct MKCryptStatePrivate {
	CryptState cs;
};

It seems they're relying on the no argument initializer being invoked implicitly. But it isn't ever called. I added this line in [MKCryptState init] and I haven't seen this crash since:

_priv->cs = CryptState();

Would be interested to hear from a C++ person if this change isn't necessary.

@rmprosser
Copy link
Author

That shouldn't be necessary because cs is not a pointer. That declaration should call the default constructor implicitly. Of course this is Objective-C not pure C++ so who knows.

@mkrautz
Copy link
Contributor

mkrautz commented Jul 27, 2017

No, I believe @wtmoose's analysis is correct. The struct is malloc'd, and I never initialize CryptState properly. Oops.

@wtmoose
Copy link

wtmoose commented Jul 27, 2017

I did verify in the debugger that it isn't initislized without my change.

@mkrautz
Copy link
Contributor

mkrautz commented Jul 27, 2017

ISTM that the easiest/cleanest fix is to replace the MKCryptStatePriv struct in MKCryptState with a pointer to CryptState instead. Then new & delete it in init/dealloc.

PRs welcome. Otherwise I'll fix it soon.

@rmprosser
Copy link
Author

Cool! I guess cs doesn't have a user-declared default constructor. I wonder why this is only a problem some of the time though. Anyway thanks @wtmoose and @mkrautz

mkrautz added a commit to mkrautz/mumblekit that referenced this issue Jul 29, 2017
Previously, the constructor of CryptState was not called
because CryptState was a member of MKCryptStatePriv, which
was allocated via malloc.

This gets rid of MKCryptStatePriv, and instead just keeps a
pointer to the private CryptState implementation directly in
MKCryptState. As a result, we now allocate a new CryptState via
'new' in init, and clean it up in dealloc via 'delete'.

Fixes mumble-voip#31
@mkrautz
Copy link
Contributor

mkrautz commented Jul 29, 2017

@wtmoose Even if CryptState is not properly initialized, it should not trigger a crash. The memory is there, and the underlying data will be initialized when connecting to a server: when the server sends the CryptState message, everything (except decrypt_state) will be initialized.

So while I agree that CryptState not being properly initialized is a bug, I am not convinced that it really fixes the issue. I know this is a hard-to-reproduce problem (at least, it has been for me), but are you sure it really fixes the crash?

@mkrautz
Copy link
Contributor

mkrautz commented Jul 29, 2017

Anyway, feel free to test PR #54 to see if it helps! Thanks.

@wtmoose
Copy link

wtmoose commented Jul 29, 2017

No, I'm not sure. I made two changes at the same time and haven't had time to test them independently.

The second change is related to #55. We were initially calling _pingTimerFired from the main thread and the second change was to move that call to our MKConnection thread. I'm almost certain this was causing a crash. I left the CryptState change in because of the amount of time it would take to retest.

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

No branches or pull requests

3 participants