8282395: URL.openConnection can throw IOOBE

Reviewed-by: dfuchs
This commit is contained in:
KIRIYAMA Takuya 2022-10-11 09:22:33 +00:00 committed by Daniel Fuchs
parent fe70487d0b
commit 4435d56d3f
3 changed files with 75 additions and 6 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -197,11 +197,14 @@ public final class ParseUtil {
bb.clear();
int ui = i;
for (;;) {
assert (n - i >= 2);
if (n - i < 2) {
throw new IllegalArgumentException("Malformed escape pair: " + s);
}
try {
bb.put(unescape(s, i));
} catch (NumberFormatException e) {
throw new IllegalArgumentException();
} catch (NumberFormatException | IndexOutOfBoundsException e) {
throw new IllegalArgumentException("Malformed escape pair: " + s);
}
i += 3;
if (i >= n)

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -30,6 +30,7 @@
package sun.net.www.protocol.ftp;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.Proxy;
import java.util.Map;
@ -58,6 +59,14 @@ public class Handler extends java.net.URLStreamHandler {
protected java.net.URLConnection openConnection(URL u, Proxy p)
throws IOException {
return new FtpURLConnection(u, p);
FtpURLConnection connection = null;
try {
connection = new FtpURLConnection(u, p);
} catch (IllegalArgumentException e) {
var mfue = new MalformedURLException(e.getMessage());
mfue.initCause(e);
throw mfue;
}
return connection;
}
}