RFR (S) 8230407 : SocketPermission and FilePermission action list allows leading comma
Peter Levart
peter.levart at gmail.com
Thu Oct 3 06:40:52 UTC 2019
Hi Ivan,
On 10/1/19 10:26 PM, Ivan Gerasimov wrote:
> Hello!
>
> The constructors of SocketPermission and FilePermission expect a
> String argument with comma-separated list of actions.
>
> If the list is malformed, then the constructors throw
> IllegalArgumentException.
>
> It turns out that the current implementation fails to throw IAE if the
> list starts with a leading comma.
>
> Would you please help review a simple fix, which will make the
> behavior more consistent?
>
> BUGURL: https://bugs.openjdk.java.net/browse/JDK-8230407
> WEBREV: http://cr.openjdk.java.net/~igerasim/8230407/00/webrev/
>
With new switch expressions the logic could be a little clearer. For
example:
for (boolean seencomma = false; i >= matchlen &&
!seencomma; i--) {
seencomma = switch (a[i - matchlen]) {
case ' ', '\r', '\n', '\f', '\t': yield false;
case ',': if (i > matchlen) yield true;
default: throw new IllegalArgumentException(
"invalid permission: " + actions);
};
}
This is still experimental, but I think it will be proposed to be
standard soon.
If you want to backport it later, then maybe you don't want to do that now.
Regards, Peter
More information about the security-dev
mailing list