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

[stable-3.30] Check added for StringIndexOutOfBoundException #14325

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,78 @@ public List<User> getAllUsers() {

@Override
public boolean exists(Account account) {
Account[] nextcloudAccounts = getAccounts();
try {
if (account == null) {
Log_OC.d(TAG, "account is null");
return false;
}

Account[] nextcloudAccounts = getAccounts();
if (nextcloudAccounts.length == 0) {
Log_OC.d(TAG, "nextcloudAccounts are empty");
return false;
}

if (account.name.isEmpty()) {
Log_OC.d(TAG, "account name is empty");
return false;
}

if (account != null && account.name != null) {
int lastAtPos = account.name.lastIndexOf('@');
if (lastAtPos == -1) {
Log_OC.d(TAG, "lastAtPos cannot be found");
return false;
}

boolean isLastAtPosInBoundsForHostAndPort = lastAtPos + 1 < account.name.length();
if (!isLastAtPosInBoundsForHostAndPort) {
Log_OC.d(TAG, "lastAtPos not in bounds");
return false;
}

String hostAndPort = account.name.substring(lastAtPos + 1);

String username = account.name.substring(0, lastAtPos);
if (hostAndPort.isEmpty() || username.isEmpty()) {
Log_OC.d(TAG, "hostAndPort or username is empty");
return false;
}

String otherHostAndPort;
String otherUsername;

for (Account otherAccount : nextcloudAccounts) {
// Skip null accounts or accounts with null names
if (otherAccount == null || otherAccount.name.isEmpty()) {
continue;
}

lastAtPos = otherAccount.name.lastIndexOf('@');

// Skip invalid account names
if (lastAtPos == -1) {
continue;
}

boolean isLastAtPosInBoundsForOtherHostAndPort = lastAtPos + 1 < otherAccount.name.length();
if (!isLastAtPosInBoundsForOtherHostAndPort) {
continue;
}
otherHostAndPort = otherAccount.name.substring(lastAtPos + 1);

otherUsername = otherAccount.name.substring(0, lastAtPos);

if (otherHostAndPort.equals(hostAndPort) &&
otherUsername.equalsIgnoreCase(username)) {
return true;
}
}

return false;
} catch (Exception e) {
Log_OC.d(TAG, "Exception caught at UserAccountManagerImpl.exists(): " + e);
return false;
}
return false;
}

@Override
Expand Down
Loading