From 65572cc067cd2c64088a10391708934bef89305f Mon Sep 17 00:00:00 2001
From: Omair Majid <omajid@redhat.com>
Date: Dec 12 2018 19:17:24 +0000
Subject: Fix CVE-2018-8416


---

diff --git a/corefx-32165-out-of-directory-extract.patch b/corefx-32165-out-of-directory-extract.patch
new file mode 100644
index 0000000..ca93a09
--- /dev/null
+++ b/corefx-32165-out-of-directory-extract.patch
@@ -0,0 +1,53 @@
+From 65a19e18d7d4b94f50772bd3118c0b9868766af5 Mon Sep 17 00:00:00 2001
+From: Maryam Ariyan <maryam.ariyan@microsoft.com>
+Date: Fri, 7 Sep 2018 10:53:25 -0700
+Subject: [PATCH] Fixes extract out of directory by ensuring trailing separator
+ for nested paths.
+
+Related to PR #32127
+---
+ .../System/IO/Compression/ZipFileExtensions.cs  |  2 ++
+ .../tests/ZipFileConvenienceMethods.cs          | 17 +++++++++++++++++
+ 2 files changed, 19 insertions(+)
+
+diff --git a/src/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFileExtensions.cs b/src/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFileExtensions.cs
+index 3fef7883c953..c749c8250f9c 100644
+--- a/src/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFileExtensions.cs
++++ b/src/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFileExtensions.cs
+@@ -160,6 +160,8 @@ public static void ExtractToDirectory(this ZipArchive source, string destination
+             // Note that this will give us a good DirectoryInfo even if destinationDirectoryName exists:
+             DirectoryInfo di = Directory.CreateDirectory(destinationDirectoryName);
+             string destinationDirectoryFullPath = di.FullName;
++            if (!destinationDirectoryFullPath.EndsWith(Path.DirectorySeparatorChar))
++                destinationDirectoryFullPath += Path.DirectorySeparatorChar;
+ 
+             foreach (ZipArchiveEntry entry in source.Entries)
+             {
+diff --git a/src/System.IO.Compression.ZipFile/tests/ZipFileConvenienceMethods.cs b/src/System.IO.Compression.ZipFile/tests/ZipFileConvenienceMethods.cs
+index 69c822e3fc7e..3a0255d03862 100644
+--- a/src/System.IO.Compression.ZipFile/tests/ZipFileConvenienceMethods.cs
++++ b/src/System.IO.Compression.ZipFile/tests/ZipFileConvenienceMethods.cs
+@@ -186,6 +186,23 @@ public void ExtractToDirectoryExtension_Unicode()
+             }
+         }
+ 
++        [Theory]
++        [InlineData("../Foo")]
++        [InlineData("../Barbell")]
++        [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Second case fails.")]
++        public void ExtractOutOfRoot(string entryName)
++        {
++            string archivePath = GetTestFilePath();
++            using (FileStream stream = new FileStream(archivePath, FileMode.Create))
++            using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: true))
++            {
++                ZipArchiveEntry entry = archive.CreateEntry(entryName);
++            }
++
++            DirectoryInfo destination = Directory.CreateDirectory(Path.Combine(GetTestFilePath(), "Bar"));
++            Assert.Throws<IOException>(() => ZipFile.ExtractToDirectory(archivePath, destination.FullName));
++        }
++
+         [Fact]
+         public void CreatedEmptyDirectoriesRoundtrip()
+         {
diff --git a/dotnet.spec b/dotnet.spec
index 88c2714..e11292d 100644
--- a/dotnet.spec
+++ b/dotnet.spec
@@ -24,7 +24,7 @@
 
 Name:           dotnet
 Version:        %{sdk_version}
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        .NET Core CLI tools and runtime
 License:        MIT and ASL 2.0 and BSD
 URL:            https://github.com/dotnet/
@@ -42,6 +42,7 @@ Source2:        dotnet.sh
 
 Patch1:         corefx-optflags-support.patch
 Patch2:         corefx-32956-alpn.patch
+Patch3:         corefx-32165-out-of-directory-extract.patch
 
 Patch300:       core-setup-4510-commit-id.patch
 Patch400:       cli-telemetry-optout.patch
@@ -182,6 +183,7 @@ sed -i 's|/usr/share/dotnet|%{_libdir}/%{name}|' src/core-setup/src/corehost/com
 pushd src/corefx
 %patch1 -p1
 %patch2 -p1
+%patch3 -p1
 popd
 
 pushd src/core-setup
@@ -274,6 +276,9 @@ echo "Testing build results for debug symbols..."
 %{_libdir}/%{name}/sdk/%{sdk_version}
 
 %changelog
+* Wed Dec 12 2018 Omair Majid <omajid@redhat.com> - 2.1.500-3
+- Fix CVE-2018-8416
+
 * Thu Nov 22 2018 Omair Majid <omajid@redhat.com> - 2.1.500-2
 - Fix requires on subpackages
 

