Don't read symlink while checking game lib directory. It's non-portable.

This commit is contained in:
Alibek Omarov 2018-01-01 20:18:12 +03:00
parent 2eb6fbbc42
commit 57ce27dfe7

View file

@ -18,7 +18,7 @@ import org.json.*;
import android.preference.*; 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 * also just shortcuts
*/ */
public class FWGSLib public class FWGSLib
@ -63,29 +63,38 @@ public class FWGSLib
{ {
try 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 ); File f = new File( gamelibdir );
if( !f.isDirectory() ) if( !f.isDirectory() )
{ {
// Log.d( TAG, "Not a directory" ); Log.d( TAG, "Not a directory" );
return false; return false;
} }
if( !f.exists() ) if( !f.exists() )
{ {
// Log.d( TAG, "Does not exist" ); Log.d( TAG, "Does not exist" );
return false; 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)?\\/).+"; final boolean ret = gamelibdir.matches( regex );
return path.matches( regex ); Log.d( TAG, "ret = " + ret );
return ret;
} }
catch( Exception e ) catch( Exception e )
{ {