Prevent insertion of UUID-only contacts at the database level.

This commit is contained in:
Greyson Parrelli 2020-05-20 17:02:05 -04:00 committed by Alex Hart
parent f8f959e05a
commit 23401440bf

View File

@ -32,6 +32,7 @@ import org.thoughtcrime.securesms.storage.StorageSyncHelper;
import org.thoughtcrime.securesms.storage.StorageSyncHelper.RecordUpdate;
import org.thoughtcrime.securesms.storage.StorageSyncModels;
import org.thoughtcrime.securesms.util.Base64;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.IdentityUtil;
import org.thoughtcrime.securesms.util.SqlUtil;
import org.thoughtcrime.securesms.util.Util;
@ -491,7 +492,7 @@ public class RecipientDatabase extends Database {
try {
for (SignalContactRecord insert : contactInserts) {
ContentValues values = getValuesForStorageContact(insert);
ContentValues values = validateContactValuesForInsert(getValuesForStorageContact(insert));
long id = db.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_IGNORE);
if (id < 0) {
@ -1644,6 +1645,17 @@ public class RecipientDatabase extends Database {
}
}
private static ContentValues validateContactValuesForInsert(ContentValues values) {
if (!FeatureFlags.uuids() &&
values.getAsString(UUID) != null &&
values.getAsString(PHONE) == null)
{
throw new UuidRecipientError();
} else {
return values;
}
}
public class BulkOperationsHandle {
private final SQLiteDatabase database;
@ -2041,4 +2053,7 @@ public class RecipientDatabase extends Database {
this.neededInsert = neededInsert;
}
}
private static class UuidRecipientError extends AssertionError {
}
}