mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8240848: ArrayIndexOutOfBoundsException buf for TextCallbackHandler
Reviewed-by: mullan
This commit is contained in:
parent
592b9a9571
commit
502d45955f
2 changed files with 25 additions and 11 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -35,7 +35,6 @@ import javax.security.auth.callback.UnsupportedCallbackException;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -236,8 +235,9 @@ public class ConsoleCallbackHandler implements CallbackHandler {
|
||||||
result = Integer.parseInt(readLine());
|
result = Integer.parseInt(readLine());
|
||||||
if (result < 0 || result > (options.length - 1)) {
|
if (result < 0 || result > (options.length - 1)) {
|
||||||
result = defaultOption;
|
result = defaultOption;
|
||||||
|
} else {
|
||||||
|
result = options[result].value;
|
||||||
}
|
}
|
||||||
result = options[result].value;
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
result = defaultOption;
|
result = defaultOption;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -23,24 +23,38 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 6599079
|
* @bug 6599079 8240848
|
||||||
* @summary Non-standard ConfirmationCallback throws NPE
|
* @summary Non-standard ConfirmationCallback throws NPE
|
||||||
|
* @modules jdk.security.auth
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import javax.security.auth.callback.Callback;
|
import javax.security.auth.callback.Callback;
|
||||||
import javax.security.auth.callback.ConfirmationCallback;
|
import javax.security.auth.callback.ConfirmationCallback;
|
||||||
import com.sun.security.auth.callback.TextCallbackHandler;
|
import com.sun.security.auth.callback.TextCallbackHandler;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class Confirm {
|
public class Confirm {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// Provide answer in an individual stream so that the program
|
InputStream in = System.in;
|
||||||
// does not block.
|
try {
|
||||||
System.setIn(new ByteArrayInputStream("1\n".getBytes()));
|
// Provide answer in an individual stream so that the program
|
||||||
|
// does not block.
|
||||||
|
System.setIn(new ByteArrayInputStream("1\n".getBytes()));
|
||||||
|
new TextCallbackHandler().handle(new Callback[]{
|
||||||
|
new ConfirmationCallback("Prince",
|
||||||
|
ConfirmationCallback.INFORMATION,
|
||||||
|
new String[]{"To be", "Not to be"}, 0)});
|
||||||
|
|
||||||
new TextCallbackHandler().handle(new Callback[]{
|
System.setIn(new ByteArrayInputStream("-1\n".getBytes()));
|
||||||
new ConfirmationCallback("Prince", ConfirmationCallback.INFORMATION,
|
new TextCallbackHandler().handle(new Callback[]{
|
||||||
new String[]{"To be", "Not to be"}, 0)});
|
new ConfirmationCallback(
|
||||||
|
ConfirmationCallback.INFORMATION,
|
||||||
|
ConfirmationCallback.OK_CANCEL_OPTION,
|
||||||
|
ConfirmationCallback.OK)});
|
||||||
|
} finally {
|
||||||
|
System.setIn(in);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue