From 6962cc0668c4ecfafe74d4564244a7e2b0d681f2 Mon Sep 17 00:00:00 2001 From: weijun Date: Tue, 26 Jan 2010 17:03:48 +0800 Subject: [PATCH] 6919610: KeyTabInputStream uses static field for per-instance value Reviewed-by: mullan --- .../krb5/internal/ktab/KeyTabInputStream.java | 4 +- test/sun/security/krb5/ktab/KeyTabIndex.java | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 test/sun/security/krb5/ktab/KeyTabIndex.java diff --git a/src/share/classes/sun/security/krb5/internal/ktab/KeyTabInputStream.java b/src/share/classes/sun/security/krb5/internal/ktab/KeyTabInputStream.java index 900c3cc52..c347c848f 100644 --- a/src/share/classes/sun/security/krb5/internal/ktab/KeyTabInputStream.java +++ b/src/share/classes/sun/security/krb5/internal/ktab/KeyTabInputStream.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2000-2010 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -49,7 +49,7 @@ import java.io.InputStream; public class KeyTabInputStream extends KrbDataInputStream implements KeyTabConstants { boolean DEBUG = Krb5.DEBUG; - static int index; + int index; public KeyTabInputStream(InputStream is) { super(is); diff --git a/test/sun/security/krb5/ktab/KeyTabIndex.java b/test/sun/security/krb5/ktab/KeyTabIndex.java new file mode 100644 index 000000000..b349f7c13 --- /dev/null +++ b/test/sun/security/krb5/ktab/KeyTabIndex.java @@ -0,0 +1,52 @@ +/* + * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +/* + * @test + * @bug 6919610 + * @summary KeyTabInputStream uses static field for per-instance value + */ +import sun.security.krb5.PrincipalName; +import sun.security.krb5.internal.ktab.KeyTab; + +public class KeyTabIndex { + public static void main(String[] args) throws Exception { + KeyTab kt = KeyTab.create("ktab"); + // Two entries with very different length, so that it's easy to + // observice the abnormal change of "index" field. + kt.addEntry(new PrincipalName( + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@A"), + "x".toCharArray(), 1); + kt.addEntry(new PrincipalName("a@A"), "x".toCharArray(), 1); + kt.save(); + Runnable t = new Runnable() { + @Override + public void run() { + KeyTab.getInstance("ktab").getClass(); + } + }; + KeyTab.refresh(); + for (int i=0; i<10; i++) { + new Thread(t).start(); + } + } +} -- GitLab