Skip to content

Commit 3ec0ab5

Browse files
[AUTO-CHERRYPICK] [Medium] Patch junit to fix CVE-2020-15250 - branch 3.0-dev (#12503)
Co-authored-by: jykanase <v-jykanase@microsoft.com>
1 parent 1fa2c57 commit 3ec0ab5

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

SPECS/junit/CVE-2020-15250.patch

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
From 2a3b5c8b4d62291d4c646b5fd9aac2753378b49e Mon Sep 17 00:00:00 2001
2+
From: jykanase <v-jykanase@microsoft.com>
3+
Date: Tue, 11 Feb 2025 13:28:51 +0000
4+
Subject: [PATCH] CVE-2020-15250
5+
6+
Source Link: https://github.com/junit-team/junit4/commit/610155b8c22138329f0723eec22521627dbc52ae
7+
---
8+
.../java/org/junit/rules/TemporaryFolder.java | 43 ++++++++++++++++++-
9+
1 file changed, 42 insertions(+), 1 deletion(-)
10+
11+
diff --git a/src/main/java/org/junit/rules/TemporaryFolder.java b/src/main/java/org/junit/rules/TemporaryFolder.java
12+
index 1a6a770..a726c66 100644
13+
--- a/src/main/java/org/junit/rules/TemporaryFolder.java
14+
+++ b/src/main/java/org/junit/rules/TemporaryFolder.java
15+
@@ -4,6 +4,9 @@ import static org.junit.Assert.fail;
16+
17+
import java.io.File;
18+
import java.io.IOException;
19+
+import java.lang.reflect.Array;
20+
+import java.lang.reflect.InvocationTargetException;
21+
+import java.lang.reflect.Method;
22+
23+
import org.junit.Rule;
24+
25+
@@ -229,7 +232,45 @@ public class TemporaryFolder extends ExternalResource {
26+
return createTemporaryFolderIn(getRoot());
27+
}
28+
29+
- private File createTemporaryFolderIn(File parentFolder) throws IOException {
30+
+ private static File createTemporaryFolderIn(File parentFolder) throws IOException {
31+
+ try {
32+
+ return createTemporaryFolderWithNioApi(parentFolder);
33+
+ } catch (ClassNotFoundException ignore) {
34+
+ // Fallback for Java 5 and 6
35+
+ return createTemporaryFolderWithFileApi(parentFolder);
36+
+ } catch (InvocationTargetException e) {
37+
+ Throwable cause = e.getCause();
38+
+ if (cause instanceof IOException) {
39+
+ throw (IOException) cause;
40+
+ }
41+
+ if (cause instanceof RuntimeException) {
42+
+ throw (RuntimeException) cause;
43+
+ }
44+
+ IOException exception = new IOException("Failed to create temporary folder in " + parentFolder);
45+
+ exception.initCause(cause);
46+
+ throw exception;
47+
+ } catch (Exception e) {
48+
+ throw new RuntimeException("Failed to create temporary folder in " + parentFolder, e);
49+
+ }
50+
+ }
51+
+
52+
+ private static File createTemporaryFolderWithNioApi(File parentFolder) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
53+
+ Class<?> filesClass = Class.forName("java.nio.file.Files");
54+
+ Object fileAttributeArray = Array.newInstance(Class.forName("java.nio.file.attribute.FileAttribute"), 0);
55+
+ Class<?> pathClass = Class.forName("java.nio.file.Path");
56+
+ Object tempDir;
57+
+ if (parentFolder != null) {
58+
+ Method createTempDirectoryMethod = filesClass.getDeclaredMethod("createTempDirectory", pathClass, String.class, fileAttributeArray.getClass());
59+
+ Object parentPath = File.class.getDeclaredMethod("toPath").invoke(parentFolder);
60+
+ tempDir = createTempDirectoryMethod.invoke(null, parentPath, TMP_PREFIX, fileAttributeArray);
61+
+ } else {
62+
+ Method createTempDirectoryMethod = filesClass.getDeclaredMethod("createTempDirectory", String.class, fileAttributeArray.getClass());
63+
+ tempDir = createTempDirectoryMethod.invoke(null, TMP_PREFIX, fileAttributeArray);
64+
+ }
65+
+ return (File) pathClass.getDeclaredMethod("toFile").invoke(tempDir);
66+
+ }
67+
+
68+
+ private static File createTemporaryFolderWithFileApi(File parentFolder) throws IOException {
69+
File createdFolder = null;
70+
for (int i = 0; i < TEMP_DIR_ATTEMPTS; ++i) {
71+
// Use createTempFile to get a suitable folder name.
72+
--
73+
2.45.2
74+

SPECS/junit/junit.spec

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Summary: Java regression test package
1919
Name: junit
2020
Version: 4.13
21-
Release: 6%{?dist}
21+
Release: 7%{?dist}
2222
License: EPL-1.0
2323
Vendor: Microsoft Corporation
2424
Distribution: Azure Linux
@@ -27,6 +27,7 @@ URL: https://www.junit.org/
2727
Source0: https://github.com/junit-team/junit/archive/r%{version}.tar.gz#/%{name}-%{version}.tar.gz
2828
Source1: build.xml
2929
Patch1: 0001-Port-to-hamcrest-2.2.patch
30+
Patch2: CVE-2020-15250.patch
3031
BuildRequires: ant
3132
BuildRequires: fdupes
3233
BuildRequires: hamcrest >= 1.3
@@ -68,6 +69,7 @@ Documentation for %{name}.
6869
%setup -q -n %{name}4-r%{version}
6970
cp %{SOURCE1} .
7071
%patch 1 -p1
72+
%patch 2 -p1
7173

7274
find . -type f -name "*.jar" -or -name "*.class" | xargs -t rm -rf
7375

@@ -123,6 +125,9 @@ java -cp %{buildroot}/%{_javadir}/%{name}.jar: test 2>&1 | \
123125
%doc doc/*
124126

125127
%changelog
128+
* Tue Feb 11 2025 Jyoti Kanase <v-jykanase@microsoft.com> - 4.13-7
129+
- Patch to fix CVE-2020-15250
130+
126131
* Wed Feb 28 2024 Riken Maharjan <rmaharjan@microsoft.com> - 4.13-6
127132
- rebuild with msopenjdk-17
128133

0 commit comments

Comments
 (0)