5301N/A/*
5301N/A * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
5301N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5301N/A *
5301N/A * This code is free software; you can redistribute it and/or modify it
5301N/A * under the terms of the GNU General Public License version 2 only, as
5301N/A * published by the Free Software Foundation.
5301N/A *
5301N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5301N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5301N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5301N/A * version 2 for more details (a copy is included in the LICENSE file that
5301N/A * accompanied this code).
5301N/A *
5301N/A * You should have received a copy of the GNU General Public License version
5301N/A * 2 along with this work; if not, write to the Free Software Foundation,
5301N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5301N/A *
5301N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5301N/A * or visit www.oracle.com if you need additional information or have any
5301N/A * questions.
5301N/A */
5301N/A
5301N/A/*
5301N/A * Portions Copyright (c) 2012 IBM Corporation
5301N/A */
5301N/A
5301N/A/* @test
5301N/A * @bug 7172149
5301N/A * @summary AIOOBE from Signature.verify after integer overflow
5301N/A * @author Jonathan Lu
5301N/A */
5301N/A
5301N/Aimport java.security.KeyPair;
5301N/Aimport java.security.KeyPairGenerator;
5301N/Aimport java.security.PublicKey;
5301N/Aimport java.security.Signature;
5301N/A
5301N/Apublic class VerifyRangeCheckOverflow {
5301N/A
5301N/A public static void main(String[] args) throws Exception {
5301N/A KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
5301N/A keyPairGenerator.initialize(1024);
5301N/A KeyPair keys = keyPairGenerator.generateKeyPair();
5301N/A PublicKey publicKey = keys.getPublic();
5301N/A byte[] sigBytes = new byte[100];
5301N/A
5301N/A Signature signature = Signature.getInstance("SHA1withDSA");
5301N/A signature.initVerify(publicKey);
5301N/A try {
5301N/A signature.verify(sigBytes, Integer.MAX_VALUE, 1);
5301N/A } catch (IllegalArgumentException ex) {
5301N/A // Expected
5301N/A }
5301N/A }
5301N/A}