signalapp / Signal-Desktop

A private messenger for Windows, macOS, and Linux.
https://signal.org/download
GNU Affero General Public License v3.0
14.7k stars 2.69k forks source link

libtextsecure crashes while sending a message if the server returns 0 for registration id #181

Open liliakai opened 9 years ago

liliakai commented 9 years ago

On https://github.com/WhisperSystems/TextSecure-Browser/blob/master/libtextsecure/sendmessage.js#L72

var registrationId = deviceObjectList[i].registrationId || deviceObjectList[i].sessions.registrationId;

This line of code assumes that for any device object, either the first registrationId is truthy /or/ sessions is defined, which might not be true.

I was seeing an exception on the above line for the first message sent to a new contact's secondary device. The server returned 0 (falsey) for the secondary device's registrationId and the sessions attribute was undefined because we had no sessions yet. The 0 registration id happens to be a server bug, but we shouldn't crash because of it.

TheBlueMatt commented 9 years ago

The best you can really do here is just throw a nicer error than an undefined object error. The server gave us a crap registrationId which means we cannot possibly send the message.