Check index length.

This commit is contained in:
David Kocher
2014-05-08 16:17:43 +02:00
parent 131e85c4d0
commit 63424657da
3 changed files with 10 additions and 1 deletions

View File

@@ -200,7 +200,10 @@ public class OpenSSHKnownHosts
if (marker != null) {
i++;
}
if(split.length < 3) {
LOG.error("Error reading entry `{}`", line);
return null;
}
final String hostnames = split[i++];
final String sType = split[i++];

View File

@@ -80,4 +80,9 @@ public class OpenSSHKnownHostsTest {
assertTrue(kh.verify("69.163.155.180", 22, key));
}
@Test
public void testVerifyIndexError() throws Exception {
final OpenSSHKnownHosts v = new OpenSSHKnownHosts(new File("src/test/resources/known_hosts.invalid"));
assertTrue(v.entries().isEmpty());
}
}

View File

@@ -0,0 +1 @@
M36Lo+Ik5ukNugvvoNFlpnyiHMmtKxt3FpyEfYuryXjNqMNWHn/ARVnpUIl5jRLTB7WBzyLYMG7X5nuoFL9zYqKGtHxChbDunxMVbspw5WXI9VN+qxcLwmITmpEvI9ApyS/Ox2ZyN7zw==