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

Avoid Null pointer at DomainChecker and enhance AssignVMCmd #4279

Merged
merged 3 commits into from Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -138,8 +138,14 @@ public void execute() {
e.printStackTrace();
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm " + e.getMessage());
s_logger.error("Failed to move vm due to: " + e.getStackTrace());
if (e.getMessage() != null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getMessage());
} else if (e.getCause() != null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getCause());
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
}
}

}
Expand Down
5 changes: 5 additions & 0 deletions server/src/main/java/com/cloud/acl/DomainChecker.java
Expand Up @@ -89,6 +89,11 @@ public boolean checkAccess(Account caller, Domain domain) throws PermissionDenie
if (caller.getState() != Account.State.enabled) {
throw new PermissionDeniedException(caller + " is disabled.");
}

if (domain == null) {
throw new PermissionDeniedException(String.format("Provided domain is NULL, cannot check access for account [uuid=%s, name=%s]", caller.getUuid(), caller.getAccountName()));
}

long domainId = domain.getId();

if (_accountService.isNormalUser(caller.getId())) {
Expand Down
4 changes: 4 additions & 0 deletions server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Expand Up @@ -6138,6 +6138,10 @@ public UserVm moveVMToUser(final AssignVMCmd cmd) throws ResourceAllocationExcep
throw new InvalidParameterValueException("The new account owner " + cmd.getAccountName() + " is disabled.");
}

if (cmd.getProjectId() != null && cmd.getDomainId() == null) {
throw new InvalidParameterValueException("Please provide a valid domain ID; cannot assign VM to a project if domain ID is NULL.");
}

//check caller has access to both the old and new account
_accountMgr.checkAccess(caller, null, true, oldAccount);
_accountMgr.checkAccess(caller, null, true, newAccount);
Expand Down