[FIX] Потенциальные NPE

This commit is contained in:
Gravit 2020-09-26 20:13:52 +07:00
parent 32d7ca932a
commit 438133bce7
No known key found for this signature in database
GPG key ID: 98A079490768CCE5
4 changed files with 26 additions and 5 deletions

View file

@ -57,6 +57,13 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti
throw new AuthException("Password decryption error"); throw new AuthException("Password decryption error");
} }
} }
if(clientData.isAuth) {
if(LogHelper.isDevEnabled()) {
LogHelper.warning("Client %s double auth", clientData.username == null ? ip : clientData.username);
}
sendError("You are already logged in");
return;
}
AuthProviderPair pair; AuthProviderPair pair;
if (auth_id == null || auth_id.isEmpty()) pair = server.config.getAuthProviderPair(); if (auth_id == null || auth_id.isEmpty()) pair = server.config.getAuthProviderPair();
else pair = server.config.getAuthProviderPair(auth_id); else pair = server.config.getAuthProviderPair(auth_id);

View file

@ -25,6 +25,10 @@ public void execute(ChannelHandlerContext ctx, Client client) {
sendError("Permissions denied"); sendError("Permissions denied");
return; return;
} }
if(username == null || accessToken == null || serverID == null) {
sendError("Invalid request");
return;
}
boolean success; boolean success;
try { try {
server.authHookManager.joinServerHook.hook(this, client); server.authHookManager.joinServerHook.hook(this, client);

View file

@ -3,6 +3,7 @@
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import pro.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent; import pro.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent;
import pro.gravit.launcher.profiles.PlayerProfile; import pro.gravit.launcher.profiles.PlayerProfile;
import pro.gravit.launchserver.auth.AuthProviderPair;
import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.Client;
import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.launchserver.socket.response.SimpleResponse;
import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.LogHelper;
@ -20,14 +21,19 @@ public String getType() {
@Override @Override
public void execute(ChannelHandlerContext ctx, Client client) throws Exception { public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
BatchProfileByUsernameRequestEvent result = new BatchProfileByUsernameRequestEvent(); BatchProfileByUsernameRequestEvent result = new BatchProfileByUsernameRequestEvent();
if(list == null) {
sendError("Invalid request");
return;
}
result.playerProfiles = new PlayerProfile[list.length]; result.playerProfiles = new PlayerProfile[list.length];
for (int i = 0; i < list.length; ++i) { for (int i = 0; i < list.length; ++i) {
UUID uuid; UUID uuid;
if (client.auth == null) { AuthProviderPair pair = client.auth;
LogHelper.warning("Client auth is null. Using default."); if (pair == null) {
uuid = server.config.getAuthProviderPair().handler.usernameToUUID(list[i].username); pair = server.config.getAuthProviderPair();
} else uuid = client.auth.handler.usernameToUUID(list[i].username); }
result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(uuid, list[i].username, list[i].client, client.auth.textureProvider); uuid = pair.handler.usernameToUUID(list[i].username);
result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(uuid, list[i].username, list[i].client, pair.textureProvider);
} }
sendResult(result); sendResult(result);
} }

View file

@ -23,6 +23,10 @@ public void execute(ChannelHandlerContext ctx, Client client) {
sendError("Access denied"); sendError("Access denied");
return; return;
} }
if(dirName == null) {
sendError("Invalid request");
return;
}
HashedDir dir = server.updatesDirMap.get(dirName); HashedDir dir = server.updatesDirMap.get(dirName);
if (dir == null) { if (dir == null) {
sendError(String.format("Directory %s not found", dirName)); sendError(String.format("Directory %s not found", dirName));