Skip to content

Commit 73aa657

Browse files
authored
Reject Windows reserved filenames in /setwarp (#6487)
Fixes #5430 stop gap for before we do #5267
1 parent 86621cd commit 73aa657

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Essentials/src/main/java/com/earth2me/essentials/commands/Commandsetwarp.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public void run(final Server server, final User user, final String commandLabel,
2525
throw new TranslatableException("invalidWarpName");
2626
}
2727

28+
if (StringUtil.isReservedFileName(args[0])) {
29+
throw new TranslatableException("invalidWarpName");
30+
}
31+
2832
final IWarps warps = ess.getWarps();
2933
Location warpLoc = null;
3034

Essentials/src/main/java/com/earth2me/essentials/utils/StringUtil.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,21 @@ public final class StringUtil {
1818
private StringUtil() {
1919
}
2020

21+
private static final Pattern WINDOWS_RESERVED = Pattern.compile("^(con|prn|aux|nul|com[0-9]|lpt[0-9])$");
22+
2123
//Used to clean file names before saving to disk
2224
public static String sanitizeFileName(final String name) {
2325
return INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
2426
}
2527

28+
/**
29+
* Returns true if the given name is a Windows reserved filename (e.g. CON, NUL, AUX).
30+
* Using these as file names on Windows will hang or crash the server.
31+
*/
32+
public static boolean isReservedFileName(final String name) {
33+
return WINDOWS_RESERVED.matcher(name.toLowerCase(Locale.ENGLISH)).matches();
34+
}
35+
2636
//Used to clean strings/names before saving as filenames/permissions
2737
public static String safeString(final String string) {
2838
if (string == null) {

0 commit comments

Comments
 (0)