Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6d1ddb3 authored by Thomas Stuart's avatar Thomas Stuart
Browse files

enforce limit on SubscriptionAddress

The SubscriptionAddress should never exceed a length of
256 characters.

bug: 256819769
bug: 259064622
Test: testLimitOnSubscriptionAddress
Change-Id: I1f0a9a4ddb971128dde9b0016d3d02b4b8a04ecf
parent bc0c3f21
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -962,18 +962,20 @@ public class PhoneAccountRegistrar {

        String[] fields =
                {"Package Name", "Class Name", "PhoneAccountHandle Id", "Label", "ShortDescription",
                        "GroupId", "Address"};
                        "GroupId", "Address", "SubscriptionAddress"};
        CharSequence[] args = {handle.getComponentName().getPackageName(),
                handle.getComponentName().getClassName(), handle.getId(), account.getLabel(),
                account.getShortDescription(), account.getGroupId(),
                (account.getAddress() != null ? account.getAddress().toString() : "")};
                (account.getAddress() != null ? account.getAddress().toString() : ""),
                (account.getSubscriptionAddress() != null ?
                        account.getSubscriptionAddress().toString() : "")};

        for (int i = 0; i < fields.length; i++) {
            if (args[i] != null && args[i].length() > MAX_PHONE_ACCOUNT_FIELD_CHAR_LIMIT) {
                EventLog.writeEvent(0x534e4554, "259064622", Binder.getCallingUid(),
                        "enforceCharacterLimit");
                throw new IllegalArgumentException("The PhoneAccount or PhoneAccountHandle"
                        + fields[i] + " field has an invalid character count. PhoneAccount and "
                throw new IllegalArgumentException("The PhoneAccount or PhoneAccountHandle ["
                        + fields[i] + "] field has an invalid character count. PhoneAccount and "
                        + "PhoneAccountHandle String and Char-Sequence fields are limited to "
                        + MAX_PHONE_ACCOUNT_FIELD_CHAR_LIMIT + " characters.");
            }
+17 −0
Original line number Diff line number Diff line
@@ -1667,6 +1667,23 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase {
        }
    }

    /**
     * Ensure an IllegalArgumentException is thrown when providing a SubscriptionAddress that
     * exceeds the PhoneAccountRegistrar limit.
     */
    @Test
    public void testLimitOnSubscriptionAddress() throws Exception {
        String text = "a".repeat(100);
        PhoneAccount.Builder builder =  new PhoneAccount.Builder(makeQuickAccountHandle(TEST_ID),
                TEST_LABEL).setSubscriptionAddress(Uri.fromParts(text, text, text));
        try {
            mRegistrar.enforceCharacterLimit(builder.build());
            fail("failed to throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // pass test
        }
    }

    private static PhoneAccount.Builder makeBuilderWithBindCapabilities(PhoneAccountHandle handle) {
        return new PhoneAccount.Builder(handle, TEST_LABEL)
                .setCapabilities(PhoneAccount.CAPABILITY_SUPPORTS_TRANSACTIONAL_OPERATIONS);