code:
Fix CVE-2017-7853:

https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-7853
https://savannah.gnu.org/support/index.php?109265

Patch copied from upstream source repository:

https://git.savannah.gnu.org/cgit/osip.git/commit/?id=1ae06daf3b2375c34af23083394a6f010be24a45

From 1ae06daf3b2375c34af23083394a6f010be24a45 Mon Sep 17 00:00:00 2001
From: Aymeric Moizard <amoizard@gmail.com>
Date: Tue, 21 Feb 2017 17:16:26 +0100
Subject: [PATCH]  * fix bug report: sr #109265: SIP message body length
 underflow in libosip2-4.1.0    https://savannah.gnu.org/support/?109265
 also applicable to current latest version

---
 src/osipparser2/osip_message_parse.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/osipparser2/osip_message_parse.c b/src/osipparser2/osip_message_parse.c
index 1628c60..aa35446 100644
--- a/src/osipparser2/osip_message_parse.c
+++ b/src/osipparser2/osip_message_parse.c
@@ -784,6 +784,12 @@ msg_osip_body_parse (osip_message_t * sip, const char *start_of_buf, const char
     if ('\n' == start_of_body[0] || '\r' == start_of_body[0])
       start_of_body++;

+    /* if message body is empty or contains a single CR/LF */
+    if (end_of_body <= start_of_body) {
+      osip_free (sep_boundary);
+      return OSIP_SYNTAXERROR;
+    }
+
     body_len = end_of_body - start_of_body;

     /* Skip CR before end boundary. */
--
2.13.1


code:
The file $(top_srcdir)/gtk-doc.make doesn't exist, so don't include it.

--- a/doc/Makefile.in	2007-04-08 20:17:25.000000000 +0200
+++ b/doc/Makefile.in	2014-09-06 23:19:41.413397662 +0200
@@ -240,9 +240,6 @@
 distclean-generic clean-generic maintainer-clean-generic clean \
 mostlyclean distclean maintainer-clean

-
-include $(top_srcdir)/gtk-doc.make
-
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:

license: mit


code:
This patch is taken from Debian and modified slightly

Description: Phoning-home version checks should be disabled in Debian packages
Author: Sandro Knauß <bugs@ssandroknauss.de>
Origin: debian
Bug-debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=721341
Forwarded: not-needed
Last-Update: 2014-02-17
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/src/libsync/configfile.cpp
+++ b/src/libsync/configfile.cpp
@@ -417,11 +417,14 @@ bool ConfigFile::skipUpdateCheck( const
     QString con( connection );
     if( connection.isEmpty() ) con = defaultConnection();

-    QVariant fallback = getValue(QLatin1String(skipUpdateCheckC), con, false);
+    QVariant fallback = getValue(QLatin1String(skipUpdateCheckC), con, true);
     fallback = getValue(QLatin1String(skipUpdateCheckC), QString(), fallback);

     QVariant value = getPolicySetting(QLatin1String(skipUpdateCheckC), fallback);
-    return value.toBool();
+    if ( !value.toBool() )
+        qDebug() << "Guix has disabled the UpdateCheck mechanism.";
+
+    return true;
 }

 void ConfigFile::setSkipUpdateCheck( bool skip, const QString& connection )
--- a/src/gui/generalsettings.cpp
+++ b/src/gui/generalsettings.cpp
@@ -124,6 +124,7 @@ void GeneralSettings::loadMiscSettings()

 void GeneralSettings::slotUpdateInfo()
 {
+    /* Guix doesn't want an autoupdater
     // Note: the sparkle-updater is not an OCUpdater
     OCUpdater *updater = qobject_cast<OCUpdater*>(Updater::instance());
     if (ConfigFile().skipUpdateCheck()) {
@@ -140,6 +141,9 @@ void GeneralSettings::slotUpdateInfo()
         // can't have those infos from sparkle currently
         _ui->updatesGroupBox->setVisible(false);
     }
+    */
+    //hide the update group box for Guix.
+    _ui->updatesGroupBox->setVisible(false);
 }

 void GeneralSettings::saveMiscSettings()


code:
From: Robert Luberda <robert@debian.org>
Date: Sat, 19 Nov 2016 08:48:08 +0100
Subject: Fix nullptr dereference (CVE-2016-9296)

Patch taken from https://sourceforge.net/p/p7zip/bugs/185/
This patch file taken from Debian's patch set for p7zip
---
 CPP/7zip/Archive/7z/7zIn.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/CPP/7zip/Archive/7z/7zIn.cpp b/CPP/7zip/Archive/7z/7zIn.cpp
index b0c6b98..7c6dde2 100644
--- a/CPP/7zip/Archive/7z/7zIn.cpp
+++ b/CPP/7zip/Archive/7z/7zIn.cpp
@@ -1097,7 +1097,8 @@ HRESULT CInArchive::ReadAndDecodePackedStreams(
       if (CrcCalc(data, unpackSize) != folders.FolderCRCs.Vals[i])
         ThrowIncorrect();
   }
-  HeadersSize += folders.PackPositions[folders.NumPackStreams];
+  if (folders.PackPositions)
+      HeadersSize += folders.PackPositions[folders.NumPackStreams];
   return S_OK;
 }


code:
Fix CVE-2017-17969:

https://sourceforge.net/p/p7zip/bugs/204/
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-17969

Patch copied from Debian.

Subject: Heap-based buffer overflow in 7zip/Compress/ShrinkDecoder.cpp
Origin: vendor, https://sourceforge.net/p/p7zip/bugs/_discuss/thread/0920f369/27d7/attachment/CVE-2017-17969.patch
Forwarded: https://sourceforge.net/p/p7zip/bugs/_discuss/thread/0920f369/#27d7
Bug: https://sourceforge.net/p/p7zip/bugs/204/
Bug-Debian: https://bugs.debian.org/888297
Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2017-17969
Author: Antoine Beaupré <anarcat@debian.org>
Reviewed-by: Salvatore Bonaccorso <carnil@debian.org>
Last-Update: 2018-02-01
Applied-Upstream: 18.00-beta

--- a/CPP/7zip/Compress/ShrinkDecoder.cpp
+++ b/CPP/7zip/Compress/ShrinkDecoder.cpp
@@ -121,8 +121,13 @@ HRESULT CDecoder::CodeReal(ISequentialIn
     {
       _stack[i++] = _suffixes[cur];
       cur = _parents[cur];
+      if (cur >= kNumItems || i >= kNumItems)
+        break;
     }
-
+
+    if (cur >= kNumItems || i >= kNumItems)
+      break;
+
     _stack[i++] = (Byte)cur;
     lastChar2 = (Byte)cur;


code:
diff --git a/C/Sha1.c b/C/Sha1.c
index 55c1c63..48b4c5d 100644
--- a/C/Sha1.c
+++ b/C/Sha1.c
@@ -104,39 +104,6 @@ void Sha1_GetBlockDigest(CSha1 *p, const UInt32 *data, UInt32 *destDigest)
   destDigest[4] = p->state[4] + e;
 }

-void Sha1_UpdateBlock_Rar(CSha1 *p, UInt32 *data, int returnRes)
-{
-  UInt32 a, b, c, d, e;
-  UInt32 W[kNumW];
-
-  a = p->state[0];
-  b = p->state[1];
-  c = p->state[2];
-  d = p->state[3];
-  e = p->state[4];
-
-  RX_15
-
-  RX_1_4(R0, R1, 15);
-
-  RX_20(R2, 20);
-  RX_20(R3, 40);
-  RX_20(R4, 60);
-
-  p->state[0] += a;
-  p->state[1] += b;
-  p->state[2] += c;
-  p->state[3] += d;
-  p->state[4] += e;
-
-  if (returnRes)
-  {
-    unsigned i;
-    for (i = 0 ; i < SHA1_NUM_BLOCK_WORDS; i++)
-      data[i] = W[kNumW - SHA1_NUM_BLOCK_WORDS + i];
-  }
-}
-
 #define Sha1_UpdateBlock(p) Sha1_GetBlockDigest(p, p->buffer, p->state)

 void Sha1_Update(CSha1 *p, const Byte *data, size_t size)
@@ -212,46 +179,6 @@ void Sha1_Update(CSha1 *p, const Byte *data, size_t size)
   }
 }

