undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2020, 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.
|
||||
*
|
||||
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.chrono.ChronoLocalDateTime;
|
||||
import java.time.chrono.Chronology;
|
||||
import java.util.Locale;
|
||||
|
||||
public class HijrahConfigCheck {
|
||||
private static final String CALTYPE = "islamic-test";
|
||||
|
||||
public static void main(String... args) {
|
||||
// Availability test
|
||||
if (Chronology.getAvailableChronologies().stream()
|
||||
.filter(c -> c.getCalendarType().equals(CALTYPE))
|
||||
.count() != 1) {
|
||||
throw new RuntimeException(CALTYPE + " chronology was not found, or " +
|
||||
"appeared more than once in Chronology.getAvailableChronologies()");
|
||||
}
|
||||
|
||||
// Instantiation tests
|
||||
Chronology c1 = Chronology.of(CALTYPE);
|
||||
Chronology c2 = Chronology.ofLocale(Locale.forLanguageTag("und-u-ca-" + CALTYPE ));
|
||||
if (!c1.equals(c2)) {
|
||||
throw new RuntimeException(CALTYPE + " chronologies differ. c1: " + c1 +
|
||||
", c2: " + c2);
|
||||
}
|
||||
|
||||
// Date test
|
||||
// 2020-01-10 is AH 1000-01-10 in islamic-test config
|
||||
LocalDateTime iso = LocalDateTime.of(LocalDate.of(2020, 1, 10), LocalTime.MIN);
|
||||
ChronoLocalDateTime hijrah = c1.date(1000, 1, 10).atTime(LocalTime.MIN);
|
||||
if (!iso.toInstant(ZoneOffset.UTC).equals(hijrah.toInstant(ZoneOffset.UTC))) {
|
||||
throw new RuntimeException("test Hijrah date is incorrect. LocalDate: " +
|
||||
iso + ", test date: " + hijrah);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2020, 2024, 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.
|
||||
*
|
||||
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import tests.Helper;
|
||||
import tests.JImageGenerator;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests whether a custom Hijrah configuration properties file works correctly
|
||||
* @bug 8187987
|
||||
* @requires (vm.compMode != "Xcomp" & os.maxMemory >= 2g)
|
||||
* @library /tools/lib /test/lib
|
||||
* @modules java.base/jdk.internal.jimage
|
||||
* jdk.jlink/jdk.tools.jimage
|
||||
* jdk.compiler
|
||||
* @build HijrahConfigCheck tests.* jdk.test.lib.compiler.CompilerUtils jdk.test.lib.process.ProcessTools
|
||||
* @run main/othervm -Xmx1g HijrahConfigTest
|
||||
*/
|
||||
public class HijrahConfigTest {
|
||||
|
||||
private static final String TEST_CONFIG = "hijrah-config-Hijrah-test_islamic-test.properties";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Helper helper = Helper.newHelper();
|
||||
if (helper == null) {
|
||||
System.err.println("Test not run");
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the test JDK image
|
||||
Path outputPath = helper.createNewImageDir("HijrahConfigTest");
|
||||
JImageGenerator.getJLinkTask()
|
||||
.output(outputPath)
|
||||
.addMods("java.base")
|
||||
.call().assertSuccess();
|
||||
|
||||
// Install the test hijrah configuration properties
|
||||
Path confPath = outputPath.resolve("conf").resolve("chronology");
|
||||
Files.createDirectory(confPath);
|
||||
Files.copy(Path.of(System.getProperty("test.src"), TEST_CONFIG),
|
||||
confPath.resolve(TEST_CONFIG));
|
||||
|
||||
// Run tests
|
||||
Path launcher = outputPath.resolve("bin").resolve("java");
|
||||
OutputAnalyzer analyzer = ProcessTools.executeCommand(launcher.toAbsolutePath().toString(), "-ea", "-esa", "HijrahConfigCheck");
|
||||
analyzer.shouldHaveExitValue(0);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
# Copyright (c) 2020, 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.
|
||||
#
|
||||
# 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
|
||||
# A test configuration properties file for a custom Hijrah chronology.
|
||||
# The data here are solely hypothetical and do not represent any of
|
||||
# the actual Hijrah variants.
|
||||
|
||||
# Version of this definition
|
||||
version=0.1
|
||||
|
||||
# Java chronology ID
|
||||
id=Hijrah-test
|
||||
|
||||
# Standard calendar type specification
|
||||
type=islamic-test
|
||||
|
||||
# defines the corresponding ISO date to the earliest Hijrah date
|
||||
iso-start=2020-01-01
|
||||
|
||||
# 1 2 3 4 5 6 7 8 9 10 11 12
|
||||
1000=29 30 29 29 30 29 30 29 30 30 30 29
|
||||
1001=30 29 30 29 29 30 29 29 30 30 30 30
|
||||
1002=29 30 29 30 29 29 29 30 29 30 30 30
|
||||
1003=29 30 30 29 30 29 29 29 30 29 30 30
|
||||
1004=29 30 30 29 30 29 30 29 29 30 29 30
|
||||
1005=30 29 30 29 30 30 29 30 29 30 29 30
|
||||
1006=29 29 30 29 30 30 29 30 29 30 30 29
|
||||
1007=30 29 29 30 29 30 29 30 30 29 30 30
|
||||
1008=29 30 29 29 30 29 29 30 30 30 29 30
|
||||
1009=30 29 30 29 29 30 29 29 30 30 29 30
|
||||
1010=30 30 29 30 29 29 30 29 29 30 30 29
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 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.
|
||||
*
|
||||
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Map;
|
||||
|
||||
/* @test
|
||||
* @bug 8235238
|
||||
* @summary Checks whether custom zone names can be formatted/parsed correctly.
|
||||
* @library zoneProvider
|
||||
* @build custom.CustomZoneRulesProvider custom.CustomTimeZoneNameProvider
|
||||
* @run main/othervm -Djava.locale.providers=SPI,CLDR CustomZoneNameTest
|
||||
*/
|
||||
public class CustomZoneNameTest {
|
||||
|
||||
private final static long now = 1575669972372L;
|
||||
private final static Instant instant = Instant.ofEpochMilli(now);
|
||||
private final static ZoneId customZone = ZoneId.of("Custom/Timezone");
|
||||
|
||||
// test data
|
||||
private final static Map<String, String> formats = Map.of(
|
||||
"yyyy-MM-dd HH:mm:ss.SSS VV", "2019-12-06 22:06:12.372 Custom/Timezone",
|
||||
"yyyy-MM-dd HH:mm:ss.SSS z", "2019-12-06 22:06:12.372 CUST_WT",
|
||||
"yyyy-MM-dd HH:mm:ss.SSS zzzz", "2019-12-06 22:06:12.372 Custom Winter Time",
|
||||
"yyyy-MM-dd HH:mm:ss.SSS v", "2019-12-06 22:06:12.372 Custom Time",
|
||||
"yyyy-MM-dd HH:mm:ss.SSS vvvv", "2019-12-06 22:06:12.372 Custom Timezone Time"
|
||||
);
|
||||
|
||||
public static void main(String... args) {
|
||||
testFormatting();
|
||||
testParsing();
|
||||
}
|
||||
|
||||
private static void testFormatting() {
|
||||
var customZDT = ZonedDateTime.ofInstant(instant, customZone);
|
||||
formats.entrySet().stream()
|
||||
.filter(e -> {
|
||||
var formatted = DateTimeFormatter.ofPattern(e.getKey()).format(customZDT);
|
||||
var expected = e.getValue();
|
||||
System.out.println("testFormatting. Pattern: " + e.getKey() +
|
||||
", expected: " + expected +
|
||||
", formatted: " + formatted);
|
||||
return !formatted.equals(expected);
|
||||
})
|
||||
.findAny()
|
||||
.ifPresent(e -> {
|
||||
throw new RuntimeException(
|
||||
"Provider's custom name was not retrieved for the format " +
|
||||
e.getKey());
|
||||
});
|
||||
}
|
||||
|
||||
public static void testParsing() {
|
||||
formats.entrySet().stream()
|
||||
.filter(e -> {
|
||||
var fmt = DateTimeFormatter.ofPattern(e.getKey());
|
||||
var input = e.getValue();
|
||||
var parsedInstant = fmt.parse(input, Instant::from).toEpochMilli();
|
||||
var parsedZone = fmt.parse(input, ZonedDateTime::from).getZone();
|
||||
System.out.println("testParsing. Input: " + input +
|
||||
", expected instant: " + now +
|
||||
", expected zone: " + customZone +
|
||||
", parsed instant: " + parsedInstant +
|
||||
", parsed zone: " + parsedZone);
|
||||
return parsedInstant != now ||
|
||||
!parsedZone.equals(customZone);
|
||||
})
|
||||
.findAny()
|
||||
.ifPresent(e -> {
|
||||
throw new RuntimeException("Parsing failed for the format " +
|
||||
e.getKey());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
custom.CustomZoneRulesProvider
|
||||
|
|
@ -0,0 +1 @@
|
|||
custom.CustomTimeZoneNameProvider
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 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.
|
||||
*
|
||||
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package custom;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.spi.TimeZoneNameProvider;
|
||||
|
||||
public class CustomTimeZoneNameProvider extends TimeZoneNameProvider {
|
||||
|
||||
public static final String ZONE_ID = "Custom/Timezone";
|
||||
|
||||
@Override
|
||||
public String getDisplayName(String ID, boolean daylight, int style, Locale locale) {
|
||||
if (ZONE_ID.equals(ID)) {
|
||||
switch (style) {
|
||||
case TimeZone.SHORT:
|
||||
if (daylight) {
|
||||
return "CUST_ST";
|
||||
} else {
|
||||
return "CUST_WT";
|
||||
}
|
||||
case TimeZone.LONG:
|
||||
if (daylight) {
|
||||
return "Custom Summer Time";
|
||||
} else {
|
||||
return "Custom Winter Time";
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGenericDisplayName(String ID, int style, Locale locale) {
|
||||
if (ZONE_ID.equals(ID)) {
|
||||
switch (style) {
|
||||
case TimeZone.SHORT:
|
||||
return "Custom Time";
|
||||
case TimeZone.LONG:
|
||||
return "Custom Timezone Time";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupportedLocale(Locale locale) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale[] getAvailableLocales() {
|
||||
return new Locale[]{
|
||||
Locale.getDefault(Locale.Category.FORMAT)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 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.
|
||||
*
|
||||
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package custom;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.zone.ZoneRules;
|
||||
import java.time.zone.ZoneRulesProvider;
|
||||
import java.util.Set;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class CustomZoneRulesProvider extends ZoneRulesProvider {
|
||||
@Override
|
||||
protected Set<String> provideZoneIds() {
|
||||
return Set.of("Custom/Timezone");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ZoneRules provideRules(String zoneId, boolean forCaching) {
|
||||
return ZoneId.of("UTC").getRules();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NavigableMap<String, ZoneRules> provideVersions(String zoneId) {
|
||||
var map = new TreeMap<String, ZoneRules>();
|
||||
map.put("bogusVersion", getRules(zoneId, false));
|
||||
return map;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue