RFR (S) 8230407 : SocketPermission and FilePermission action list allows leading comma
Ivan Gerasimov
ivan.gerasimov at oracle.com
Fri Oct 4 01:36:42 UTC 2019
Thanks Peter, your variant looks cute!
Let's keep this code in mind as a candidate for refactoring once the
switch expression will make its way to the standard.
I would hesitate to allow using experimental features in building the
JDK just for that code :)
With kind regards,
Ivan
On 10/2/19 11:40 PM, Peter Levart wrote:
> 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
>
--
With kind regards,
Ivan Gerasimov
More information about the security-dev
mailing list