-void Sha1_Update_Rar(CSha1 *p, Byte *data, size_t size /* , int rar350Mode */)
-{
-  int returnRes = False;
-
-  unsigned pos = (unsigned)p->count & 0x3F;
-  p->count += size;
-
-  while (size--)
-  {
-    unsigned pos2 = (pos & 3);
-    UInt32 v = ((UInt32)*data++) << (8 * (3 - pos2));
-    UInt32 *ref = &(p->buffer[pos >> 2]);
-    pos++;
-    if (pos2 == 0)
-    {
-      *ref = v;
-      continue;
-    }
-    *ref |= v;
-
-    if (pos == SHA1_BLOCK_SIZE)
-    {
-      pos = 0;
-      Sha1_UpdateBlock_Rar(p, p->buffer, returnRes);
-      if (returnRes)
-      {
-        unsigned i;
-        for (i = 0; i < SHA1_NUM_BLOCK_WORDS; i++)
-        {
-          UInt32 d = p->buffer[i];
-          Byte *prev = data + i * 4 - SHA1_BLOCK_SIZE;
-          SetUi32(prev, d);
-        }
-      }
-      // returnRes = rar350Mode;
-      returnRes = True;
-    }
-  }
-}
-
 void Sha1_Final(CSha1 *p, Byte *digest)
 {
   unsigned pos = (unsigned)p->count & 0x3F;
diff --git a/C/Sha1.h b/C/Sha1.h
index aa22ec3..9c45653 100644
--- a/C/Sha1.h
+++ b/C/Sha1.h
@@ -27,8 +27,6 @@ void Sha1_GetBlockDigest(CSha1 *p, const UInt32 *data, UInt32 *destDigest);
 void Sha1_Update(CSha1 *p, const Byte *data, size_t size);
 void Sha1_Final(CSha1 *p, Byte *digest);

-void Sha1_Update_Rar(CSha1 *p, Byte *data, size_t size /* , int rar350Mode */);
-
 void Sha1_32_PrepareBlock(const CSha1 *p, UInt32 *block, unsigned size);
 void Sha1_32_Update(CSha1 *p, const UInt32 *data, size_t size);
 void Sha1_32_Final(CSha1 *p, UInt32 *digest);
diff --git a/CPP/7zip/Archive/7z/7zUpdate.cpp b/CPP/7zip/Archive/7z/7zUpdate.cpp
index a0571e7..43ad3e9 100644
--- a/CPP/7zip/Archive/7z/7zUpdate.cpp
+++ b/CPP/7zip/Archive/7z/7zUpdate.cpp
@@ -562,7 +562,7 @@ static int CompareEmptyItems(const unsigned *p1, const unsigned *p2, void *param
 }

 static const char *g_Exts =
-  " 7z xz lzma ace arc arj bz tbz bz2 tbz2 cab deb gz tgz ha lha lzh lzo lzx pak rar rpm sit zoo"
+  " 7z xz lzma ace arc arj bz tbz bz2 tbz2 cab deb gz tgz ha lha lzh lzo lzx pak rpm sit zoo"
   " zip jar ear war msi"
   " 3gp avi mov mpeg mpg mpe wmv"
   " aac ape fla flac la mp3 m4a mp4 ofr ogg pac ra rm rka shn swa tta wv wma wav"
diff --git a/CPP/7zip/Bundles/Format7zFree/makefile.list b/CPP/7zip/Bundles/Format7zFree/makefile.list
index da2056b..1dcf1a5 100644
--- a/CPP/7zip/Bundles/Format7zFree/makefile.list
+++ b/CPP/7zip/Bundles/Format7zFree/makefile.list
@@ -87,8 +87,6 @@ SRCS=\
   ../../../../CPP/7zip/Archive/PeHandler.cpp \
   ../../../../CPP/7zip/Archive/PpmdHandler.cpp \
   ../../../../CPP/7zip/Archive/QcowHandler.cpp \
-  ../../../../CPP/7zip/Archive/Rar/RarHandler.cpp \
-  ../../../../CPP/7zip/Archive/Rar/Rar5Handler.cpp \
   ../../../../CPP/7zip/Archive/RpmHandler.cpp \
   ../../../../CPP/7zip/Archive/SplitHandler.cpp \
   ../../../../CPP/7zip/Archive/SquashfsHandler.cpp \
@@ -191,9 +189,6 @@ SRCS=\
   ../../../../CPP/7zip/Crypto/MyAesReg.cpp \
   ../../../../CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp \
   ../../../../CPP/7zip/Crypto/RandGen.cpp \
-  ../../../../CPP/7zip/Crypto/Rar20Crypto.cpp \
-  ../../../../CPP/7zip/Crypto/Rar5Aes.cpp \
-  ../../../../CPP/7zip/Crypto/RarAes.cpp \
   ../../../../CPP/7zip/Crypto/WzAes.cpp \
   ../../../../CPP/7zip/Crypto/ZipCrypto.cpp \
   ../../../../CPP/7zip/Crypto/ZipStrong.cpp \
@@ -485,10 +480,6 @@ PpmdHandler.o : ../../../../CPP/7zip/Archive/PpmdHandler.cpp
 	$(CXX) $(CXXFLAGS) ../../../../CPP/7zip/Archive/PpmdHandler.cpp
 QcowHandler.o : ../../../../CPP/7zip/Archive/QcowHandler.cpp
 	$(CXX) $(CXXFLAGS) ../../../../CPP/7zip/Archive/QcowHandler.cpp
-RarHandler.o : ../../../../CPP/7zip/Archive/Rar/RarHandler.cpp
-	$(CXX) $(CXXFLAGS) ../../../../CPP/7zip/Archive/Rar/RarHandler.cpp
-Rar5Handler.o : ../../../../CPP/7zip/Archive/Rar/Rar5Handler.cpp
-	$(CXX) $(CXXFLAGS) ../../../../CPP/7zip/Archive/Rar/Rar5Handler.cpp
 RpmHandler.o : ../../../../CPP/7zip/Archive/RpmHandler.cpp
 	$(CXX) $(CXXFLAGS) ../../../../CPP/7zip/Archive/RpmHandler.cpp
 SplitHandler.o : ../../../../CPP/7zip/Archive/SplitHandler.cpp
@@ -693,12 +684,6 @@ Pbkdf2HmacSha1.o : ../../../../CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp
 	$(CXX) $(CXXFLAGS) ../../../../CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp
 RandGen.o : ../../../../CPP/7zip/Crypto/RandGen.cpp
 	$(CXX) $(CXXFLAGS) ../../../../CPP/7zip/Crypto/RandGen.cpp
-Rar20Crypto.o : ../../../../CPP/7zip/Crypto/Rar20Crypto.cpp
-	$(CXX) $(CXXFLAGS) ../../../../CPP/7zip/Crypto/Rar20Crypto.cpp
-Rar5Aes.o : ../../../../CPP/7zip/Crypto/Rar5Aes.cpp
-	$(CXX) $(CXXFLAGS) ../../../../CPP/7zip/Crypto/Rar5Aes.cpp
-RarAes.o : ../../../../CPP/7zip/Crypto/RarAes.cpp
-	$(CXX) $(CXXFLAGS) ../../../../CPP/7zip/Crypto/RarAes.cpp
 WzAes.o : ../../../../CPP/7zip/Crypto/WzAes.cpp
 	$(CXX) $(CXXFLAGS) ../../../../CPP/7zip/Crypto/WzAes.cpp
 ZipCrypto.o : ../../../../CPP/7zip/Crypto/ZipCrypto.cpp
@@ -869,8 +854,6 @@ OBJS=\
  PeHandler.o \
  PpmdHandler.o \
  QcowHandler.o \
- RarHandler.o \
- Rar5Handler.o \
  RpmHandler.o \
  SplitHandler.o \
  SquashfsHandler.o \
@@ -973,9 +956,6 @@ OBJS=\
  MyAesReg.o \
  Pbkdf2HmacSha1.o \
  RandGen.o \
- Rar20Crypto.o \
- Rar5Aes.o \
- RarAes.o \
  WzAes.o \
  ZipCrypto.o \
  ZipStrong.o \
diff --git a/CPP/7zip/CMAKE/Format7zFree/CMakeLists.txt b/CPP/7zip/CMAKE/Format7zFree/CMakeLists.txt
index 61f41f9..adc7117 100644
--- a/CPP/7zip/CMAKE/Format7zFree/CMakeLists.txt
+++ b/CPP/7zip/CMAKE/Format7zFree/CMakeLists.txt
@@ -126,8 +126,6 @@ add_library(7z MODULE
   "../../../../CPP/7zip/Archive/PeHandler.cpp"
   "../../../../CPP/7zip/Archive/PpmdHandler.cpp"
   "../../../../CPP/7zip/Archive/QcowHandler.cpp"
-  "../../../../CPP/7zip/Archive/Rar/RarHandler.cpp"
-  "../../../../CPP/7zip/Archive/Rar/Rar5Handler.cpp"
   "../../../../CPP/7zip/Archive/RpmHandler.cpp"
   "../../../../CPP/7zip/Archive/SplitHandler.cpp"
   "../../../../CPP/7zip/Archive/SquashfsHandler.cpp"
@@ -230,9 +228,6 @@ add_library(7z MODULE
   "../../../../CPP/7zip/Crypto/MyAesReg.cpp"
   "../../../../CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp"
   "../../../../CPP/7zip/Crypto/RandGen.cpp"
-  "../../../../CPP/7zip/Crypto/Rar20Crypto.cpp"
-  "../../../../CPP/7zip/Crypto/Rar5Aes.cpp"
-  "../../../../CPP/7zip/Crypto/RarAes.cpp"
   "../../../../CPP/7zip/Crypto/WzAes.cpp"
   "../../../../CPP/7zip/Crypto/ZipCrypto.cpp"
   "../../../../CPP/7zip/Crypto/ZipStrong.cpp"
diff --git a/CPP/7zip/Crypto/Sha1Cls.h b/CPP/7zip/Crypto/Sha1Cls.h
index 71acbde..cde4a57 100644
--- a/CPP/7zip/Crypto/Sha1Cls.h
+++ b/CPP/7zip/Crypto/Sha1Cls.h
@@ -28,7 +28,6 @@ class CContext: public CContextBase
 {
 public:
   void Update(const Byte *data, size_t size) throw() { Sha1_Update(&_s, data, size); }
-  void UpdateRar(Byte *data, size_t size /* , bool rar350Mode */) throw() { Sha1_Update_Rar(&_s, data, size /* , rar350Mode ? 1 : 0 */); }
   void Final(Byte *digest) throw() { Sha1_Final(&_s, digest); }
 };

diff --git a/CPP/7zip/Guid.txt b/CPP/7zip/Guid.txt
index 7edab6e..cc22992 100644
--- a/CPP/7zip/Guid.txt
+++ b/CPP/7zip/Guid.txt
@@ -151,7 +151,6 @@ Handler GUIDs:

   01 Zip
   02 BZip2
-  03 Rar
   04 Arj
   05 Z
   06 Lzh
@@ -168,7 +167,6 @@ Handler GUIDs:
   C9 VDI
   CA Qcow
   CB GPT
-  CC Rar5
   CD IHex
   CE Hxs
   CF TE
diff --git a/CPP/7zip/QMAKE/Format7zFree/Format7zFree.pro b/CPP/7zip/QMAKE/Format7zFree/Format7zFree.pro
index afa36d4..93c45c7 100644
--- a/CPP/7zip/QMAKE/Format7zFree/Format7zFree.pro
+++ b/CPP/7zip/QMAKE/Format7zFree/Format7zFree.pro
@@ -137,8 +137,6 @@ SOURCES +=  \
   ../../../../CPP/7zip/Archive/PeHandler.cpp \
   ../../../../CPP/7zip/Archive/PpmdHandler.cpp \
   ../../../../CPP/7zip/Archive/QcowHandler.cpp \
-  ../../../../CPP/7zip/Archive/Rar/RarHandler.cpp \
-  ../../../../CPP/7zip/Archive/Rar/Rar5Handler.cpp \
   ../../../../CPP/7zip/Archive/RpmHandler.cpp \
   ../../../../CPP/7zip/Archive/SplitHandler.cpp \
   ../../../../CPP/7zip/Archive/SquashfsHandler.cpp \
@@ -241,9 +239,6 @@ SOURCES +=  \
   ../../../../CPP/7zip/Crypto/MyAesReg.cpp \
   ../../../../CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp \
   ../../../../CPP/7zip/Crypto/RandGen.cpp \
-  ../../../../CPP/7zip/Crypto/Rar20Crypto.cpp \
-  ../../../../CPP/7zip/Crypto/Rar5Aes.cpp \
-  ../../../../CPP/7zip/Crypto/RarAes.cpp \
   ../../../../CPP/7zip/Crypto/WzAes.cpp \
   ../../../../CPP/7zip/Crypto/ZipCrypto.cpp \
   ../../../../CPP/7zip/Crypto/ZipStrong.cpp \
diff --git a/CPP/7zip/QMAKE/all.pro b/CPP/7zip/QMAKE/all.pro
index a565ba8..6668619 100644
--- a/CPP/7zip/QMAKE/all.pro
+++ b/CPP/7zip/QMAKE/all.pro
@@ -4,7 +4,6 @@ SUBDIRS = 7za \
           7zr \
           7z_ \
           Format7zFree \
-          Rar \
           Lzham \
           test_lib

diff --git a/CPP/7zip/UI/Client7z/Client7z.cpp b/CPP/7zip/UI/Client7z/Client7z.cpp
index d0eca6d..7f4e6e2 100644
--- a/CPP/7zip/UI/Client7z/Client7z.cpp
+++ b/CPP/7zip/UI/Client7z/Client7z.cpp
@@ -32,7 +32,7 @@ HINSTANCE g_hInstance = 0;
 #endif

 // Tou can find the list of all GUIDs in Guid.txt file.
-// use another CLSIDs, if you want to support other formats (zip, rar, ...).
+// use another CLSIDs, if you want to support other formats (zip, ...).
 // {23170F69-40C1-278A-1000-000110070000}

 DEFINE_GUID(CLSID_CFormat7z,
diff --git a/CPP/7zip/UI/Common/LoadCodecs.h b/CPP/7zip/UI/Common/LoadCodecs.h
index ac9eeac..076bd1c 100644
--- a/CPP/7zip/UI/Common/LoadCodecs.h
+++ b/CPP/7zip/UI/Common/LoadCodecs.h
@@ -158,7 +158,6 @@ struct CArcInfoEx
   void AddExts(const UString &ext, const UString &addExt);

   bool IsSplit() const { return StringsAreEqualNoCase_Ascii(Name, "Split"); }
-  // bool IsRar() const { return StringsAreEqualNoCase_Ascii(Name, "Rar"); }

   CArcInfoEx():
       Flags(0),
diff --git a/CPP/7zip/UI/Common/OpenArchive.cpp b/CPP/7zip/UI/Common/OpenArchive.cpp
index 7d5b0c4..88ea5ab 100644
--- a/CPP/7zip/UI/Common/OpenArchive.cpp
+++ b/CPP/7zip/UI/Common/OpenArchive.cpp
@@ -1063,7 +1063,6 @@ static const char * const k_Formats_with_simple_signuature[] =
 {
     "7z"
   , "xz"
-  , "rar"
   , "bzip2"
   , "gzip"
   , "cab"
@@ -1720,29 +1719,6 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
         {
           // signature search was here
         }
-        else if (extension.IsEqualTo("000") || extension.IsEqualTo("001"))
-        {
-          int i = FindFormatForArchiveType(op.codecs, orderIndices, "rar");
-          if (i >= 0)
-          {
-            const size_t kBufSize = (1 << 10);
-            byteBuffer.Alloc(kBufSize);
-            size_t processedSize = kBufSize;
-            RINOK(ReadStream(op.stream, byteBuffer, &processedSize));
-            if (processedSize >= 16)
-            {
-              const Byte *buf = byteBuffer;
-              const Byte kRarHeader[] = { 0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00 };
-              if (TestSignature(buf, kRarHeader, 7) && buf[9] == 0x73 && (buf[10] & 1) != 0)
-              {
-                orderIndices2.Add(orderIndices[i]);
-                orderIndices[i] = -1;
-                if (i >= (int)numFinded)
-                  numFinded++;
-              }
-            }
-          }
-        }
         else
         {
           const size_t kBufSize = (1 << 10);
diff --git a/CPP/7zip/UI/FileManager/FM_rc.cpp b/CPP/7zip/UI/FileManager/FM_rc.cpp
index 83578ed..034feed 100644
--- a/CPP/7zip/UI/FileManager/FM_rc.cpp
+++ b/CPP/7zip/UI/FileManager/FM_rc.cpp
@@ -821,8 +821,6 @@ REGISTER_STRINGTABLE(g_stringTable)

 /////////////////////////////////////////////////////

-#include "res/ParentFolder.h"
-
 	SevenZipPanel::SevenZipPanel(MyFrame *frame, wxWindow *parent,int id,int panelIndex) :
 	       	wxPanel(parent,id) , m_frame(frame), _wList(0)
 	{
@@ -840,7 +838,7 @@ REGISTER_STRINGTABLE(g_stringTable)
 		int sizes[] = {150, 250, 350, -1};
 		wxArrayString pathArray;
 		wxBoxSizer *pPathSizer = new wxBoxSizer(wxHORIZONTAL);
-		m_pBmpButtonParentFolder = new wxBitmapButton(this, kParentFolderID, wxGetBitmapFromMemory(PARENT_FOLDER), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW);
+		m_pBmpButtonParentFolder = new wxBitmapButton(this, kParentFolderID, wxArtProvider::GetBitmap(wxART_GO_DIR_UP, wxART_TOOLBAR, wxDefaultSize), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW);
 		m_pComboBoxPath = new wxComboBox(this, _comboBoxID, wxEmptyString, wxDefaultPosition, wxSize(300,-1), pathArray, wxCB_DROPDOWN | wxCB_SORT );
 		pPathSizer->Add(m_pBmpButtonParentFolder, 0, wxALL|wxEXPAND, 0);
 		pPathSizer->Add(m_pComboBoxPath, 1, wxALL|wxEXPAND, 5);
diff --git a/CPP/ANDROID/Format7zFree/jni/Android.mk b/CPP/ANDROID/Format7zFree/jni/Android.mk
index 7c74e73..48cb4fa 100644
--- a/CPP/ANDROID/Format7zFree/jni/Android.mk
+++ b/CPP/ANDROID/Format7zFree/jni/Android.mk
@@ -91,8 +91,6 @@ LOCAL_SRC_FILES := \
   ../../../../CPP/7zip/Archive/PeHandler.cpp \
   ../../../../CPP/7zip/Archive/PpmdHandler.cpp \
   ../../../../CPP/7zip/Archive/QcowHandler.cpp \
-  ../../../../CPP/7zip/Archive/Rar/RarHandler.cpp \
-  ../../../../CPP/7zip/Archive/Rar/Rar5Handler.cpp \
   ../../../../CPP/7zip/Archive/RpmHandler.cpp \
   ../../../../CPP/7zip/Archive/SplitHandler.cpp \
   ../../../../CPP/7zip/Archive/SquashfsHandler.cpp \
@@ -195,9 +193,6 @@ LOCAL_SRC_FILES := \
   ../../../../CPP/7zip/Crypto/MyAesReg.cpp \
   ../../../../CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp \
   ../../../../CPP/7zip/Crypto/RandGen.cpp \
-  ../../../../CPP/7zip/Crypto/Rar20Crypto.cpp \
-  ../../../../CPP/7zip/Crypto/Rar5Aes.cpp \
-  ../../../../CPP/7zip/Crypto/RarAes.cpp \
   ../../../../CPP/7zip/Crypto/WzAes.cpp \
   ../../../../CPP/7zip/Crypto/ZipCrypto.cpp \
   ../../../../CPP/7zip/Crypto/ZipStrong.cpp \
diff --git a/ChangeLog b/ChangeLog
index daabd8e..f2a01d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -28,7 +28,6 @@ Version 16.00 (never published)
       - 7z update bcj bugs were fixed.
       - split (aaa.001) fixed
       - iso loop fix
-      - rar4 multivol -stdin kpidSize
       - drag and drop 1<2.txt
       - memory access violation fix

@@ -80,11 +79,6 @@ Version 15.12 (never published)
     - "There are no errors" string after "Test" operation inside archive.
     - The bugs in LZMA SDK were fixed (but these bugs are not related directly to 7-Zip's code).

-
-  - From Windows version of 7-Zip 15.11 :
-        - Some bugs were fixed.
-        - 7-Zip 15.10 showed incorrect error message about missing volume for multivolume RAR archives.
-
    - ..../LZHAM added

@@ -104,9 +98,6 @@ Version 15.10 beta
 	  version (-m switch).
     - Some bugs were fixed.
       - extracting from solid wim archives worked incorrectly in some cases,
-    - Also there are some minor changes.
-      - 7-Zip can show the name of missing volume for multivolume RAR and VMDK archives.
-      - Some internal changes with 7-Zip Benchmark.

 Version 15.09 beta
 ==================
@@ -128,8 +119,6 @@ Version 15.08 beta
 Version 15.07 beta
 ==================

-  - "bin/Codecs/Rar29.so" renamed to "bin/Codecs/Rar.so"
-
   - support for cygwin 64 bits

   - support for cygwin 64 bits with asm
@@ -153,15 +142,12 @@ Version 15.07 beta

   - From Windows version of 7-zip 15.06 beta:

-    - 7-Zip now can extract RAR5 archives.
     - 7-Zip now doesn't sort files by type while adding to solid 7z archive.
       new -mqs switch to sort files by type while adding to solid 7z archive.
     - The BUG in 7-Zip File Manager was fixed:
       The "Move" operation to open 7z archive didn't delete empty files.
     - The BUG in 15.05 was fixed:
       console version added some text to the end of stdout stream, is -so switch was used.
-    - The BUG in 9.30 - 15.05 was fixed:
-      7-Zip could not open multivolume sfx RAR archive.
     - Some bugs were fixed.

   - From Windows version of 7-zip 15.05 beta:
@@ -214,9 +200,6 @@ Version 9.38
   - bug #139 "password from commanline is visible in processes list"
       Now the characters of the password are replaced with *.

-  - From Windows version of 7-zip
-     - bug#138 If you extract the password with # program crashes
-       7z now supports long password in RAR 3 and 4.

@@ -247,12 +230,6 @@ Version 9.22
   - #3283518 : Asm/x{32,64}/7zCrcT8U.asm introduces executable stack

-Version 9.20.1
-==============
-
-  - #3211479 "p7zip 9.20 - "unsupported method" with RAR files - " fixed
-    "install.sh" installs again "bin/Codecs/Rar29.so"
-
 Version 9.20
 ============

@@ -325,8 +302,6 @@ Version 9.13
     - Some bugs were fixed.

-  - #2863580 "Crash in Rar decoder on a corrupted file" fixed
-
   - #2860898 "Dereferencing a zero pointer in cab handler" fixed

   - #2860679 "Division by zero in cab decoder" fixed
@@ -455,7 +430,7 @@ Version 4.59 (never published)
     - It's allowed to use -t switch for "list" and "extract" commands.
     - Some bugs were fixed.

-  - Bug : wrong timestamp for files extracted from .zip or .rar archives
+  - Bug : wrong timestamp for files extracted from .zip archives

 Version 4.58
@@ -468,8 +443,6 @@ Version 4.58
         2) -mcu switch:  7-Zip uses UTF-8, if there are non-ASCII symbols.
         3) -mcl switch:  7-Zip uses local code page.
     - Now it's possible to store file creation time in 7z and ZIP archives (-mtc switch).
-    - 7-Zip now can unpack multivolume RAR archives created with
-      "old style volume names" scheme and names *.001, *.002, ...
     - Now it's possible to use -mSW- and -mSW+ switches instead of -mSW=off and -mSW=on
     - Some bugs were fixed.

@@ -685,7 +658,7 @@ Version 4.44

   - From Windows version of 7-zip 4.44 :
     - 7za : Cab support
-    - Speed optimizations for LZMA, Deflate, BZip2 and unRAR.
+    - Speed optimizations for LZMA, Deflate and BZip2.
     - fix : now, updating a crypted header archive keeps the crypted header

   - fixes in the help displayed by 7za/7z/7zr.
@@ -805,8 +778,6 @@ Version 4.38

   - patch #1465026 - Patch for install.sh for packagers

-  - DosDateTimeToFileTime fixed (rar format)
-
   - contrib/VirtualFileSystemForMidnightCommander/u7z updated
     (thank sgh_punk)

@@ -923,8 +894,6 @@ Version 4.25
     - Some bugs were fixed
     - DOCS/MANUAL/exit_codes.htm added

-  - new plugin for 7z : RAR format support (extracting only)
-
   - better dependencies in makefile

 Version 4.23
@@ -1112,9 +1081,6 @@ Version 4.10
   - new port of 7za from the source of 7za 4.10Beta for Windows
     => p7zip now work on big endian CPU.

-  - 7z for Unix is not maintain anymore (because as the source of unrar plugin for 7z
-    is not available, 7z is unless on Unix).
-
 Version 0.91
 ============
   - add support for FreeBSD 5.2.1
diff --git a/DOC/License.txt b/DOC/License.txt
index 0bcbe26..5b0dfaa 100644
--- a/DOC/License.txt
+++ b/DOC/License.txt
@@ -5,15 +5,6 @@

   7-Zip Copyright (C) 1999-2016 Igor Pavlov.

-  Licenses for files are:
-
-    1) CPP/7zip/Compress/Rar* files:  GNU LGPL + unRAR restriction
-    2) All other files:  GNU LGPL
-
-  The GNU LGPL + unRAR restriction means that you must follow both
-  GNU LGPL rules and unRAR restriction rules.
-
-
   GNU LGPL information
   --------------------

@@ -33,21 +24,5 @@
     USA

-  unRAR restriction
-  -----------------
-
-    The decompression engine for RAR archives was developed using source
-    code of unRAR program.
-    All copyrights to original unRAR code are owned by Alexander Roshal.
-
-    The license for original unRAR code has the following restriction:
-
-    The unRAR sources cannot be used to re-create the RAR compression algorithm,
-    which is proprietary. Distribution of modified unRAR sources in separate form
-    or as a part of other software is permitted, provided that it is clearly
-    stated in the documentation and source comments that the code may
-    not be used to develop a RAR (WinRAR) compatible archiver.
-
-
   --
   Igor Pavlov
diff --git a/DOC/MANUAL/cmdline/switches/update.htm b/DOC/MANUAL/cmdline/switches/update.htm
index 27385b1..0190fc1 100644
--- a/DOC/MANUAL/cmdline/switches/update.htm
+++ b/DOC/MANUAL/cmdline/switches/update.htm
@@ -139,7 +139,7 @@ someone in another time zone.</P>
 <LI>UTC file systems: NTFS
 <LI>UTC archive formats: .zip with -mtc switch, 7z, tar, gzip2, iso, wim
 <LI>Local time file systems : FAT, FAT32
-<LI>Local time archive formats : rar, zip, cab
+<LI>Local time archive formats : zip, cab
 </UL>

 <H4>Examples</H4>
diff --git a/DOC/MANUAL/general/formats.htm b/DOC/MANUAL/general/formats.htm
index 7996c5c..cd01bd6 100644
--- a/DOC/MANUAL/general/formats.htm
+++ b/DOC/MANUAL/general/formats.htm
@@ -47,7 +47,6 @@
   <TR> <TD align="center">NSIS</TD> <TD></TD> <TD>nsis</TD> </TR>
   <TR> <TD align="center">NTFS</TD> <TD></TD> <TD>ntfs img</TD> </TR>
   <TR> <TD align="center">MBR</TD> <TD></TD> <TD>mbr</TD> </TR>
-  <TR> <TD align="center">RAR</TD> <TD></TD> <TD>rar r00</TD> </TR>
   <TR> <TD align="center">RPM</TD>  <TD></TD> <TD>rpm</TD></TR>
   <TR> <TD align="center">PPMD</TD> <TD></TD> <TD>ppmd</TD> </TR>
   <TR> <TD align="center">QCOW2</TD> <TD></TD> <TD>qcow qcow2 qcow2c</TD> </TR>
diff --git a/DOC/Methods.txt b/DOC/Methods.txt
index 1a1c54c..daa94e2 100644
--- a/DOC/Methods.txt
+++ b/DOC/Methods.txt
@@ -97,12 +97,6 @@ List of defined IDs
    02 -
       02 - BZip2

-   03 - [Rar]
-      01 - Rar1
-      02 - Rar2
-      03 - Rar3
-      05 - Rar5
-
    04 - [Arj]
       01 - Arj(1,2,3)
       02 - Arj4
@@ -146,10 +140,6 @@ List of defined IDs
       01 - [Zip]
          01 - ZipCrypto (Main Zip crypto algo)

-      03 - [RAR]
-         02 -
-         03 - Rar29AES (AES-128 + modified SHA-1)
-
       07 - [7z]
          01 - 7zAES (AES-256 + SHA-256)

diff --git a/DOC/readme.txt b/DOC/readme.txt
index 4a6998c..00591d4 100644
--- a/DOC/readme.txt
+++ b/DOC/readme.txt
@@ -9,30 +9,9 @@
 License Info
 ------------

-7-Zip is free software distributed under the GNU LGPL
-(except for unRar code).
+7-Zip is free software distributed under the GNU LGPL.
 read License.txt for more infomation about license.

-Notes about unRAR license:
-
-Please check main restriction from unRar license:
-
-   2. The unRAR sources may be used in any software to handle RAR
-      archives without limitations free of charge, but cannot be used
-      to re-create the RAR compression algorithm, which is proprietary.
-      Distribution of modified unRAR sources in separate form or as a
-      part of other software is permitted, provided that it is clearly
-      stated in the documentation and source comments that the code may
-      not be used to develop a RAR (WinRAR) compatible archiver.
-
-In brief it means:
-1) You can compile and use compiled files under GNU LGPL rules, since
-   unRAR license almost has no restrictions for compiled files.
-   You can link these compiled files to LGPL programs.
-2) You can fix bugs in source code and use compiled fixed version.
-3) You can not use unRAR sources to re-create the RAR compression algorithm.
-
-
 LZMA SDK
 --------

@@ -96,7 +75,6 @@ DOC                Documentation
 ---
   7zFormat.txt   - 7z format description
   copying.txt    - GNU LGPL license
-  unRarLicense.txt - License for unRAR part of source code
   src-history.txt  - Sources history
   Methods.txt    - Compression method IDs
   readme.txt     - Readme file
diff --git a/DOC/src-history.txt b/DOC/src-history.txt
index 6b48c80..dda8057 100644
--- a/DOC/src-history.txt
+++ b/DOC/src-history.txt
@@ -188,8 +188,6 @@ HISTORY of the 7-Zip source code
 - 7-Zip now has 128 MB dictionary limit for 32-bit version:
   It's for speed optimization: kNumLogBits = 9 + sizeof(size_t) / 2;
 - TAR: 'D' link flag support.
-- 7-Zip now can unpack multivolume RAR archives created with
-  "old style volume names" scheme (-vn switch) and names *.001, *.002, ...
 - Fixed bugs:
   - 7-Zip FM could not copy / move files to root network folders like \\COMPNAME\FOLDERNAME\
     In case of move it removed original files.
@@ -200,8 +198,6 @@ HISTORY of the 7-Zip source code
       7-zip tries to delete all extra fileds (except for WzAES).
       And that code could hang.
   -  7-Zip GUI didn't suggest BZip2 dictionary size used in previous run.
-  -  If creation time stamp was included in .RAR archive, 7-zip used creation time stamp
-     as modification time stamp.

 4.58 alpha 2   2007-12-31
 -------------------------
@@ -251,7 +247,6 @@ HISTORY of the 7-Zip source code
   stratup code, or you must add CPP/Common/CRC.cpp to your project.
 - Method ID in .7z now is 63-bit integer (UInt64).
 - Open error messages
-- unRar 1.5 fixed
 - unShrink fixed
 - BUG of 4.43 beta and 4.44 beta was fixed.
   7-Zip compressing to .zip in multi-threading mode didn't work in some cases.
@@ -433,11 +428,6 @@ HISTORY of the 7-Zip source code
     contains common resurces

-2.30 Beta 19   2002-04-11
--------------------------
-- SDK/Archive/Rar/Handler.cpp
-    supporting RAR29
-
 2.30 Beta 18   2002-03-25
 -------------------------
 - SDK/Archive/Cab/MSZipDecoder.cpp
diff --git a/GUI/Contents/Info.plist b/GUI/Contents/Info.plist
index 71650e1..d60b262 100644
--- a/GUI/Contents/Info.plist
+++ b/GUI/Contents/Info.plist
@@ -311,24 +311,6 @@
 		<dict>
 			<key>CFBundleTypeExtensions</key>
 			<array>
-				<string>rar</string>
-				<string>RAR</string>
-				<string>.r00</string>
-			</array>
-			<key>CFBundleTypeIconFile</key>
-			<string>p7zip</string>
-			<key>CFBundleTypeName</key>
-			<string>Rar</string>
-			<key>CFBundleTypeRole</key>
-			<string>Viewer</string>
-			<key>LSTypeIsPackage</key>
-			<false/>
-			<key>NSPersistentStoreTypeKey</key>
-			<string>XML</string>
-		</dict>
-		<dict>
-			<key>CFBundleTypeExtensions</key>
-			<array>
 				<string>ace</string>
 				<string>ACE</string>
 				<string>.c00</string>
diff --git a/README b/README
index b76407f..c03917b 100644
--- a/README
+++ b/README
@@ -8,7 +8,7 @@ p7zip is a port of the Windows programs 7z.exe and 7za.exe provided by 7-zip.
 7-zip is a file archiver with the highest compression ratio.
 Homepage : www.7-zip.org

-  7z uses plugins (7z.so and Codecs/Rar.so) to handle archives.
+  7z uses plugins (7z.so) to handle archives.
   7za is a stand-alone executable (7za handles less archive formats than 7z).
   7zr is a light stand-alone executable that supports only 7z/LZMA/BCJ/BCJ2.

@@ -63,7 +63,6 @@ BUILD :
     make sfx      : to build bin/7zCon.sfx (7za can now create SFX archive)
     make 7z       : to build bin/7z and its plugins :
                           - "bin/7z.so" (GNU LGPL + AES code license)
-                          - "bin/Codecs/Rar.so" (GNU LGPL + unRAR restriction)
     make 7zr      : to build bin/7zr
     make all      : to build bin/7za and bin/7zCon.sfx
     make all2     : to build bin/7za, bin/7z (with its plugins) and bin/7zCon.sfx
@@ -74,7 +73,6 @@ BUILD :

     make 7zG      : to build bin/7zG and its plugins :
                           - "bin/7z.so" (GNU LGPL + AES code license)
-                          - "bin/Codecs/Rar.so" (GNU LGPL + unRAR restriction)
     make test_7zG : to test bin/7zG (extracting, archiving, ...)

diff --git a/Utils/bin_to_sources.py b/Utils/bin_to_sources.py
index 1be72ec..7da359a 100644
--- a/Utils/bin_to_sources.py
+++ b/Utils/bin_to_sources.py
@@ -13,9 +13,6 @@ file0='Utils/file_7zCon_sfx.py'
 dir0='CPP/7zip/UI/Console'
 file0='Utils/file_7z.py'

-dir0='CPP/7zip/Compress/Rar'
-file0='Utils/file_Codecs_Rar_so.py'
-
 dir0='CPP/7zip/Bundles/Format7zFree'
 file0='Utils/file_7z_so.py'

diff --git a/Utils/file_7z_so.py b/Utils/file_7z_so.py
index 7ca9fff..43edb87 100644
--- a/Utils/file_7z_so.py
+++ b/Utils/file_7z_so.py
@@ -111,8 +111,6 @@ files_cpp=[
  'CPP/7zip/Archive/PeHandler.cpp',
  'CPP/7zip/Archive/PpmdHandler.cpp',
  'CPP/7zip/Archive/QcowHandler.cpp',
- 'CPP/7zip/Archive/Rar/RarHandler.cpp',
- 'CPP/7zip/Archive/Rar/Rar5Handler.cpp',
  'CPP/7zip/Archive/RpmHandler.cpp',
  'CPP/7zip/Archive/SplitHandler.cpp',
  'CPP/7zip/Archive/SquashfsHandler.cpp',
@@ -215,9 +213,6 @@ files_cpp=[
  'CPP/7zip/Crypto/MyAesReg.cpp',
  'CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp',
  'CPP/7zip/Crypto/RandGen.cpp',
- 'CPP/7zip/Crypto/Rar20Crypto.cpp',
- 'CPP/7zip/Crypto/Rar5Aes.cpp',
- 'CPP/7zip/Crypto/RarAes.cpp',
  'CPP/7zip/Crypto/WzAes.cpp',
  'CPP/7zip/Crypto/ZipCrypto.cpp',
  'CPP/7zip/Crypto/ZipStrong.cpp',
diff --git a/Utils/generate.py b/Utils/generate.py
index 132024a..62c0456 100755
--- a/Utils/generate.py
+++ b/Utils/generate.py
@@ -281,7 +281,6 @@ import file_7zr
 import file_7zG
 import file_7zFM
 import file_7z_so
-import file_Codecs_Rar_so
 import file_Codecs_Lzham_so
 import file_LzmaCon
 import file_Client7z
@@ -440,43 +439,6 @@ LOCAL_CFLAGS := -DANDROID_NDK  -fexceptions \
 -I../../../include_windows
 ''')

-project_Codecs_Rar=Structure(name="Rar",name2="Rar",
-	type=TYPE_DLL,
-	need_AES=False,
-	includedirs=includedirs_7za,
-	defines=[ "EXTERNAL_CODECS", "_FILE_OFFSET_BITS=64", "_LARGEFILE_SOURCE", "_REENTRANT", "ENV_UNIX", "BREAK_HANDLER", "UNICODE", "_UNICODE", "UNIX_USE_WIN_FILE" ],
-	files_c=file_Codecs_Rar_so.files_c,
-	files_cpp=file_Codecs_Rar_so.files_cpp,
-	cmake_end='''
-
-find_library(DL_LIB dl)
-
-link_directories(${DL_LIB_PATH})
-
-IF(APPLE)
-   TARGET_LINK_LIBRARIES(Rar ${COREFOUNDATION_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
-ELSE(APPLE)
-  IF(HAVE_PTHREADS)
-   TARGET_LINK_LIBRARIES(Rar ${CMAKE_THREAD_LIBS_INIT} dl)
-  ENDIF(HAVE_PTHREADS)
-ENDIF(APPLE)
-
-''',
-android_header=r'''
-LOCAL_CFLAGS := -DANDROID_NDK  -fexceptions \
-	-DNDEBUG -D_REENTRANT -DENV_UNIX \
-	-DEXTERNAL_CODECS \
-	-DBREAK_HANDLER \
-	-DUNICODE -D_UNICODE -DUNIX_USE_WIN_FILE \
-	-I../../../Windows \
-	-I../../../Common \
-	-I../../../../C \
--I../../../myWindows \
--I../../../ \
--I../../../include_windows
-''')
-
-

 project_Codecs_Lzham=Structure(name="Lzham",name2="Lzham",
 	type=TYPE_DLL,
@@ -762,7 +724,6 @@ generate_makefile_list('../CPP/7zip/Bundles/Alone/makefile.list',project_7za)
 generate_makefile_list('../CPP/7zip/Bundles/Alone7z/makefile.list',project_7zr)
 generate_makefile_list('../CPP/7zip/UI/Console/makefile.list',project_7z)
 generate_makefile_list('../CPP/7zip/Bundles/Format7zFree/makefile.list',project_Format7zFree)
-generate_makefile_list('../CPP/7zip/Compress/Rar/makefile.list',project_Codecs_Rar,'../../../../bin/Codecs')
 generate_makefile_list('../CPP/7zip/Compress/Lzham/makefile.list',project_Codecs_Lzham,'../../../../bin/Codecs')
 generate_makefile_list('../CPP/7zip/Bundles/SFXCon/makefile.list',project_7zCon_sfx)
 generate_makefile_list('../CPP/7zip/UI/GUI/makefile.list',project_7zG)
@@ -776,7 +737,6 @@ generate_pro('../CPP/7zip/QMAKE/7za/7za.pro',project_7za)
 generate_pro('../CPP/7zip/QMAKE/7zr/7zr.pro',project_7zr)
 generate_pro('../CPP/7zip/QMAKE/7z_/7z_.pro',project_7z)
 generate_pro('../CPP/7zip/QMAKE/Format7zFree/Format7zFree.pro',project_Format7zFree)
-generate_pro('../CPP/7zip/QMAKE/Rar/Rar.pro',project_Codecs_Rar)
 generate_pro('../CPP/7zip/QMAKE/Lzham/Lzham.pro',project_Codecs_Lzham)

 generate_premake4('../CPP/7zip/PREMAKE/premake4.lua',project_7za)
diff --git a/contrib/qnx630sp3/qnx630sp3-shared b/contrib/qnx630sp3/qnx630sp3-shared
index 6f5481f..ea07114 100644
--- a/contrib/qnx630sp3/qnx630sp3-shared
+++ b/contrib/qnx630sp3/qnx630sp3-shared
@@ -8,7 +8,7 @@ mv ./bin/7z ../${BIN} && mv ./bin/7za ../${BIN} && mv ./bin/7zr ../${BIN} && mv
 make clean && \
 cp makefile.qnx_shared.so makefile.machine && \
 make 7z && \
-mv ./bin/7z.so ../${BIN} && mv ./bin/Codecs/Rar.so ../${BIN}/Codecs && \
+mv ./bin/7z.so ../${BIN} && \
 make clean && \
 mv makefile.machine.bak makefile.machine
 echo "All done - look for binaries in ../${BIN}"
diff --git a/makefile b/makefile
index 745c8ed..f8e8e33 100644
--- a/makefile
+++ b/makefile
@@ -31,7 +31,6 @@ depend:
 	$(MAKE) -C CPP/7zip/UI/Client7z           depend
 	$(MAKE) -C CPP/7zip/UI/Console            depend
 	$(MAKE) -C CPP/7zip/Bundles/Format7zFree  depend
-	$(MAKE) -C CPP/7zip/Compress/Rar          depend
 	$(MAKE) -C CPP/7zip/UI/GUI                depend
 	$(MAKE) -C CPP/7zip/UI/FileManager        depend

@@ -42,7 +41,6 @@ sfx: common
 common7z:common
 	$(MKDIR) bin/Codecs
 	$(MAKE) -C CPP/7zip/Bundles/Format7zFree all
-	$(MAKE) -C CPP/7zip/Compress/Rar         all

 lzham:common
 	$(MKDIR) bin/Codecs
@@ -67,7 +65,6 @@ clean_C:
 	$(MAKE) -C CPP/7zip/UI/FileManager       clean
 	$(MAKE) -C CPP/7zip/UI/GUI               clean
 	$(MAKE) -C CPP/7zip/Bundles/Format7zFree clean
-	$(MAKE) -C CPP/7zip/Compress/Rar         clean
 	$(MAKE) -C CPP/7zip/Compress/Lzham       clean
 	$(MAKE) -C CPP/7zip/Bundles/LzmaCon      clean2
 	$(MAKE) -C CPP/7zip/Bundles/AloneGCOV    clean
diff --git a/makefile.oldmake b/makefile.oldmake
index afc681c..690af08 100644
--- a/makefile.oldmake
+++ b/makefile.oldmake
@@ -31,7 +31,6 @@ depend:
 	cd CPP/7zip/UI/Client7z           ; $(MAKE) depend
 	cd CPP/7zip/UI/Console            ; $(MAKE) depend
 	cd CPP/7zip/Bundles/Format7zFree  ; $(MAKE) depend
-	cd CPP/7zip/Compress/Rar          ; $(MAKE) depend
 	cd CPP/7zip/UI/GUI                ; $(MAKE) depend
 	cd CPP/7zip/UI/FileManager        ; $(MAKE) depend

@@ -42,7 +41,6 @@ sfx: common
 common7z:common
 	$(MKDIR) bin/Codecs
 	cd CPP/7zip/Bundles/Format7zFree ; $(MAKE) all
-	cd CPP/7zip/Compress/Rar         ; $(MAKE) all

 lzham:common
 	$(MKDIR) bin/Codecs
@@ -67,7 +65,6 @@ clean_C:
 	cd CPP/7zip/UI/FileManager       ; $(MAKE) clean
 	cd CPP/7zip/UI/GUI               ; $(MAKE) clean
 	cd CPP/7zip/Bundles/Format7zFree ; $(MAKE) clean
-	cd CPP/7zip/Compress/Rar         ; $(MAKE) clean
 	cd CPP/7zip/Compress/Lzham       ; $(MAKE) clean
 	cd CPP/7zip/Bundles/LzmaCon      ; $(MAKE) clean2
 	cd CPP/7zip/Bundles/AloneGCOV    ; $(MAKE) clean
diff --git a/makefile.qnx_shared.so b/makefile.qnx_shared.so
index abd1caf..cff5485 100644
--- a/makefile.qnx_shared.so
+++ b/makefile.qnx_shared.so
@@ -1,5 +1,5 @@
 ###################################################
-# makefile.machine for "7z.so , Codecs/Rar.so" :
+# makefile.machine for "7z.so" :
 # tested with p7zip-4.47_beta on qnx-6.3.0 sp3 x86 target

 OPTFLAGS=-O -s


code:
See <http://lists.gnu.org/archive/html/bug-patch/2015-06/msg00009.html>

From 0507dfad5f060161f01840067e1bb1615257b636 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Mon, 8 Jun 2015 17:27:56 +0200
Subject: [PATCH] Do not rely on PATH_MAX when reading a symlink target.

* src/util.c (move_file, copy_file): Use 'fromst->st_size + 1' and
'tost->st_size + 1' for the allocation, and 'fromst->st_size' and
'tost->st_size' instead of PATH_MAX.  Fixes compilation on GNU/Hurd.
---
 src/util.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/util.c b/src/util.c
index 1cc08ba..67dbd3a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -460,12 +460,12 @@ move_file (char const *from, bool *from_needs_removal,

 	  /* FROM contains the contents of the symlink we have patched; need
 	     to convert that back into a symlink. */
-	  char *buffer = xmalloc (PATH_MAX);
+	  char *buffer = xmalloc (fromst->st_size + 1);
 	  int fd, size = 0, i;

 	  if ((fd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0)
 	    pfatal ("Can't reopen file %s", quotearg (from));
-	  while ((i = read (fd, buffer + size, PATH_MAX - size)) > 0)
+	  while ((i = read (fd, buffer + size, fromst->st_size - size)) > 0)
 	    size += i;
 	  if (i != 0 || close (fd) != 0)
 	    read_fatal ();
@@ -610,10 +610,10 @@ copy_file (char const *from, char const *to, struct stat *tost,

   if (S_ISLNK (mode))
     {
-      char *buffer = xmalloc (PATH_MAX + 1);
+      char *buffer = xmalloc (tost->st_size + 1);
       ssize_t r;

-      if ((r = safe_readlink (from, buffer, PATH_MAX)) < 0)
+      if ((r = safe_readlink (from, buffer, tost->st_size)) < 0)
 	pfatal ("Can't read %s %s", "symbolic link", from);
       buffer[r] = '\0';
       if (safe_symlink (buffer, to) != 0)
--
2.16.2


code:
Improve the determination of pageSize in patchelf.cc.

Patch by Mark H Weaver <mhw@netris.org>.

--- patchelf/src/patchelf.cc.orig	1969-12-31 19:00:01.000000000 -0500
+++ patchelf/src/patchelf.cc	2014-02-16 20:15:06.283203125 -0500
@@ -21,11 +21,19 @@
 using namespace std;

-#ifdef MIPSEL
-/* The lemote fuloong 2f kernel defconfig sets a page size of 16KB */
-const unsigned int pageSize = 4096*4;
-#else
+/* Note that some platforms support multiple page sizes.  Therefore,
+   it is not enough to query the current page size.  'pageSize' must
+   be the maximum architectural page size for the platform, which is
+   typically defined in the corresponding ABI document.
+
+   XXX FIXME: This won't work when we're cross-compiling.  */
+
+#if defined __MIPSEL__ || defined __MIPSEB__ || defined __aarch64__
+const unsigned int pageSize = 65536;
+#elif defined __x86_64__ || defined __i386__ || defined __arm__
 const unsigned int pageSize = 4096;
+#else
+# error maximum architectural page size unknown for this platform
 #endif

--- patchelf/tests/no-rpath.sh.orig	2014-01-14 08:17:47.000000000 -0500
+++ patchelf/tests/no-rpath.sh	2015-01-06 18:31:53.418172797 -0500
@@ -1,23 +1,23 @@
 #! /bin/sh -e
 SCRATCH=scratch/$(basename $0 .sh)

-rm -rf ${SCRATCH}
-mkdir -p ${SCRATCH}
+if [ "$(uname -m)" = i686 -a "$(uname -s)" = Linux ]; then
+    rm -rf ${SCRATCH}
+    mkdir -p ${SCRATCH}

-cp ${srcdir}/no-rpath ${SCRATCH}/
+    cp ${srcdir}/no-rpath ${SCRATCH}/

-oldRPath=$(../src/patchelf --print-rpath ${SCRATCH}/no-rpath)
-if test -n "$oldRPath"; then exit 1; fi
-../src/patchelf \
-  --set-interpreter "$(../src/patchelf --print-interpreter ../src/patchelf)" \
-  --set-rpath /foo:/bar:/xxxxxxxxxxxxxxx ${SCRATCH}/no-rpath
+    oldRPath=$(../src/patchelf --print-rpath ${SCRATCH}/no-rpath)
+    if test -n "$oldRPath"; then exit 1; fi
+    ../src/patchelf \
+      --set-interpreter "$(../src/patchelf --print-interpreter ../src/patchelf)" \
+      --set-rpath /foo:/bar:/xxxxxxxxxxxxxxx ${SCRATCH}/no-rpath

-newRPath=$(../src/patchelf --print-rpath ${SCRATCH}/no-rpath)
-if ! echo "$newRPath" | grep -q '/foo:/bar'; then
-    echo "incomplete RPATH"
-    exit 1
-fi
+    newRPath=$(../src/patchelf --print-rpath ${SCRATCH}/no-rpath)
+    if ! echo "$newRPath" | grep -q '/foo:/bar'; then
+        echo "incomplete RPATH"
+        exit 1
+    fi

-if [ "$(uname -m)" = i686 -a "$(uname -s)" = Linux ]; then
     cd ${SCRATCH} && ./no-rpath
 fi


code:
Rework the growing algorithm in patchelf to support ARM systems.
See <https://github.com/NixOS/patchelf/issues/8>.
This patch copied from:
<https://github.com/sriemer/patchelf/commit/0a96239cea6b97b9a0fff80da576e58ca2dfb2a2>

From 0a96239cea6b97b9a0fff80da576e58ca2dfb2a2 Mon Sep 17 00:00:00 2001
From: Sebastian Parschauer <s.parschauer@gmx.de>
Date: Sat, 28 Jun 2014 01:24:57 +0200
Subject: [PATCH] Rework the growing algorithm

On ARM systems there is no space in virtual memory for another LOAD
area in front of the code LOAD area. So insert data to its end
instead. At this location there should be enough space in virtual
memory due to alignment. We can extend it until the end of the
alignment but the file shift may be greater as it must be aligned
to the page size. Do the same for the data LOAD area.
---
 src/patchelf.cc | 357 ++++++++++++++++++++++----------------------------------
 1 file changed, 142 insertions(+), 215 deletions(-)

diff --git a/src/patchelf.cc b/src/patchelf.cc
index dcbfd38..4fce9e6 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -116,7 +116,11 @@ private:

     void sortShdrs();

-    void shiftFile(unsigned int extraPages, Elf_Addr startPage);
+    void shiftFileSingle(size_t fileShift, Elf_Off insertOff);
+
+    void shiftFile(size_t neededCode, size_t neededData,
+                   Elf_Off codeOff[], Elf_Off dataOff[],
+                   Elf_Addr *codePage, Elf_Addr *dataPage);

     string getSectionName(const Elf_Shdr & shdr);

@@ -130,13 +134,11 @@ private:
         unsigned int size);

     void writeReplacedSections(Elf_Off & curOff,
-        Elf_Addr startAddr, Elf_Off startOffset);
+        Elf_Addr startAddr, Elf_Off startOffset, bool isData);

     void rewriteHeaders(Elf_Addr phdrAddress);

-    void rewriteSectionsLibrary();
-
-    void rewriteSectionsExecutable();
+    void rewriteSectionsBinary();

 public:

@@ -391,46 +393,119 @@ static unsigned int roundUp(unsigned int n, unsigned int m)

 template<ElfFileParams>
-void ElfFile<ElfFileParamNames>::shiftFile(unsigned int extraPages, Elf_Addr startPage)
+void ElfFile<ElfFileParamNames>::shiftFileSingle(size_t fileShift,
+        Elf_Off insertOff)
 {
-    /* Move the entire contents of the file `extraPages' pages
-       further. */
     unsigned int oldSize = fileSize;
-    unsigned int shift = extraPages * pageSize;
-    growFile(fileSize + extraPages * pageSize);
-    memmove(contents + extraPages * pageSize, contents, oldSize);
-    memset(contents + sizeof(Elf_Ehdr), 0, shift - sizeof(Elf_Ehdr));
+
+    /* Grow at the end */
+    growFile(fileSize + fileShift);
+
+    /* move the data from the insertion point
+       to the end and zero inserted space */
+    memmove(contents + insertOff + fileShift,
+            contents + insertOff, oldSize - insertOff);
+    memset(contents + insertOff, 0, fileShift);

     /* Adjust the ELF header. */
     wri(hdr->e_phoff, sizeof(Elf_Ehdr));
-    wri(hdr->e_shoff, rdi(hdr->e_shoff) + shift);
+    if (rdi(hdr->e_shoff) >= insertOff)
+        wri(hdr->e_shoff, rdi(hdr->e_shoff) + fileShift);

     /* Update the offsets in the section headers. */
-    for (int i = 1; i < rdi(hdr->e_shnum); ++i)
-        wri(shdrs[i].sh_offset, rdi(shdrs[i].sh_offset) + shift);
+    for (int i = 1; i < rdi(hdr->e_shnum); ++i) {
+        if (rdi(shdrs[i].sh_offset) >= insertOff)
+            wri(shdrs[i].sh_offset, rdi(shdrs[i].sh_offset) + fileShift);
+    }

     /* Update the offsets in the program headers. */
     for (int i = 0; i < rdi(hdr->e_phnum); ++i) {
-        wri(phdrs[i].p_offset, rdi(phdrs[i].p_offset) + shift);
-        if (rdi(phdrs[i].p_align) != 0 &&
-            (rdi(phdrs[i].p_vaddr) - rdi(phdrs[i].p_offset)) % rdi(phdrs[i].p_align) != 0) {
-            debug("changing alignment of program header %d from %d to %d\n", i,
-                rdi(phdrs[i].p_align), pageSize);
-            wri(phdrs[i].p_align, pageSize);
+        if (rdi(phdrs[i].p_offset) >= insertOff)
+            wri(phdrs[i].p_offset, rdi(phdrs[i].p_offset) + fileShift);
+        /* Check for ELF load command alignment issue the same
+           way as glibc/elf/dl-load.c does. This gives us the
+           chance to run an interpreter explicitly. */
+        if (rdi(phdrs[i].p_type) == PT_LOAD && ((rdi(phdrs[i].p_vaddr) -
+          rdi(phdrs[i].p_offset)) & (rdi(phdrs[i].p_align) - 1)) != 0) {
+             debug("changing alignment of program header %d from %d to %d\n",
+                   i, rdi(phdrs[i].p_align), pageSize);
+             wri(phdrs[i].p_align, pageSize);
         }
     }
+}
+
+template<ElfFileParams>
+void ElfFile<ElfFileParamNames>::shiftFile(size_t neededCode,
+        size_t neededData, Elf_Off codeOff[], Elf_Off dataOff[],
+        Elf_Addr *codePage, Elf_Addr *dataPage)
+{
+    /* Move some contents of the file further. The binary has one LOAD area
+     * for code and one for data. There is virtual memory space between
+     * these which we can use due to alignment.
+     */
+    unsigned int memShift = neededCode;
+    unsigned int fileShift = roundUp(neededCode, pageSize);
+    unsigned int maxMemShift = 0;
+
+    if (neededCode > 0) {
+        /* find the LOAD program header for code and extend it */
+        for (int i = 0; i < rdi(hdr->e_phnum); ++i) {
+            if (rdi(phdrs[i].p_type) == PT_LOAD &&
+              rdi(phdrs[i].p_flags) & PF_X) {
+                codeOff[1] = rdi(phdrs[i].p_filesz);
+                codeOff[0] = codeOff[1] + rdi(phdrs[i].p_offset);
+                maxMemShift = rdi(phdrs[i].p_memsz) % rdi(phdrs[i].p_align);
+                if (maxMemShift == 0)
+                    continue;
+                maxMemShift = rdi(phdrs[i].p_align) - maxMemShift;
+                if (maxMemShift == 0 || memShift > maxMemShift)
+                    continue;
+                *codePage = rdi(phdrs[i].p_vaddr);
+                wri(phdrs[i].p_filesz, rdi(phdrs[i].p_filesz) + memShift);
+                wri(phdrs[i].p_memsz, rdi(phdrs[i].p_memsz) + memShift);
+                break;
+            }
+        }
+        debug("codeOff: %#lx, memShift: %d, maxMemShift: %d, fileShift: %d\n",
+              codeOff[1], memShift, maxMemShift, fileShift);
+        if (codeOff[1] == 0 || maxMemShift == 0)
+            goto out;
+
+        shiftFileSingle(fileShift, codeOff[0]);
+    }
+
+    /* +++ Do the same for the data LOAD area  +++ */
+    memShift = neededData;
+    fileShift = roundUp(neededData, pageSize);
+    maxMemShift = 0;
+    if (neededData > 0) {
+        /* find the LOAD program header for data and extend it */
+        for (int i = 0; i < rdi(hdr->e_phnum); ++i) {
+            if (rdi(phdrs[i].p_type) == PT_LOAD &&
+              rdi(phdrs[i].p_flags) & PF_W) {
+                dataOff[1] = rdi(phdrs[i].p_filesz);
+                dataOff[0] = dataOff[1] + rdi(phdrs[i].p_offset);
+                maxMemShift = rdi(phdrs[i].p_memsz) % rdi(phdrs[i].p_align);
+                if (maxMemShift == 0)
+                    continue;
+                maxMemShift = rdi(phdrs[i].p_align) - maxMemShift;
+                if (maxMemShift == 0 || memShift > maxMemShift)
+                    continue;
+                *dataPage = rdi(phdrs[i].p_vaddr);
+                wri(phdrs[i].p_filesz, rdi(phdrs[i].p_filesz) + memShift);
+                wri(phdrs[i].p_memsz, rdi(phdrs[i].p_memsz) + memShift);
+                break;
+            }
+        }
+        debug("dataOff: %#lx, memShift: %d, maxMemShift: %d, fileShift: %d\n",
+              dataOff[1], memShift, maxMemShift, fileShift);
+        if (dataOff[1] == 0 || maxMemShift == 0)
+            goto out;

-    /* Add a segment that maps the new program/section headers and
-       PT_INTERP segment into memory.  Otherwise glibc will choke. */
-    phdrs.resize(rdi(hdr->e_phnum) + 1);
-    wri(hdr->e_phnum, rdi(hdr->e_phnum) + 1);
-    Elf_Phdr & phdr = phdrs[rdi(hdr->e_phnum) - 1];
-    wri(phdr.p_type, PT_LOAD);
-    wri(phdr.p_offset, 0);
-    wri(phdr.p_vaddr, wri(phdr.p_paddr, startPage));
-    wri(phdr.p_filesz, wri(phdr.p_memsz, shift));
-    wri(phdr.p_flags, PF_R | PF_W);
-    wri(phdr.p_align, pageSize);
+        shiftFileSingle(fileShift, dataOff[0]);
+    }
+out:
+    return;
 }

@@ -491,7 +566,7 @@ string & ElfFile<ElfFileParamNames>::replaceSection(const SectionName & sectionN

 template<ElfFileParams>
 void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
-    Elf_Addr startAddr, Elf_Off startOffset)
+    Elf_Addr startAddr, Elf_Off startOffset, bool isData = false)
 {
     /* Overwrite the old section contents with 'X's.  Do this
        *before* writing the new section contents (below) to prevent
@@ -501,6 +576,9 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
     {
         string sectionName = i->first;
         Elf_Shdr & shdr = findSection(sectionName);
+        if ((!isData && rdi(shdr.sh_flags) & SHF_WRITE) ||
+         (isData && ~(rdi(shdr.sh_flags)) & SHF_WRITE))
+            continue;
         memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size));
     }

@@ -509,6 +587,9 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
     {
         string sectionName = i->first;
         Elf_Shdr & shdr = findSection(sectionName);
+        if ((!isData && rdi(shdr.sh_flags) & SHF_WRITE) ||
+         (isData && ~(rdi(shdr.sh_flags)) & SHF_WRITE))
+            continue;
         debug("rewriting section `%s' from offset 0x%x (size %d) to offset 0x%x (size %d)\n",
             sectionName.c_str(), rdi(shdr.sh_offset), rdi(shdr.sh_size), curOff, i->second.size());

@@ -546,201 +627,47 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
         curOff += roundUp(i->second.size(), sectionAlignment);
     }

-    replacedSections.clear();
+    if (isData)
+        replacedSections.clear();
 }

 template<ElfFileParams>
-void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
+void ElfFile<ElfFileParamNames>::rewriteSectionsBinary()
 {
-    /* For dynamic libraries, we just place the replacement sections
-       at the end of the file.  They're mapped into memory by a
-       PT_LOAD segment located directly after the last virtual address
-       page of other segments. */
-    Elf_Addr startPage = 0;
-    for (unsigned int i = 0; i < phdrs.size(); ++i) {
-        Elf_Addr thisPage = roundUp(rdi(phdrs[i].p_vaddr) + rdi(phdrs[i].p_memsz), pageSize);
-        if (thisPage > startPage) startPage = thisPage;
-    }
-
-    debug("last page is 0x%llx\n", (unsigned long long) startPage);
+    Elf_Off codeOff[2] = {0}, dataOff[2] = {0};
+    Elf_Addr codePage = 0, dataPage = 0;
+    size_t neededCode = 0, neededData = 0, oldCode = 0, oldData = 0;
+    Elf_Shdr shdr = findSection(".text");
+    Elf_Addr firstPage = rdi(shdr.sh_addr) - rdi(shdr.sh_offset);

+    debug("first page is 0x%llx\n", (unsigned long long) firstPage);

-    /* Compute the total space needed for the replaced sections and
-       the program headers. */
-    off_t neededSpace = (phdrs.size() + 1) * sizeof(Elf_Phdr);
+    /* Compute the total space needed for the replaced sections */
     for (ReplacedSections::iterator i = replacedSections.begin();
-         i != replacedSections.end(); ++i)
-        neededSpace += roundUp(i->second.size(), sectionAlignment);
-    debug("needed space is %d\n", neededSpace);
-
-
-    size_t startOffset = roundUp(fileSize, pageSize);
-
-    growFile(startOffset + neededSpace);
-
-
-    /* Even though this file is of type ET_DYN, it could actually be
-       an executable.  For instance, Gold produces executables marked
-       ET_DYN.  In that case we can still hit the kernel bug that
-       necessitated rewriteSectionsExecutable().  However, such
-       executables also tend to start at virtual address 0, so
-       rewriteSectionsExecutable() won't work because it doesn't have
-       any virtual address space to grow downwards into.  As a
-       workaround, make sure that the virtual address of our new
-       PT_LOAD segment relative to the first PT_LOAD segment is equal
-       to its offset; otherwise we hit the kernel bug.  This may
-       require creating a hole in the executable.  The bigger the size
-       of the uninitialised data segment, the bigger the hole. */
-    if (isExecutable) {
-        if (startOffset >= startPage) {
-            debug("shifting new PT_LOAD segment by %d bytes to work around a Linux kernel bug\n", startOffset - startPage);
-        } else {
-            size_t hole = startPage - startOffset;
-            /* Print a warning, because the hole could be very big. */
-            fprintf(stderr, "warning: working around a Linux kernel bug by creating a hole of %zu bytes in ‘%s’\n", hole, fileName.c_str());
-            assert(hole % pageSize == 0);
-            /* !!! We could create an actual hole in the file here,
-               but it's probably not worth the effort. */
-            growFile(fileSize + hole);
-            startOffset += hole;
-        }
-        startPage = startOffset;
-    }
-
-
-    /* Add a segment that maps the replaced sections and program
-       headers into memory. */
-    phdrs.resize(rdi(hdr->e_phnum) + 1);
-    wri(hdr->e_phnum, rdi(hdr->e_phnum) + 1);
-    Elf_Phdr & phdr = phdrs[rdi(hdr->e_phnum) - 1];
-    wri(phdr.p_type, PT_LOAD);
-    wri(phdr.p_offset, startOffset);
-    wri(phdr.p_vaddr, wri(phdr.p_paddr, startPage));
-    wri(phdr.p_filesz, wri(phdr.p_memsz, neededSpace));
-    wri(phdr.p_flags, PF_R | PF_W);
-    wri(phdr.p_align, pageSize);
-
-
-    /* Write out the replaced sections. */
-    Elf_Off curOff = startOffset + phdrs.size() * sizeof(Elf_Phdr);
-    writeReplacedSections(curOff, startPage, startOffset);
-    assert((off_t) curOff == startOffset + neededSpace);
-
-
-    /* Move the program header to the start of the new area. */
-    wri(hdr->e_phoff, startOffset);
-
-    rewriteHeaders(startPage);
-}
-
-
-template<ElfFileParams>
-void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()
-{
-    /* Sort the sections by offset, otherwise we won't correctly find
-       all the sections before the last replaced section. */
-    sortShdrs();
-
-
-    /* What is the index of the last replaced section? */
-    unsigned int lastReplaced = 0;
-    for (unsigned int i = 1; i < rdi(hdr->e_shnum); ++i) {
-        string sectionName = getSectionName(shdrs[i]);
-        if (replacedSections.find(sectionName) != replacedSections.end()) {
-            debug("using replaced section `%s'\n", sectionName.c_str());
-            lastReplaced = i;
-        }
-    }
-
-    assert(lastReplaced != 0);
-
-    debug("last replaced is %d\n", lastReplaced);
-
-    /* Try to replace all sections before that, as far as possible.
-       Stop when we reach an irreplacable section (such as one of type
-       SHT_PROGBITS).  These cannot be moved in virtual address space
-       since that would invalidate absolute references to them. */
-    assert(lastReplaced + 1 < shdrs.size()); /* !!! I'm lazy. */
-    size_t startOffset = rdi(shdrs[lastReplaced + 1].sh_offset);
-    Elf_Addr startAddr = rdi(shdrs[lastReplaced + 1].sh_addr);
-    string prevSection;
-    for (unsigned int i = 1; i <= lastReplaced; ++i) {
-        Elf_Shdr & shdr(shdrs[i]);
-        string sectionName = getSectionName(shdr);
-        debug("looking at section `%s'\n", sectionName.c_str());
-        /* !!! Why do we stop after a .dynstr section? I can't
-           remember! */
-        if ((rdi(shdr.sh_type) == SHT_PROGBITS && sectionName != ".interp")
-            || prevSection == ".dynstr")
-        {
-            startOffset = rdi(shdr.sh_offset);
-            startAddr = rdi(shdr.sh_addr);
-            lastReplaced = i - 1;
-            break;
+         i != replacedSections.end(); ++i) {
+        shdr = findSection(i->first);
+        if (rdi(shdr.sh_flags) & SHF_WRITE) {
+            oldData += rdi(shdr.sh_size);
+            neededData += roundUp(i->second.size(), sectionAlignment);
         } else {
-            if (replacedSections.find(sectionName) == replacedSections.end()) {
-                debug("replacing section `%s' which is in the way\n", sectionName.c_str());
-                replaceSection(sectionName, rdi(shdr.sh_size));
-            }
+            oldCode += rdi(shdr.sh_size);
+            neededCode += roundUp(i->second.size(), sectionAlignment);
         }
-        prevSection = sectionName;
     }

-    debug("first reserved offset/addr is 0x%x/0x%llx\n",
-        startOffset, (unsigned long long) startAddr);
-
-    assert(startAddr % pageSize == startOffset % pageSize);
-    Elf_Addr firstPage = startAddr - startOffset;
-    debug("first page is 0x%llx\n", (unsigned long long) firstPage);
-
-    /* Right now we assume that the section headers are somewhere near
-       the end, which appears to be the case most of the time.
-       Therefore they're not accidentally overwritten by the replaced
-       sections. !!!  Fix this. */
-    assert((off_t) rdi(hdr->e_shoff) >= startOffset);
-
-
-    /* Compute the total space needed for the replaced sections, the
-       ELF header, and the program headers. */
-    size_t neededSpace = sizeof(Elf_Ehdr) + phdrs.size() * sizeof(Elf_Phdr);
-    for (ReplacedSections::iterator i = replacedSections.begin();
-         i != replacedSections.end(); ++i)
-        neededSpace += roundUp(i->second.size(), sectionAlignment);
-
-    debug("needed space is %d\n", neededSpace);
-
-    /* If we need more space at the start of the file, then grow the
-       file by the minimum number of pages and adjust internal
-       offsets. */
-    if (neededSpace > startOffset) {
-
-        /* We also need an additional program header, so adjust for that. */
-        neededSpace += sizeof(Elf_Phdr);
-        debug("needed space is %d\n", neededSpace);
-
-        unsigned int neededPages = roundUp(neededSpace - startOffset, pageSize) / pageSize;
-        debug("needed pages is %d\n", neededPages);
-        if (neededPages * pageSize > firstPage)
-            error("virtual address space underrun!");
-
-        firstPage -= neededPages * pageSize;
-        startOffset += neededPages * pageSize;
-
-        shiftFile(neededPages, firstPage);
-    }
-
-
-    /* Clear out the free space. */
-    Elf_Off curOff = sizeof(Elf_Ehdr) + phdrs.size() * sizeof(Elf_Phdr);
-    debug("clearing first %d bytes\n", startOffset - curOff);
-    memset(contents + curOff, 0, startOffset - curOff);
+    debug("needed space is C: %d, D: %d\n", neededCode, neededData);

+    /* If we need more space within the file, then grow the
+       file and adjust internal offsets. */
+    shiftFile(neededCode, neededData, codeOff, dataOff, &codePage,
+              &dataPage);
+    assert(codeOff[0] > 0);

     /* Write out the replaced sections. */
-    writeReplacedSections(curOff, firstPage, 0);
-    assert((off_t) curOff == neededSpace);
-
+    debug("codePage: %#lx, dataPage: %#lx\n", codePage, dataPage);
+    writeReplacedSections(codeOff[0], codePage + codeOff[1], codeOff[0]);
+    writeReplacedSections(dataOff[0], dataPage + dataOff[1], dataOff[0], true);

     rewriteHeaders(firstPage + rdi(hdr->e_phoff));
 }
@@ -758,10 +685,10 @@ void ElfFile<ElfFileParamNames>::rewriteSections()

     if (rdi(hdr->e_type) == ET_DYN) {
         debug("this is a dynamic library\n");
-        rewriteSectionsLibrary();
+        rewriteSectionsBinary();
     } else if (rdi(hdr->e_type) == ET_EXEC) {
         debug("this is an executable\n");
-        rewriteSectionsExecutable();
+        rewriteSectionsBinary();
     } else error("unknown ELF type");
 }

--
2.1.2


code:
The gendiff1 and gendiff2 tests need the gendiff script that's distributed
with the rpm package management tool.  Without that script, these tests are
expected to fail.

Need to mark one of the tests as PHONY to get permissions set correctly on
built scripts.

--- a/Makefile.in	2011-02-10 09:44:43.000000000 -0600
+++ b/Makefile.in	2014-03-06 17:27:55.610048953 -0600
@@ -378,6 +378,8 @@
 # These ones don't work yet.
 # Feel free to send me patches. :-)
 XFAIL_TESTS = \
+	tests/gendiff1/run-test \
+	tests/gendiff2/run-test \
 	tests/delhunk5/run-test \
 	tests/delhunk6/run-test

@@ -1106,6 +1108,7 @@
 	rm -f $(DESTDIR)$(bindir)/"`echo lsdiff|sed '$(transform)'`"
 	rm -f $(DESTDIR)$(bindir)/"`echo grepdiff|sed '$(transform)'`"

+.PHONY: tests/combine1/run-test
 tests/combine1/run-test: src/combinediff$(EXEEXT) src/flipdiff$(EXEEXT) \
 		src/lsdiff$(EXEEXT) src/grepdiff$(EXEEXT)
 	for script in $(bin_SCRIPTS); do \


code:
Work around this GCC ICE: <https://bugs.gnu.org/31708>.

--- linux-4.16.13/tools/perf/util/header.c	2018-06-04 11:30:39.368146035 +0200
+++ linux-4.16.13/tools/perf/util/header.c	2018-06-04 11:34:04.667212378 +0200
@@ -135,7 +135,7 @@ int do_write(struct feat_fd *ff, const v
 int write_padded(struct feat_fd *ff, const void *bf,
 		 size_t count, size_t count_aligned)
 {
-	static const char zero_buf[NAME_ALIGN];
+	static const char zero_buf[NAME_ALIGN] = { 0 };
 	int err = do_write(ff, bf, count);

 	if (!err)


code:
Fix CVE-2018-12015:

https://security-tracker.debian.org/tracker/CVE-2018-12015
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-12015
https://rt.cpan.org/Ticket/Display.html?id=125523

Patch taken from this upstream commit and adapted to apply to
the bundled copy in the Perl distribution:

https://github.com/jib/archive-tar-new/commit/ae65651eab053fc6dc4590dbb863a268215c1fc5

diff --git a/cpan/Archive-Tar/lib/Archive/Tar.pm b/cpan/Archive-Tar/lib/Archive/Tar.pm
index 6244369..a83975f 100644
--- a/cpan/Archive-Tar/lib/Archive/Tar.pm
+++ b/cpan/Archive-Tar/lib/Archive/Tar.pm
@@ -845,6 +845,20 @@ sub _extract_file {
         return;
     }

+    ### If a file system already contains a block device with the same name as
+    ### the being extracted regular file, we would write the file's content
+    ### to the block device. So remove the existing file (block device) now.
+    ### If an archive contains multiple same-named entries, the last one
+    ### should replace the previous ones. So remove the old file now.
+    ### If the old entry is a symlink to a file outside of the CWD, the new
+    ### entry would create a file there. This is CVE-2018-12015
+    ### <https://rt.cpan.org/Ticket/Display.html?id=125523>.
+    if (-l $full || -e _) {
+	if (!unlink $full) {
+	    $self->_error( qq[Could not remove old file '$full': $!] );
+	    return;
+	}
+    }
     if( length $entry->type && $entry->is_file ) {
         my $fh = IO::File->new;
         $fh->open( $full, '>' ) or (


code:
AutoSplit will fail to create an index for files whose modification time is 0
because its default time for a non-existent index is 1.  Set this default time
to -1 instead.

--- perl-5.16.1/cpan/AutoLoader/lib/AutoSplit.pm.orig	2012-02-14 22:44:36.000000000 -0600
+++ perl-5.16.1/cpan/AutoLoader/lib/AutoSplit.pm	2015-09-09 19:59:22.208708921 -0500
@@ -361,7 +361,7 @@
     my($al_idx_file) = catfile($autodir, $modpname, $IndexFile);

     if ($check_mod_time){
-	my($al_ts_time) = (stat("$al_idx_file"))[9] || 1;
+	my($al_ts_time) = (stat("$al_idx_file"))[9] || -1;
 	if ($al_ts_time >= $pm_mod_time and
 	    $al_ts_time >= $self_mod_time){
 	    print "AutoSplit skipped ($al_idx_file newer than $filename)\n"


code:
From <https://bugs.debian.org/801523>.

From c01f602d1926b0671fd2c8d91f7e52c4e4c9fb24 Mon Sep 17 00:00:00 2001
From: Niko Tyni <ntyni@debian.org>
Date: Sun, 11 Oct 2015 19:27:56 +0300
Subject: [PATCH] Sort the list of XS code files when generating RealPPPort.xs

all_files_in_dir() uses readdir() ordering to make the list of
input files. This can vary between build systems, breaking build
reproducibility.
---
 cpan/Devel-PPPort/PPPort_xs.PL | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpan/Devel-PPPort/PPPort_xs.PL b/cpan/Devel-PPPort/PPPort_xs.PL
index 5f18940..149f2fe 100644
--- a/cpan/Devel-PPPort/PPPort_xs.PL
+++ b/cpan/Devel-PPPort/PPPort_xs.PL
@@ -38,7 +38,7 @@ END
 my $file;
 my $sec;

-for $file (all_files_in_dir('parts/inc')) {
+for $file (sort(all_files_in_dir('parts/inc'))) {
   my $spec = parse_partspec($file);

   my $msg = 0;
--
2.5.1


code:
Fix CVE-2017-6512:

https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-6512
https://rt.cpan.org/Public/Bug/Display.html?id=121951

Patch copied from Debian, adapted to apply to the copy of File::Path in Perl
5.24.0.

https://github.com/jkeenan/File-Path/commit/e5ef95276ee8ad471c66ee574a5d42552b3a6af2
https://anonscm.debian.org/cgit/perl/perl.git/diff/debian/patches/fixes/file_path_chmod_race.diff?id=e7b50f8fb6413f8ddfbbfda2d531615fb029e2d3

From d760748be0efca7c05454440e24f3df77bf7cf5d Mon Sep 17 00:00:00 2001
From: John Lightsey <john@nixnuts.net>
Date: Tue, 2 May 2017 12:03:52 -0500
Subject: Prevent directory chmod race attack.

CVE-2017-6512 is a race condition attack where the chmod() of directories
that cannot be entered is misused to change the permissions on other
files or directories on the system. This has been corrected by limiting
the directory-permission loosening logic to systems where fchmod() is
supported.

[Backported (whitespace adjustments) to File-Path 2.12 / perl 5.24 by
Dominic Hargreaves for Debian.]

Bug: https://rt.cpan.org/Public/Bug/Display.html?id=121951
Bug-Debian: https://bugs.debian.org/863870
Patch-Name: fixes/file_path_chmod_race.diff
---
 cpan/File-Path/lib/File/Path.pm | 39 +++++++++++++++++++++++++--------------
 cpan/File-Path/t/Path.t         | 40 ++++++++++++++++++++++++++--------------
 2 files changed, 51 insertions(+), 28 deletions(-)

diff --git a/cpan/File-Path/lib/File/Path.pm b/cpan/File-Path/lib/File/Path.pm
index 034da1e..a824cc8 100644
--- a/cpan/File-Path/lib/File/Path.pm
+++ b/cpan/File-Path/lib/File/Path.pm
@@ -354,21 +354,32 @@ sub _rmtree {

                 # see if we can escalate privileges to get in
                 # (e.g. funny protection mask such as -w- instead of rwx)
-                $perm &= oct '7777';
-                my $nperm = $perm | oct '700';
-                if (
-                    !(
-                           $arg->{safe}
-                        or $nperm == $perm
-                        or chmod( $nperm, $root )
-                    )
-                  )
-                {
-                    _error( $arg,
-                        "cannot make child directory read-write-exec", $canon );
-                    next ROOT_DIR;
+                # This uses fchmod to avoid traversing outside of the proper
+                # location (CVE-2017-6512)
+                my $root_fh;
+                if (open($root_fh, '<', $root)) {
+                    my ($fh_dev, $fh_inode) = (stat $root_fh )[0,1];
+                    $perm &= oct '7777';
+                    my $nperm = $perm | oct '700';
+                    local $@;
+                    if (
+                        !(
+                            $arg->{safe}
+                           or $nperm == $perm
+                           or !-d _
+                           or $fh_dev ne $ldev
+                           or $fh_inode ne $lino
+                           or eval { chmod( $nperm, $root_fh ) }
+                        )
+                      )
+                    {
+                        _error( $arg,
+                            "cannot make child directory read-write-exec", $canon );
+                        next ROOT_DIR;
+                    }
+                    close $root_fh;
                 }
-                elsif ( !chdir($root) ) {
+                if ( !chdir($root) ) {
                     _error( $arg, "cannot chdir to child", $canon );
                     next ROOT_DIR;
                 }
diff --git a/cpan/File-Path/t/Path.t b/cpan/File-Path/t/Path.t
index ff52fd6..956ca09 100644
--- a/cpan/File-Path/t/Path.t
+++ b/cpan/File-Path/t/Path.t
@@ -3,7 +3,7 @@

 use strict;

-use Test::More tests => 127;
+use Test::More tests => 126;
 use Config;
 use Fcntl ':mode';
 use lib 't/';
@@ -18,6 +18,13 @@ BEGIN {

 my $Is_VMS = $^O eq 'VMS';

+my $fchmod_supported = 0;
+if (open my $fh, curdir()) {
+    my ($perm) = (stat($fh))[2];
+    $perm &= 07777;
+    eval { $fchmod_supported = chmod( $perm, $fh); };
+}
+
 # first check for stupid permissions second for full, so we clean up
 # behind ourselves
 for my $perm (0111,0777) {
@@ -299,16 +306,19 @@ is($created[0], $dir, "created directory (old style 3 mode undef) cross-check");

 is(rmtree($dir, 0, undef), 1, "removed directory 3 verbose undef");

-$dir = catdir($tmp_base,'G');
-$dir = VMS::Filespec::unixify($dir) if $Is_VMS;
+SKIP: {
+    skip "fchmod of directories not supported on this platform", 3 unless $fchmod_supported;
+    $dir = catdir($tmp_base,'G');
+    $dir = VMS::Filespec::unixify($dir) if $Is_VMS;

-@created = mkpath($dir, undef, 0200);
+    @created = mkpath($dir, undef, 0400);

-is(scalar(@created), 1, "created write-only dir");
+    is(scalar(@created), 1, "created read-only dir");

-is($created[0], $dir, "created write-only directory cross-check");
+    is($created[0], $dir, "created read-only directory cross-check");

-is(rmtree($dir), 1, "removed write-only dir");
+    is(rmtree($dir), 1, "removed read-only dir");
+}

 # borderline new-style heuristics
 if (chdir $tmp_base) {
@@ -450,26 +460,28 @@ SKIP: {
 }

 SKIP : {
-    my $skip_count = 19;
+    my $skip_count = 18;
     # this test will fail on Windows, as per:
     #   http://perldoc.perl.org/perlport.html#chmod

     skip "Windows chmod test skipped", $skip_count
         if $^O eq 'MSWin32';
+    skip "fchmod() on directories is not supported on this platform", $skip_count
+        unless $fchmod_supported;
     my $mode;
     my $octal_mode;
     my @inputs = (
-      0777, 0700, 0070, 0007,
-      0333, 0300, 0030, 0003,
-      0111, 0100, 0010, 0001,
-      0731, 0713, 0317, 0371, 0173, 0137,
-      00 );
+      0777, 0700, 0470, 0407,
+      0433, 0400, 0430, 0403,
+      0111, 0100, 0110, 0101,
+      0731, 0713, 0317, 0371,
+      0173, 0137);
     my $input;
     my $octal_input;
-    $dir = catdir($tmp_base, 'chmod_test');

     foreach (@inputs) {
         $input = $_;
+        $dir = catdir($tmp_base, sprintf("chmod_test%04o", $input));
         # We can skip from here because 0 is last in the list.
         skip "Mode of 0 means assume user defaults on VMS", 1
           if ($input == 0 && $Is_VMS);


code:
Rather than unconditionally using Mozilla's CA certificates, let the user tell
LWP's UserAgent where to find certificates with the PERL_LWP_SSL_CA_FILE,
HTTPS_CA_FILE, PERL_LWP_SSL_CA_PATH, or HTTPS_CA_DIR environment variables
instead.

--- Finance-Quote-1.37/lib/Finance/Quote/Tiaacref.pm.orig	2015-02-01 13:24:41.000000000 -0600
+++ Finance-Quote-1.37/lib/Finance/Quote/Tiaacref.pm	2015-07-07 20:09:47.278885944 -0500
@@ -30,7 +30,6 @@
 package Finance::Quote::Tiaacref;
 require 5.005;
 require LWP::Protocol::https;
-require Mozilla::CA;

 use strict;


code:
Work around a problem arising from the update to OpenSSL 1.0.2f, based on the
following upstream commit:

  https://github.com/noxxi/p5-io-socket-ssl/commit/6e23ee4a433f83f1065bd2467255eba5ee9b1ddd

Attempting to update to IO-Socket-SSL-2.023, which includes this commit,
caused other test failures.  See:

  https://lists.gnu.org/archive/html/guix-devel/2016-01/msg01032.html

Description from the upstream commit:

  OpenSSL 1.0.2f changed the behavior of SSL shutdown in case the TLS connection
  was not fully established (commit: f73c737c7ac908c5d6407c419769123392a3b0a9).
  This somehow resulted in Net::SSLeay::shutdown returning 0 (i.e. keep trying)
  which caused an endless loop. It will now ignore this result in case the TLS
  connection was not yet established and consider the TLS connection closed
  instead.

--- IO-Socket-SSL-2.002/lib/IO/Socket/SSL.pm.orig	2014-10-21 16:51:16.000000000 -0400
+++ IO-Socket-SSL-2.002/lib/IO/Socket/SSL.pm	2016-01-31 15:07:14.971099894 -0500
@@ -1213,6 +1213,11 @@
 		    # shutdown complete
 		    last;
 		}
+		if ((${*$self}{'_SSL_opened'}||0) <= 0) {
+		    # not really open, thus don't expect shutdown to return
+		    # something meaningful
+		    last;
+		}

 		# initiate or complete shutdown
 		local $SIG{PIPE} = 'IGNORE';


code:
Fix Perl module Module::Pluggable such that it can find plugins that live in
symlinked directories.

Patch borrowed/adapted from Nixpkgs.

--- Module-Pluggable-5.2/lib/Module/Pluggable/Object.pm   2015-04-08 23:28:48.120164135 -0500
+++ Module-Pluggable-5.2/lib/Module/Pluggable/Object.pm   2015-04-08 23:30:27.032166704 -0500
@@ -164,7 +164,7 @@
         my $sp = catdir($dir, (split /::/, $searchpath));

         # if it doesn't exist or it's not a dir then skip it
-        next unless ( -e $sp && -d _ ); # Use the cached stat the second time
+        next unless ( -e $sp );

         my @files = $self->find_files($sp);

@@ -279,7 +279,7 @@
                              (my $path = $File::Find::name) =~ s#^\\./##;
                              push @files, $path;
                            }
-                      }, $search_path );
+                      }, "$search_path/." );
     }
     #chdir $cwd;
     return @files;


code:
Patch borrowed from nixpkgs.  Works around warning message produced by the
current version of Moose:

"Passing a list of values to enum is deprecated. Enum values should be wrapped
in an arrayref."

--- Net-Amazon-S3-0.60/lib/Net/Amazon/S3/Client/Object.pm	2015-04-15 16:18:47.226410022 -0500
+++ Net-Amazon-S3-0.60/lib/Net/Amazon/S3/Client/Object.pm	2015-04-15 16:19:25.410408425 -0500
@@ -19,7 +19,7 @@
     [ qw(private public-read public-read-write authenticated-read) ];

 enum 'StorageClass' =>
-    qw(standard reduced_redundancy);
+    [ qw(standard reduced_redundancy) ];

 has 'client' =>
     ( is => 'ro', isa => 'Net::Amazon::S3::Client', required => 1 );


code:
perl-net-dns-resolver-programmable used the undocumented and internal
method Net::DNS::rcodesbyname [0], and that interface is no longer
exposed.

This patch, copied from [1], makes the program check for the existence
of the method before trying to use it.

[0]
<https://rt.cpan.org/Public/Bug/Display.html?id=95901>

[1]
<https://rt.cpan.org/Public/Bug/Display.html?id=95901#txn-1575108>

diff --git a/lib/Net/DNS/Resolver/Programmable.pm b/lib/Net/DNS/Resolver/Programmable.pm
index 1af72ce..e09a2f0 100644
--- a/lib/Net/DNS/Resolver/Programmable.pm
+++ b/lib/Net/DNS/Resolver/Programmable.pm
@@ -203,8 +203,10 @@ sub send {
     if (defined(my $resolver_code = $self->{resolver_code})) {
         ($result, $aa, @answer_rrs) = $resolver_code->($domain, $rr_type, $class);
     }
-
-    if (not defined($result) or defined($Net::DNS::rcodesbyname{$result})) {
+
+    if (not defined($result)
+         or defined($Net::DNS::Parameters::rcodebyname{$result})
+         or defined($Net::DNS::rcodesbyname{$result})) {
         # Valid RCODE, return a packet:

         $aa     = TRUE      if not defined($aa);


code:
Don't look for headers and libraries in "traditional" locations.

Patch adapted from Nixpkgs, originally by Eelco Dolstra
<eelco.dolstra@logicblox.com>.

diff -ru -x '*~' -x '*.rej' perl-5.20.0-orig/Configure perl-5.20.0/Configure
--- perl-5.20.0-orig/Configure	2014-05-26 15:34:18.000000000 +0200
+++ perl-5.20.0/Configure	2014-06-25 10:43:35.368285986 +0200
@@ -106,15 +106,7 @@
 fi

 : Proper PATH setting
-paths='/bin /usr/bin /usr/local/bin /usr/ucb /usr/local /usr/lbin'
-paths="$paths /opt/bin /opt/local/bin /opt/local /opt/lbin"
-paths="$paths /usr/5bin /etc /usr/gnu/bin /usr/new /usr/new/bin /usr/nbin"
-paths="$paths /opt/gnu/bin /opt/new /opt/new/bin /opt/nbin"
-paths="$paths /sys5.3/bin /sys5.3/usr/bin /bsd4.3/bin /bsd4.3/usr/ucb"
-paths="$paths /bsd4.3/usr/bin /usr/bsd /bsd43/bin /opt/ansic/bin /usr/ccs/bin"
-paths="$paths /etc /usr/lib /usr/ucblib /lib /usr/ccs/lib"
-paths="$paths /sbin /usr/sbin /usr/libexec"
-paths="$paths /system/gnu_library/bin"
+paths=''

 for p in $paths
 do
@@ -1337,8 +1329,7 @@
 archname=''
 : Possible local include directories to search.
 : Set locincpth to "" in a hint file to defeat local include searches.
-locincpth="/usr/local/include /opt/local/include /usr/gnu/include"
-locincpth="$locincpth /opt/gnu/include /usr/GNU/include /opt/GNU/include"
+locincpth=""
 :
 : no include file wanted by default
 inclwanted=''
@@ -1349,17 +1340,12 @@

 libnames=''
 : change the next line if compiling for Xenix/286 on Xenix/386
-xlibpth='/usr/lib/386 /lib/386'
+xlibpth=''
 : Possible local library directories to search.
-loclibpth="/usr/local/lib /opt/local/lib /usr/gnu/lib"
-loclibpth="$loclibpth /opt/gnu/lib /usr/GNU/lib /opt/GNU/lib"
+loclibpth=""

 : general looking path for locating libraries
-glibpth="/lib /usr/lib $xlibpth"
-glibpth="$glibpth /usr/ccs/lib /usr/ucblib /usr/local/lib"
-test -f /usr/shlib/libc.so && glibpth="/usr/shlib $glibpth"
-test -f /shlib/libc.so     && glibpth="/shlib $glibpth"
-test -d /usr/lib64         && glibpth="$glibpth /lib64 /usr/lib64 /usr/local/lib64"
+glibpth=""

 : Private path used by Configure to find libraries.  Its value
 : is prepended to libpth. This variable takes care of special
@@ -1391,8 +1377,6 @@
 libswanted="$libswanted m crypt sec util c cposix posix ucb bsd BSD"
 : We probably want to search /usr/shlib before most other libraries.
 : This is only used by the lib/ExtUtils/MakeMaker.pm routine extliblist.
-glibpth=`echo " $glibpth " | sed -e 's! /usr/shlib ! !'`
-glibpth="/usr/shlib $glibpth"
 : Do not use vfork unless overridden by a hint file.
 usevfork=false

@@ -2446,7 +2430,6 @@
 zip
 "
 pth=`echo $PATH | sed -e "s/$p_/ /g"`
-pth="$pth $sysroot/lib $sysroot/usr/lib"
 for file in $loclist; do
 	eval xxx=\$$file
 	case "$xxx" in
@@ -4936,7 +4919,7 @@
 : Set private lib path
 case "$plibpth" in
 '') if ./mips; then
-	plibpth="$incpath/usr/lib $sysroot/usr/local/lib $sysroot/usr/ccs/lib"
+	plibpth="$incpath/usr/lib"
     fi;;
 esac
 case "$libpth" in
@@ -8600,13 +8583,8 @@
 echo " "
 case "$sysman" in
 '')
-	syspath='/usr/share/man/man1 /usr/man/man1'
-	syspath="$syspath /usr/man/mann /usr/man/manl /usr/man/local/man1"
-	syspath="$syspath /usr/man/u_man/man1"
-	syspath="$syspath /usr/catman/u_man/man1 /usr/man/l_man/man1"
-	syspath="$syspath /usr/local/man/u_man/man1 /usr/local/man/l_man/man1"
-	syspath="$syspath /usr/man/man.L /local/man/man1 /usr/local/man/man1"
-	sysman=`./loc . /usr/man/man1 $syspath`
+	syspath=''
+	sysman=''
 	;;
 esac
 if $test -d "$sysman"; then
@@ -19900,9 +19878,10 @@
 case "$full_ar" in
 '') full_ar=$ar ;;
 esac
+full_ar=ar

 : Store the full pathname to the sed program for use in the C program
-full_sed=$sed
+full_sed=sed

 : see what type gids are declared as in the kernel
 echo " "
Only in perl-5.20.0/: Configure.orig
diff -ru -x '*~' -x '*.rej' perl-5.20.0-orig/ext/Errno/Errno_pm.PL perl-5.20.0/ext/Errno/Errno_pm.PL
--- perl-5.20.0-orig/ext/Errno/Errno_pm.PL	2014-05-26 15:34:20.000000000 +0200
+++ perl-5.20.0/ext/Errno/Errno_pm.PL	2014-06-25 10:31:24.317970047 +0200
@@ -126,11 +126,7 @@
 	if ($dep =~ /(\S+errno\.h)/) {
 	     $file{$1} = 1;
 	}
-    } elsif ($^O eq 'linux' &&
-	      $Config{gccversion} ne '' &&
-	      $Config{gccversion} !~ /intel/i
-	      # might be using, say, Intel's icc
-	     ) {
+    } elsif (0) {
     # When cross-compiling we may store a path for gcc's "sysroot" option:
     my $sysroot = $Config{sysroot} || '';
 	# Some Linuxes have weird errno.hs which generate
Only in perl-5.20.0/ext/Errno: Errno_pm.PL.orig
diff -ru -x '*~' -x '*.rej' perl-5.20.0-orig/hints/freebsd.sh perl-5.20.0/hints/freebsd.sh
--- perl-5.20.0-orig/hints/freebsd.sh	2014-01-31 22:55:51.000000000 +0100
+++ perl-5.20.0/hints/freebsd.sh	2014-06-25 10:25:53.263964680 +0200
@@ -119,21 +119,21 @@
         objformat=`/usr/bin/objformat`
         if [ x$objformat = xaout ]; then
             if [ -e /usr/lib/aout ]; then
-                libpth="/usr/lib/aout /usr/local/lib /usr/lib"
-                glibpth="/usr/lib/aout /usr/local/lib /usr/lib"
+                libpth=""
+                glibpth=""
             fi
             lddlflags='-Bshareable'
         else
-            libpth="/usr/lib /usr/local/lib"
-            glibpth="/usr/lib /usr/local/lib"
+            libpth=""
+            glibpth=""
             ldflags="-Wl,-E "
             lddlflags="-shared "
         fi
         cccdlflags='-DPIC -fPIC'
         ;;
 *)
-       libpth="/usr/lib /usr/local/lib"
-       glibpth="/usr/lib /usr/local/lib"
+       libpth=""
+       glibpth=""
        ldflags="-Wl,-E "
         lddlflags="-shared "
         cccdlflags='-DPIC -fPIC'
diff -ru -x '*~' -x '*.rej' perl-5.20.0-orig/hints/linux.sh perl-5.20.0/hints/linux.sh
--- perl-5.20.0-orig/hints/linux.sh	2014-05-26 15:34:20.000000000 +0200
+++ perl-5.20.0/hints/linux.sh	2014-06-25 10:33:47.354883843 +0200
@@ -150,25 +150,6 @@
     ;;
 esac

-# Ubuntu 11.04 (and later, presumably) doesn't keep most libraries
-# (such as -lm) in /lib or /usr/lib.  So we have to ask gcc to tell us
-# where to look.  We don't want gcc's own libraries, however, so we
-# filter those out.
-# This could be conditional on Unbuntu, but other distributions may
-# follow suit, and this scheme seems to work even on rather old gcc's.
-# This unconditionally uses gcc because even if the user is using another
-# compiler, we still need to find the math library and friends, and I don't
-# know how other compilers will cope with that situation.
-# Morever, if the user has their own gcc earlier in $PATH than the system gcc,
-# we don't want its libraries. So we try to prefer the system gcc
-# Still, as an escape hatch, allow Configure command line overrides to
-# plibpth to bypass this check.
-if [ -x /usr/bin/gcc ] ; then
-    gcc=/usr/bin/gcc
-else
-    gcc=gcc
-fi
-
 case "$plibpth" in
 '') plibpth=`LANG=C LC_ALL=C $gcc $ccflags $ldflags -print-search-dirs | grep libraries |
 	cut -f2- -d= | tr ':' $trnl | grep -v 'gcc' | sed -e 's:/$::'`
@@ -367,33 +322,6 @@
 	;;
 esac

-# SuSE8.2 has /usr/lib/libndbm* which are ld scripts rather than
-# true libraries. The scripts cause binding against static
-# version of -lgdbm which is a bad idea. So if we have 'nm'
-# make sure it can read the file
-# NI-S 2003/08/07
-case "$nm" in
-    '') ;;
-    *)
-    for p in $plibpth
-    do
-        if $test -r $p/libndbm.so; then
-            if $nm $p/libndbm.so >/dev/null 2>&1 ; then
-                echo 'Your shared -lndbm seems to be a real library.'
-                _libndbm_real=1
-                break
-            fi
-        fi
-    done
-    if $test "X$_libndbm_real" = X; then
-        echo 'Your shared -lndbm is not a real library.'
-        set `echo X "$libswanted "| sed -e 's/ ndbm / /'`
-        shift
-        libswanted="$*"
-    fi
-    ;;
-esac
-
 # Linux on Synology.
 if [ -f /etc/synoinfo.conf -a -d /usr/syno ]; then
     # Tested on Synology DS213 and DS413
diff --git a/hints/linux.sh b/hints/linux.sh
index 3f38ea0..97aed11 100644
--- a/hints/linux.sh
+++ b/hints/linux.sh
@@ -195,32 +195,6 @@ case "$usequadmath" in
   ;;
 esac

-case "$libc" in
-'')
-# If you have glibc, then report the version for ./myconfig bug reporting.
-# (Configure doesn't need to know the specific version since it just uses
-# gcc to load the library for all tests.)
-# We don't use __GLIBC__ and  __GLIBC_MINOR__ because they
-# are insufficiently precise to distinguish things like
-# libc-2.0.6 and libc-2.0.7.
-    for p in $plibpth
-    do
-        for trylib in libc.so.6 libc.so
-        do
-            if $test -e $p/$trylib; then
-                libc=`ls -l $p/$trylib | awk '{print $NF}'`
-                if $test "X$libc" != X; then
-                    break
-                fi
-            fi
-        done
-        if $test "X$libc" != X; then
-            break
-        fi
-    done
-    ;;
-esac
-
 if ${sh:-/bin/sh} -c exit; then
   echo ''
   echo 'You appear to have a working bash.  Good.'


code:
Don't encode the current timestamp.

This affects the output of `perl -V`, specifically the message "Compiled
at [...]".

The 'cf_time' and 'cf_by' values show up in 'config.h' and
in 'Config_heavy.pl'.

Use the output of 'uname -s' instead of 'uname -a' to avoid recording
the kernel version ('uname -o' leads to directory names like
'x86_64-gnulinux' instead of 'x86_64-linux', which might cause breakage
down the road.)

diff --git a/perl.c b/perl.c
index 228a0d8..ed38313 100644
--- a/perl.c
+++ b/perl.c
@@ -1825,6 +1825,7 @@ S_Internals_V(pTHX_ CV *cv)
     PUSHs(Perl_newSVpvn_flags(aTHX_ non_bincompat_options,
 			      sizeof(non_bincompat_options) - 1, SVs_TEMP));

+#define PERL_BUILD_DATE "Jan  1 1970 00:00:00"
 #ifndef PERL_BUILD_DATE
 #  ifdef __DATE__
 #    ifdef __TIME__

--- a/Configure	1970-01-01 01:00:00.000000000 +0100
+++ b/Configure	2016-10-01 14:47:20.017319739 +0200
@@ -3276,7 +3276,7 @@ $eunicefix tr
 : Try to determine whether config.sh was made on this system
 case "$config_sh" in
 '')
-myuname=`$uname -a 2>/dev/null`
+myuname=`$uname -s 2>/dev/null`
 $test -z "$myuname" && myuname=`hostname 2>/dev/null`
 # Downcase everything to avoid ambiguity.
 # Remove slashes and single quotes so we can use parts of this in
@@ -3845,10 +3845,10 @@
 . ./posthint.sh

 : who configured the system
-cf_time=`LC_ALL=C; LANGUAGE=C; export LC_ALL; export LANGUAGE; $date 2>&1`
+cf_time="1970-01-01"
 case "$cf_by" in
 "")
-	cf_by=`(logname) 2>/dev/null`
+	cf_by="guix"
 	case "$cf_by" in
 	"")
 		cf_by=`(whoami) 2>/dev/null`


code:
Description: Use the markdown library provided by the libmarkdown2 package.
Author: Alessandro Ghedini <al3xbio@gmail.com>
Origin: vendor
Forwarded: not-needed
Last-Update: 2012-01-01

--- a/Makefile.PL
+++ b/Makefile.PL
@@ -57,12 +57,6 @@

-sub MY::postamble {
-    return sprintf('
-$(MYEXTLIB):
-	%s
-', qq{( cd $extdir; CC='cc -fPIC' sh configure.sh; make )\n});
-}

 WriteMakefile(
     NAME              => 'Text::Markdown::Discount',
@@ -71,8 +65,6 @@
     ($] >= 5.005 ?
       (ABSTRACT_FROM  => 'lib/Text/Markdown/Discount.pm',
        AUTHOR         => 'Masayoshi Sekimura <sekimura@cpan.org>') : ()),
-    LIBS               => '-L' . $extdir,
-    INC               => '-I. -I' . $extdir,
-    MYEXTLIB          => $myextlib,
-    clean             => { FILES => $clean_files },
+    LIBS               => '-lmarkdown',
+    INC               => '-I.',
 );


code:
Fix build failure caused by erroneous use of an undeclared symbol.

Patch copied from upstream bug report:
https://rt.cpan.org/Public/Bug/Display.html?id=117793

From 0be0223422e6e5f4091c6e4e058d213623eed105 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Mon, 12 Sep 2016 14:40:44 +0200
Subject: [PATCH] Skip preprocessor symbol only CURL_STRICTER
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

CURL_STRICTER leaked into curl-constants.c when building against
curl-7.50.2. This is a preprocessor only macro without a value.

CPAN RT#117793

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 Makefile.PL | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.PL b/Makefile.PL
index f9170bb..ad2bd3d 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -127,7 +127,7 @@ if (!defined($curl_h)) {
     close H;

     for my $e (sort @syms) {
-       if($e =~ /(OBSOLETE|^CURL_EXTERN|_LAST\z|_LASTENTRY\z)/) {
+       if($e =~ /(OBSOLETE|^CURL_EXTERN|^CURL_STRICTER\z|_LAST\z|_LASTENTRY\z)/) {
           next;
        }
        my ($group) = $e =~ m/^([^_]+_)/;
--
2.7.4


code:
https://sources.debian.org/data/main/p/picprog/1.9.1-3/debian/patches/20_iopl.patch

Description: Avoid some functions in some architectures
 Upstream uses iopl() function and other architecture-dependent
 codes. This patch adds building switches to avoid them in
 some architectures.
Author: Koichi Akabe <vbkaisetsu@gmail.com>
Last-Update: 2011-11-30

--- picprog-1.9.1.orig/picport.cc
+++ picprog-1.9.1/picport.cc
@@ -38,7 +38,12 @@
 #include <ctime>

 #include <sys/ioctl.h>
-#include <sys/io.h>
+
+#if defined(__i386__) || defined(__x86_64__)
+  #include <sys/io.h>
+  #define HAVE_IOPL
+#endif
+
 #include <fcntl.h>
 #include <sys/time.h>
 #include <unistd.h>
@@ -160,8 +165,12 @@
     // Not root.  Cannot use realtime scheduling.
     use_nanosleep = 0;
   }
+#ifdef HAVE_IOPL
   if (iopl (3))
     disable_interrupts = 0;
+#else
+  disable_interrupts = 0;
+#endif

 #ifdef CPU_SETSIZE
   // When computing the delay loops, we do not want the cpu's to change.
@@ -403,13 +412,17 @@
 {
   struct timeval tv1, tv2;
   gettimeofday (&tv1, 0);
+#if defined(__i386__) or defined(__x86_64__)
   if (tsc_1000ns > 1 && disable_interrupts)
     asm volatile("pushf; cli");
+#endif
   set_clock_data (1, b); // set data, clock up
   delay (cable_delay);
   set_clock_data (0, b); // clock down
+#if defined(__i386__) or defined(__x86_64__)
   if (tsc_1000ns > 1 && disable_interrupts)
     asm volatile("popf");
+#endif
   gettimeofday (&tv2, 0);

   // We may have spent a long time in an interrupt or in another task
@@ -428,13 +441,17 @@
 {
   struct timeval tv1, tv2;
   gettimeofday (&tv1, 0);
+#if defined(__i386__) or defined(__x86_64__)
   if (tsc_1000ns > 1 && disable_interrupts)
     asm volatile("pushf; cli");
+#endif
   set_clock_data (1, 1); // clock up
   delay (cable_delay);
   set_clock_data (0, 1); // set data up, clock down
+#if defined(__i386__) or defined(__x86_64__)
   if (tsc_1000ns > 1 && disable_interrupts)
     asm volatile("popf");
+#endif
   gettimeofday (&tv2, 0);

   // We may have spent a long time in an interrupt or in another task


code:
Support the PURPLE_PLUGIN_PATH environment variable.  This patch is based on
one from Nixpkgs, but properly handles the case where that variable is unset.

--- pidgin-2.10.11/libpurple/plugin.c.orig	2014-11-23 11:41:25.000000000 -0500
+++ pidgin-2.10.11/libpurple/plugin.c	2015-08-04 14:31:02.257366144 -0400
@@ -1178,8 +1178,19 @@
 void
 purple_plugins_init(void) {
 	void *handle = purple_plugins_get_handle();
+	const gchar *purple_plugin_path;

 	purple_plugins_add_search_path(LIBDIR);
+	purple_plugin_path = g_getenv("PURPLE_PLUGIN_PATH");
+	if (purple_plugin_path && *purple_plugin_path) {
+		gchar **paths = g_strsplit(purple_plugin_path, ":", -1);
+		if (paths) {
+			gchar **p;
+			for (p = paths; *p; ++p)
+				if (**p) purple_plugins_add_search_path(*p);
+		}
+		g_strfreev(paths);
+	}

 	purple_signal_register(handle, "plugin-load",
 						 purple_marshal_VOID__POINTER,


code:
Description: Add missing inlcudes of cstddef, fixing FTBFS13.1
Author: Regis Boudin <regis@debian.org>
Bug-Debian: http://bugs.debian.org/624953
Bug-Debian: http://bugs.debian.org/640726

--- pinball-0.3.1/base/Behavior.cpp
+++ pinball-0.3.1/base/Behavior.cpp
@@ -10,6 +10,8 @@
 #include "Behavior.h"
 #include "Group.h"

+#include <cstddef>
+
 Behavior::Behavior() {
 	//EM_COUT("Behavior::Behavior", 1);
 	p_Light = NULL;
--- pinball-0.3.1/base/SignalSender.cpp
+++ pinball-0.3.1/base/SignalSender.cpp
@@ -12,6 +12,8 @@
 #include "Group.h"
 #include "Behavior.h"

+#include <cstddef>
+
 SignalSender * SignalSender::p_SignalSender = NULL;

 SignalSender::SignalSender() {
--- pinball-0.3.1/base/BehaviorVisitor.cpp
+++ pinball-0.3.1/base/BehaviorVisitor.cpp
@@ -10,6 +10,8 @@
 #include "Behavior.h"
 #include "Group.h"

+#include <cstddef>
+
 BehaviorVisitor * BehaviorVisitor::p_BehaviorVisitor = NULL;

 BehaviorVisitor::BehaviorVisitor() {