From 57ce27dfe7f6bedf41da44156ef3a2b9951c3c45 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 1 Jan 2018 20:18:12 +0300 Subject: [PATCH] Don't read symlink while checking game lib directory. It's non-portable. --- src/su/xash/fwgslib/FWGSLib.java | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/su/xash/fwgslib/FWGSLib.java b/src/su/xash/fwgslib/FWGSLib.java index 5e722a14..68f5e2d8 100644 --- a/src/su/xash/fwgslib/FWGSLib.java +++ b/src/su/xash/fwgslib/FWGSLib.java @@ -18,7 +18,7 @@ import org.json.*; import android.preference.*; /* - * This utility class is intended to hide some Android and Java design-flaws + * This utility class is intended to hide some Android and Java design-flaws and * also just shortcuts */ public class FWGSLib @@ -63,29 +63,38 @@ public class FWGSLib { try { - // Log.d( TAG, " gamelibdir = " + gamelibdir + " allowed = " + allowed ); + Log.d( TAG, " gamelibdir = " + gamelibdir + " allowed = " + allowed ); + + if( gamelibdir.contains( "/.." )) + return false; File f = new File( gamelibdir ); if( !f.isDirectory() ) { - // Log.d( TAG, "Not a directory" ); + Log.d( TAG, "Not a directory" ); return false; } if( !f.exists() ) { - // Log.d( TAG, "Does not exist" ); + Log.d( TAG, "Does not exist" ); return false; } - final String path = f.getCanonicalPath(); + // add trailing / for simple regexp + if( gamelibdir.charAt(gamelibdir.length() - 1) != '/' ) + gamelibdir = gamelibdir + "/"; + + final String regex = ".+\\/" + allowed.replace(".", "\\.") + "(|(-\\d))\\/(.+|)"; - // Log.d( TAG, "path = " + path ); + Log.d( TAG, regex ); - final String regex = ".+\\/" + allowed + "(\\/|(-\\d)?\\/).+"; - - return path.matches( regex ); + final boolean ret = gamelibdir.matches( regex ); + + Log.d( TAG, "ret = " + ret ); + + return ret; } catch( Exception e ) {