Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.

Commit 2c2b772

Browse files
author
Yann Prono
committed
fix vulnerabilities from SQ
1 parent 85d4fde commit 2c2b772

3 files changed

Lines changed: 21 additions & 20 deletions

File tree

src/main/java/io/chocorean/authmod/authentication/datasource/DatabaseSourceStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public boolean exist(IPlayer player) {
5959
try {
6060
return this.playersDAO.findFirst(player) != null;
6161
} catch (SQLException e) {
62-
e.printStackTrace();
62+
LOGGER.catching(Level.ERROR, e);
6363
}
6464
return false;
6565
}

src/main/java/io/chocorean/authmod/authentication/datasource/FileDataSourceStrategy.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.chocorean.authmod.model.IPlayer;
44
import io.chocorean.authmod.model.Player;
55
import net.minecraftforge.fml.common.FMLLog;
6+
import org.apache.logging.log4j.Level;
67
import org.apache.logging.log4j.Logger;
78

89
import java.io.*;
@@ -25,26 +26,28 @@ public FileDataSourceStrategy(File authFile) {
2526

2627
private void readFile() {
2728
this.players.clear();
29+
boolean created;
2830
try {
29-
this.authFile.createNewFile();
30-
} catch (IOException e) { LOGGER.catching(e); }
31-
try(BufferedReader bf = new BufferedReader(new FileReader(this.authFile))) {
32-
String line;
33-
while((line = bf.readLine()) != null && line.trim().length() > 0) {
34-
if(!line.startsWith("#")) {
35-
String[] parts = line.trim().split(SEPARATOR);
36-
IPlayer p = new Player();
37-
p.setEmail(parts[0].trim());
38-
p.setUsername(parts[1].trim());
39-
p.setPassword(parts[2].trim());
40-
p.setBan(Boolean.parseBoolean(parts[3].trim()));
41-
this.players.put(p.getEmail(), p);
31+
created = this.authFile.createNewFile();
32+
if(created) {
33+
try(BufferedReader bf = new BufferedReader(new FileReader(this.authFile))) {
34+
String line;
35+
while((line = bf.readLine()) != null && line.trim().length() > 0) {
36+
if(!line.startsWith("#")) {
37+
String[] parts = line.trim().split(SEPARATOR);
38+
IPlayer p = new Player();
39+
p.setEmail(parts[0].trim());
40+
p.setUsername(parts[1].trim());
41+
p.setPassword(parts[2].trim());
42+
p.setBan(Boolean.parseBoolean(parts[3].trim()));
43+
this.players.put(p.getEmail(), p);
44+
}
45+
}
46+
this.lastModification = this.authFile.lastModified();
4247
}
4348
}
44-
this.lastModification = this.authFile.lastModified();
45-
} catch (IOException e) {
46-
e.printStackTrace();
47-
}
49+
} catch (IOException e) { LOGGER.catching(e); }
50+
4851
}
4952

5053
private void reloadFile() {

src/main/java/io/chocorean/authmod/command/LoginCommand.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
7474
);
7575
}
7676
} catch (Exception e) {
77-
e.printStackTrace();
7877
LOGGER.error(e.getMessage());
7978
((EntityPlayerMP)sender).connection.sendPacket(new SPacketChat(new TextComponentString(e.getMessage())));
80-
loggedPlayer = null;
8179
}
8280
}
8381
else {

0 commit comments

Comments
 (0)