src/java.prefs/macosx/classes/java/util/prefs/MacOSXPreferences.java

Print this page
rev 11676 : 8075156: (prefs) remove() should disallow the use of the null control character '\u0000' as key
Summary: Extend disallowing null control character key to remove()
Reviewed-by: XXX

*** 1,7 **** /* ! * Copyright (c) 2011, 2012, Oracle and/or its affiliates. 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. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2011, 2015, Oracle and/or its affiliates. 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. Oracle designates this
*** 28,37 **** --- 28,44 ---- import java.util.Objects; class MacOSXPreferences extends AbstractPreferences { // fixme need security checks? + /** + * The code point U+0000, assigned to the null control character, is the + * only character encoded in Unicode and ISO/IEC 10646 that is always + * invalid in any XML 1.0 and 1.1 document. + */ + private static final String CODE_POINT_U0000 = String.valueOf('\u0000'); + // CF preferences file name for Java nodes with short names // This value is also in MacOSXPreferencesFile.c private static final String defaultAppName = "com.apple.java.util.prefs"; // true if this node is a child of userRoot or is userRoot
*** 140,149 **** --- 147,161 ---- // AbstractPreferences implementation @Override protected void putSpi(String key, String value) { + if (key.indexOf(CODE_POINT_U0000) != -1) { + throw new IllegalArgumentException("Key contains code point U+0000"); + } else if (value.indexOf(CODE_POINT_U0000) != -1) { + throw new IllegalArgumentException("Value contains code point U+0000"); + } file.addKeyToNode(path, key, value); } // AbstractPreferences implementation @Override
*** 155,164 **** --- 167,179 ---- // AbstractPreferences implementation @Override protected void removeSpi(String key) { Objects.requireNonNull(key, "Specified key cannot be null"); + if (key.indexOf(CODE_POINT_U0000) != -1) { + throw new IllegalArgumentException("Key contains code point U+0000"); + } file.removeKeyFromNode(path, key); } // AbstractPreferences implementation