From 8a15a08d0f9f0e14dc31df08bf04c3d84c3c758c Mon Sep 17 00:00:00 2001 From: KHobbits Date: Thu, 2 Feb 2012 09:26:36 +0000 Subject: Sanitize mail for untoward characters. Prevent a user error from terminating essentials timer task. --- .../src/com/earth2me/essentials/EssentialsTimer.java | 16 ++++++++++++---- Essentials/src/com/earth2me/essentials/Util.java | 10 ++++++++-- .../com/earth2me/essentials/commands/Commandmail.java | 7 ++++--- .../com/earth2me/essentials/signs/SignProtection.java | 2 +- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java index f3b447dae..0c413bfc8 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java @@ -3,6 +3,7 @@ package com.earth2me.essentials; import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.logging.Level; import org.bukkit.entity.Player; @@ -22,10 +23,17 @@ public class EssentialsTimer implements Runnable final long currentTime = System.currentTimeMillis(); for (Player player : ess.getServer().getOnlinePlayers()) { - final User user = ess.getUser(player); - onlineUsers.add(user); - user.setLastOnlineActivity(currentTime); - user.checkActivity(); + try + { + final User user = ess.getUser(player); + onlineUsers.add(user); + user.setLastOnlineActivity(currentTime); + user.checkActivity(); + } + catch (Exception e) + { + ess.getLogger().log(Level.WARNING, "EssentialsTimer Error:", e); + } } final Iterator iterator = onlineUsers.iterator(); diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 386433326..48e2a53a0 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -21,11 +21,17 @@ public class Util { } private final static Logger logger = Logger.getLogger("Minecraft"); - private final static Pattern INVALIDCHARS = Pattern.compile("[^a-z0-9]"); + private final static Pattern INVALIDFILECHARS = Pattern.compile("[^a-z0-9]"); + private final static Pattern INVALIDCHARS = Pattern.compile("[^\\p{Print}]"); public static String sanitizeFileName(final String name) { - return INVALIDCHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_"); + return INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_"); + } + + public static String sanitizeString(final String string) + { + return INVALIDCHARS.matcher(string).replaceAll(""); } public static String formatDateDiff(long date) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index 4a9928b85..abc551f58 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -40,7 +40,7 @@ public class Commandmail extends EssentialsCommand { if (!user.isAuthorized("essentials.mail.send")) { - throw new Exception(_("noPerm","essentials.mail.send")); + throw new Exception(_("noPerm", "essentials.mail.send")); } Player player = server.getPlayer(args[1]); @@ -59,7 +59,8 @@ public class Commandmail extends EssentialsCommand } if (!u.isIgnoredPlayer(user.getName())) { - u.addMail(user.getName() + ": " + Util.stripColor(getFinalArg(args, 2))); + final String mail = Util.sanitizeString(Util.stripColor(getFinalArg(args, 2))); + u.addMail(user.getName() + ": " + mail); } user.sendMessage(_("mailSent")); return; @@ -68,7 +69,7 @@ public class Commandmail extends EssentialsCommand { if (!user.isAuthorized("essentials.mail.sendall")) { - throw new Exception(_("noPerm","essentials.mail.sendall")); + throw new Exception(_("noPerm", "essentials.mail.sendall")); } ess.scheduleAsyncDelayedTask(new SendAll(user.getName() + ": " + Util.stripColor(getFinalArg(args, 1)))); user.sendMessage(_("mailSent")); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java index f64b6f3f1..088e74f01 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java @@ -129,7 +129,7 @@ public class SignProtection extends EssentialsSign if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) { final BlockSign sign = new BlockSign(block); - if (sign.getLine(0).equalsIgnoreCase(this.getSuccessName())) + if (sign.getLine(0).equals(this.getSuccessName())) { return checkProtectionSign(sign, user, username); } -- cgit v1.2.3