From 03b1eb4bd50d8861c1562456d1ba46f968ba44f3 Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Mon, 8 Jul 2019 12:35:09 -0400 Subject: [PATCH] Prevent attempting to send push media messages to non-phone addresses. Prevents crash loop in #8910 --- .../securesms/jobs/PushMediaSendJob.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java index 40e026a122..adc627a764 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java @@ -1,6 +1,7 @@ package org.thoughtcrime.securesms.jobs; import android.content.Context; + import androidx.annotation.NonNull; import androidx.annotation.WorkerThread; @@ -68,6 +69,10 @@ public class PushMediaSendJob extends PushSendJob { @WorkerThread public static void enqueue(@NonNull Context context, @NonNull JobManager jobManager, long messageId, @NonNull Address destination) { try { + if (!destination.isPhone()) { + throw new AssertionError(); + } + MmsDatabase database = DatabaseFactory.getMmsDatabase(context); OutgoingMediaMessage message = database.getOutgoingMessage(messageId); List attachments = new LinkedList<>(); @@ -200,11 +205,19 @@ public class PushMediaSendJob extends PushSendJob { throw new UndeliverableMessageException("No destination address."); } + final Address destination = message.getRecipient().getAddress(); + + if (!destination.isPhone()) { + if (destination.isEmail()) throw new UndeliverableMessageException("Not e164, is email"); + if (destination.isGroup()) throw new UndeliverableMessageException("Not e164, is group"); + throw new UndeliverableMessageException("Not e164, unknown"); + } + try { rotateSenderCertificateIfNecessary(); SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender(); - SignalServiceAddress address = getPushAddress(message.getRecipient().getAddress()); + SignalServiceAddress address = getPushAddress(destination); List attachments = Stream.of(message.getAttachments()).filterNot(Attachment::isSticker).toList(); List serviceAttachments = getAttachmentPointersFor(attachments); Optional profileKey = getProfileKey(message.getRecipient());