From 42d42b58cdf9ab7be0f398a74b00ef887266dbf3 Mon Sep 17 00:00:00 2001 From: xuelei Date: Wed, 20 Jan 2010 21:38:37 +0800 Subject: [PATCH] 6862064: incorrect implementation of PKIXParameters.clone() Reviewed-by: weijun, mullan --- .../java/security/cert/PKIXParameters.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/share/classes/java/security/cert/PKIXParameters.java b/src/share/classes/java/security/cert/PKIXParameters.java index 7608d9f7b..f9f95ce78 100644 --- a/src/share/classes/java/security/cert/PKIXParameters.java +++ b/src/share/classes/java/security/cert/PKIXParameters.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2000-2009 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 @@ -663,15 +663,23 @@ public class PKIXParameters implements CertPathParameters { */ public Object clone() { try { - Object copy = super.clone(); - // Must clone these because addCertStore, et al. modify them + PKIXParameters copy = (PKIXParameters)super.clone(); + + // must clone these because addCertStore, et al. modify them if (certStores != null) { - certStores = new ArrayList(certStores); + copy.certStores = new ArrayList(certStores); } if (certPathCheckers != null) { - certPathCheckers = - new ArrayList(certPathCheckers); + copy.certPathCheckers = + new ArrayList(certPathCheckers.size()); + for (PKIXCertPathChecker checker : certPathCheckers) { + copy.certPathCheckers.add( + (PKIXCertPathChecker)checker.clone()); + } } + + // other class fields are immutable to public, don't bother + // to clone the read-only fields. return copy; } catch (CloneNotSupportedException e) { /* Cannot happen */ -- GitLab