avoid potential crashes when opening child databases (caused by network on main thread or URLs without username/password), fixes https://github.com/PhilippC/keepass2android/issues/728

This commit is contained in:
Philipp Crocoll
2019-03-18 03:56:34 +01:00
parent 92a0ce98bb
commit 40f3066ee0
3 changed files with 22 additions and 6 deletions

View File

@@ -52,11 +52,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<LibraryProjectZip Include="..\java\android-filechooser-AS\app\build\outputs\aar\android-filechooser-release.aar">
<Link>Jars\android-filechooser-release.aar</Link>
</LibraryProjectZip>
<None Include="Jars\AboutJars.txt" />
<None Include="Additions\AboutAdditions.txt" />
<LibraryProjectZip Include="Jars\android-filechooser-debug.aar" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>

View File

@@ -71,9 +71,18 @@ public class WebDavStorage extends JavaFileStorageBase {
String scheme = filename.substring(0, filename.indexOf("://"));
filename = filename.substring(scheme.length() + 3);
String userPwd = filename.substring(0, filename.indexOf('@'));
ci.username = decode(userPwd.substring(0, userPwd.indexOf(":")));
ci.password = decode(userPwd.substring(userPwd.indexOf(":") + 1));
int idxAt = filename.indexOf('@');
if (idxAt >= 0)
{
String userPwd = filename.substring(0, idxAt);
int idxColon = userPwd.indexOf(":");
if (idxColon >= 0);
{
ci.username = decode(userPwd.substring(0, idxColon));
ci.password = decode(userPwd.substring(idxColon + 1));
}
}
ci.URL = scheme + "://" +filename.substring(filename.indexOf('@') + 1);
return ci;
}

View File

@@ -335,9 +335,18 @@ namespace keepass2android
private static bool CheckFileExsts(IOConnectionInfo ioc)
{
try
{
var fileStorage = App.Kp2a.GetFileStorage(ioc);
//we're assuming that remote files always exist (if we have a file storage, i.e. we check after receiving a file storage)
//The SkipIfNotExists switch only makes sense for local files, because remote files either exist for all devices or none
//(Ok, there are exceptions like files available in a (W)LAN. But then we still have the device switch and caches.)
//We cannot use OpenFileForRead on remote storages because this method is called from the main thread.
if (!ioc.IsLocalFile())
return true;
using (var stream = fileStorage.OpenFileForRead(ioc))
{
}