8230407: SocketPermission and FilePermission action list allows leading comma

Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Reviewed-by: chegar
This commit is contained in:
Ivan Gerasimov 2019-10-16 14:32:17 -07:00
parent 7e6ebde13c
commit 31afddccae
4 changed files with 94 additions and 38 deletions

View file

@ -287,6 +287,11 @@ public final class SocketPermission extends Permission
* @param host the hostname or IP address of the computer, optionally
* including a colon followed by a port or port range.
* @param action the action string.
*
* @throws NullPointerException if any parameters are null
* @throws IllegalArgumentException if the format of {@code host} is
* invalid, or if the {@code action} string is empty, malformed, or
* contains an action other than the specified possible actions
*/
public SocketPermission(String host, String action) {
super(getHost(host));
@ -589,14 +594,15 @@ public final class SocketPermission extends Permission
// like "ackbarfaccept". Also, skip to the comma.
boolean seencomma = false;
while (i >= matchlen && !seencomma) {
switch(a[i-matchlen]) {
case ',':
seencomma = true;
break;
switch (c = a[i-matchlen]) {
case ' ': case '\r': case '\n':
case '\f': case '\t':
break;
default:
if (c == ',' && i > matchlen) {
seencomma = true;
break;
}
throw new IllegalArgumentException(
"invalid permission: " + action);
}