Skip to content

Commit

Permalink
Check added for StringIndexOutOfBoundException
Browse files Browse the repository at this point in the history
Signed-off-by: A117870935 <[email protected]>
  • Loading branch information
surinder-tsys authored and tobiasKaminsky committed Jan 13, 2025
1 parent abbdc90 commit b613336
Showing 1 changed file with 56 additions and 3 deletions.
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

0 comments on commit b613336

Please sign in to comment.