[Pkg-cli-apps-commits] [keepass2] 01/01: fix-webdav-storage-with-mono-2.11.patch
Julian Taylor
jtaylor.debian at googlemail.com
Tue May 13 20:11:04 UTC 2014
This is an automated email from the git hooks/post-receive script.
jtaylor-guest pushed a commit to branch master
in repository keepass2.
commit cddc84d2f62e95cf9e9ccbe2ae6f219f2472e969
Author: Julian Taylor <jtaylor.debian at googlemail.com>
Date: Tue May 13 19:32:03 2014 +0200
fix-webdav-storage-with-mono-2.11.patch
fix possible dataloss when storing database via webdav (LP: #1315962)
thanks to David Lechner for the original patch
---
debian/changelog | 8 +
.../fix-webdav-storage-with-mono-2.11.patch | 321 +++++++++++++++++++++
debian/patches/series | 1 +
3 files changed, 330 insertions(+)
diff --git a/debian/changelog b/debian/changelog
index 49b6254..b80e26d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+keepass2 (2.26+dfsg-2) unstable; urgency=medium
+
+ * fix-webdav-storage-with-mono-2.11.patch:
+ fix possible dataloss when storing database via webdav (LP: #1315962)
+ thanks to David Lechner for the original patch
+
+ -- Julian Taylor <jtaylor.debian at googlemail.com> Tue, 13 May 2014 19:30:54 +0200
+
keepass2 (2.26+dfsg-1) unstable; urgency=medium
* New upstream release
diff --git a/debian/patches/fix-webdav-storage-with-mono-2.11.patch b/debian/patches/fix-webdav-storage-with-mono-2.11.patch
new file mode 100644
index 0000000..a7fbcd8
--- /dev/null
+++ b/debian/patches/fix-webdav-storage-with-mono-2.11.patch
@@ -0,0 +1,321 @@
+From: Julian Taylor <jtaylor.debian at googlemail.com>
+Date: Tue, 13 May 2014 19:14:00 +0200
+Subject: fix webdav storage with mono >= 2.11
+
+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/keepass2/+bug/1315962
+Bug: http://sourceforge.net/p/keepass/bugs/1117/
+Applied-Upstream: 2.27
+
+--- a/KeePass/Util/MonoWorkarounds.cs
++++ b/KeePass/Util/MonoWorkarounds.cs
+@@ -42,6 +42,13 @@ namespace KeePass.Util
+ // 5795:
+ // https://bugzilla.xamarin.com/show_bug.cgi?id=5795
+ // https://sourceforge.net/p/keepass/discussion/329220/thread/d23dc88b/
++ // 10163:
++ // https://bugzilla.xamarin.com/show_bug.cgi?id=10163
++ // https://sourceforge.net/p/keepass/bugs/1117/
++ // https://sourceforge.net/p/keepass/discussion/329221/thread/9422258c/
++ // https://github.com/mono/mono/commit/8e67b8c2fc7cb66bff7816ebf7c1039fb8cfc43b
++ // https://bugzilla.xamarin.com/show_bug.cgi?id=1512
++ // https://sourceforge.net/p/keepass/patches/89/
+ // 12525:
+ // https://bugzilla.xamarin.com/show_bug.cgi?id=12525
+ // https://sourceforge.net/p/keepass/discussion/329220/thread/54f61e9a/
+@@ -64,7 +71,16 @@ namespace KeePass.Util
+ // https://sourceforge.net/p/keepass/discussion/329220/thread/d50a79d6/
+ public static bool IsRequired(uint uBugID)
+ {
+- return MonoWorkarounds.IsRequired();
++ if(!MonoWorkarounds.IsRequired()) return false;
++
++ ulong v = NativeLib.MonoVersion;
++ if(v != 0)
++ {
++ if(uBugID == 10163)
++ return (v >= 0x0002000B00000000UL); // >= 2.11
++ }
++
++ return true;
+ }
+
+ public static void ApplyTo(Form f)
+--- a/KeePassLib/Native/NativeLib.cs
++++ b/KeePassLib/Native/NativeLib.cs
+@@ -20,6 +20,7 @@
+ using System;
+ using System.Collections.Generic;
+ using System.Text;
++using System.Text.RegularExpressions;
+ using System.Runtime.InteropServices;
+ using System.Windows.Forms;
+ using System.Threading;
+@@ -49,6 +50,43 @@ namespace KeePassLib.Native
+ set { m_bAllowNative = value; }
+ }
+
++ public static ulong? m_ouMonoVersion = null;
++ public static ulong MonoVersion
++ {
++ get
++ {
++ if(m_ouMonoVersion.HasValue) return m_ouMonoVersion.Value;
++
++ ulong uVersion = 0;
++ try
++ {
++ Type t = Type.GetType("Mono.Runtime");
++ if(t != null)
++ {
++ MethodInfo mi = t.GetMethod("GetDisplayName",
++ BindingFlags.NonPublic | BindingFlags.Static);
++ if(mi != null)
++ {
++ string strName = (mi.Invoke(null, null) as string);
++ if(!string.IsNullOrEmpty(strName))
++ {
++ Match m = Regex.Match(strName, "\\d+(\\.\\d+)+");
++ if(m.Success)
++ uVersion = StrUtil.ParseVersion(m.Value);
++ else { Debug.Assert(false); }
++ }
++ else { Debug.Assert(false); }
++ }
++ else { Debug.Assert(false); }
++ }
++ }
++ catch(Exception) { Debug.Assert(false); }
++
++ m_ouMonoVersion = uVersion;
++ return uVersion;
++ }
++ }
++
+ /// <summary>
+ /// Determine if the native library is installed.
+ /// </summary>
+--- a/KeePassLib/Serialization/IOConnection.cs
++++ b/KeePassLib/Serialization/IOConnection.cs
+@@ -22,6 +22,7 @@ using System.Collections.Generic;
+ using System.Text;
+ using System.IO;
+ using System.Net;
++using System.Reflection;
+ using System.Diagnostics;
+
+ #if (!KeePassLibSD && !KeePassRT)
+@@ -50,6 +51,175 @@ namespace KeePassLib.Serialization
+ }
+ #endif
+
++ public abstract class WrapperStream : Stream
++ {
++ private readonly Stream m_s;
++ protected Stream BaseStream
++ {
++ get { return m_s; }
++ }
++
++ public override bool CanRead
++ {
++ get { return m_s.CanRead; }
++ }
++
++ public override bool CanSeek
++ {
++ get { return m_s.CanSeek; }
++ }
++
++ public override bool CanTimeout
++ {
++ get { return m_s.CanTimeout; }
++ }
++
++ public override bool CanWrite
++ {
++ get { return m_s.CanWrite; }
++ }
++
++ public override long Length
++ {
++ get { return m_s.Length; }
++ }
++
++ public override long Position
++ {
++ get { return m_s.Position; }
++ set { m_s.Position = value; }
++ }
++
++ public override int ReadTimeout
++ {
++ get { return m_s.ReadTimeout; }
++ set { m_s.ReadTimeout = value; }
++ }
++
++ public override int WriteTimeout
++ {
++ get { return m_s.WriteTimeout; }
++ set { m_s.WriteTimeout = value; }
++ }
++
++ public WrapperStream(Stream sBase) : base()
++ {
++ if(sBase == null) throw new ArgumentNullException("sBase");
++
++ m_s = sBase;
++ }
++
++ public override IAsyncResult BeginRead(byte[] buffer, int offset,
++ int count, AsyncCallback callback, object state)
++ {
++ return m_s.BeginRead(buffer, offset, count, callback, state);
++ }
++
++ public override IAsyncResult BeginWrite(byte[] buffer, int offset,
++ int count, AsyncCallback callback, object state)
++ {
++ return BeginWrite(buffer, offset, count, callback, state);
++ }
++
++ public override void Close()
++ {
++ m_s.Close();
++ }
++
++ public override int EndRead(IAsyncResult asyncResult)
++ {
++ return m_s.EndRead(asyncResult);
++ }
++
++ public override void EndWrite(IAsyncResult asyncResult)
++ {
++ m_s.EndWrite(asyncResult);
++ }
++
++ public override void Flush()
++ {
++ m_s.Flush();
++ }
++
++ public override int Read(byte[] buffer, int offset, int count)
++ {
++ return m_s.Read(buffer, offset, count);
++ }
++
++ public override int ReadByte()
++ {
++ return m_s.ReadByte();
++ }
++
++ public override long Seek(long offset, SeekOrigin origin)
++ {
++ return m_s.Seek(offset, origin);
++ }
++
++ public override void SetLength(long value)
++ {
++ m_s.SetLength(value);
++ }
++
++ public override void Write(byte[] buffer, int offset, int count)
++ {
++ m_s.Write(buffer, offset, count);
++ }
++
++ public override void WriteByte(byte value)
++ {
++ m_s.WriteByte(value);
++ }
++ }
++
++ public sealed class IocStream : WrapperStream
++ {
++ private readonly bool m_bWrite; // Initially opened for writing
++
++ public IocStream(Stream sBase) : base(sBase)
++ {
++ m_bWrite = sBase.CanWrite;
++ }
++
++ public override void Close()
++ {
++ base.Close();
++
++ if(m_bWrite)
++ {
++ try
++ {
++ Stream s = this.BaseStream;
++ Type t = s.GetType();
++ if(t.Name == "WebConnectionStream")
++ {
++ PropertyInfo pi = t.GetProperty("Request",
++ BindingFlags.Instance | BindingFlags.NonPublic);
++ if(pi != null)
++ {
++ WebRequest wr = (pi.GetValue(s, null) as WebRequest);
++ if(wr != null)
++ IOConnection.DisposeResponse(wr.GetResponse(), false);
++ else { Debug.Assert(false); }
++ }
++ else { Debug.Assert(false); }
++ }
++ }
++ catch(Exception) { Debug.Assert(false); }
++ }
++ }
++
++ public static Stream WrapIfRequired(Stream s)
++ {
++ if(s == null) { Debug.Assert(false); return null; }
++
++ if(s.CanWrite)
++ return new IocStream(s);
++
++ return s;
++ }
++ }
++
+ public static class IOConnection
+ {
+ #if (!KeePassLibSD && !KeePassRT)
+@@ -244,7 +414,8 @@ namespace KeePassLib.Serialization
+
+ if(ioc.IsLocalFile()) return OpenReadLocal(ioc);
+
+- return CreateWebClient(ioc).OpenRead(new Uri(ioc.Path));
++ return IocStream.WrapIfRequired(CreateWebClient(ioc).OpenRead(
++ new Uri(ioc.Path)));
+ }
+ #else
+ public static Stream OpenRead(IOConnectionInfo ioc)
+@@ -271,15 +442,17 @@ namespace KeePassLib.Serialization
+ if(ioc.IsLocalFile()) return OpenWriteLocal(ioc);
+
+ Uri uri = new Uri(ioc.Path);
++ Stream s;
+
+ // Mono does not set HttpWebRequest.Method to POST for writes,
+ // so one needs to set the method to PUT explicitly
+ if(NativeLib.IsUnix() && (uri.Scheme.Equals(Uri.UriSchemeHttp,
+ StrUtil.CaseIgnoreCmp) || uri.Scheme.Equals(Uri.UriSchemeHttps,
+ StrUtil.CaseIgnoreCmp)))
+- return CreateWebClient(ioc).OpenWrite(uri, WebRequestMethods.Http.Put);
++ s = CreateWebClient(ioc).OpenWrite(uri, WebRequestMethods.Http.Put);
++ else s = CreateWebClient(ioc).OpenWrite(uri);
+
+- return CreateWebClient(ioc).OpenWrite(uri);
++ return IocStream.WrapIfRequired(s);
+ }
+ #else
+ public static Stream OpenWrite(IOConnectionInfo ioc)
+@@ -443,7 +616,7 @@ namespace KeePassLib.Serialization
+ }
+ #endif
+
+- private static void DisposeResponse(WebResponse wr, bool bGetStream)
++ public static void DisposeResponse(WebResponse wr, bool bGetStream)
+ {
+ if(wr == null) return;
+
diff --git a/debian/patches/series b/debian/patches/series
index f2fef72..e18be3c 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -6,3 +6,4 @@ fix-XSL-search-path.patch
remove-ToolsVersion-3.5.patch
enable-local-help.patch
disable-autoupdate-dialog.patch
+fix-webdav-storage-with-mono-2.11.patch
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-cli-apps/packages/keepass2.git
More information about the Pkg-cli-apps-commits
mailing list