Subject: bug#29782: Samba fails on core-updates

From: Marius Bakke <[email-masked]>
Date: Sun, 31 Dec 2017 16:11:29 +0100

Gábor Boskovits <[email-masked]> writes:

> [email-masked] fails on core-updates, commit 677bc34.
>
> This is the error message:
> error: file default/docs-xml/manpages/smb.conf.5.xml
> xsltRunStylesheet : run failed
> Waf: Leaving directory /tmp/guix-build-samba-4.7.3.drv-0/samba-4.7.3/bin'
> Build failed: -> task failed (err #11): {task: manpages/smb.conf.5
> smb.conf.5.xml,parameters.all.xml -> smb.conf.5} make: *** [Makefile:8:
> all] Error 1 phasebuild' failed after 588.9 seconds
> note: keeping build directory /tmp/guix-build-samba-4.7.3.drv-0' builder
> for/gnu/store/pc07rliscyvldzkj2gbq2lzcaj22m9wh-samba-4.7.3.drv' failed with
> exit code 1

Apparently the Samba man page blows up the XSL parser[0].  This patch
fixes it, and is carried by (at least) Debian, Fedora and Gentoo:

From e83e66d3efab96b181526ce9feaad42adb024f26 Mon Sep 17 00:00:00 2001
From: Marius Bakke <[email-masked]>
Date: Wed, 20 Dec 2017 17:40:43 +0100
Subject: [PATCH] gnu: docbook-xsl: Disable recursion in string substitution.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fixes <https://bugs.gnu.org/29782>.
Reported by Gábor Boskovits.

* gnu/packages/patches/docbook-xsl-nonrecursive-string-subst.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register it.
* gnu/packages/docbook.scm (docbook-xsl)[source](patches): Use it.
[native-inputs]: Add XZ.
[arguments]: Adjust PATH accordingly.
---
 gnu/local.mk                                       |  1 +
 gnu/packages/docbook.scm                           |  5 ++-
 .../docbook-xsl-nonrecursive-string-subst.patch    | 39 ++++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/docbook-xsl-nonrecursive-string-subst.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 514daec1c..7c30dd0f8 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -604,6 +604,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/dfu-programmer-fix-libusb.patch		\
   %D%/packages/patches/diffutils-gets-undeclared.patch		\
   %D%/packages/patches/diffutils-getopt.patch			\
+  %D%/packages/patches/docbook-xsl-nonrecursive-string-subst.patch	\
   %D%/packages/patches/doc++-include-directives.patch		\
   %D%/packages/patches/doc++-segfault-fix.patch			\
   %D%/packages/patches/doxygen-test.patch			\
diff --git a/gnu/packages/docbook.scm b/gnu/packages/docbook.scm
index 189ece01a..8507fb805 100644
--- a/gnu/packages/docbook.scm
+++ b/gnu/packages/docbook.scm
@@ -136,6 +136,7 @@ by no means limited to these applications.)  This package provides XML DTDs.")
               (method url-fetch)
               (uri (string-append "mirror://sourceforge/docbook/docbook-xsl/"
                                   version "/docbook-xsl-" version ".tar.bz2"))
+              (patches (search-patches "docbook-xsl-nonrecursive-string-subst.patch"))
               (sha256
                (base32
                 "0s59lihif2fr7rznckxr2kfyrvkirv76r1zvidp9b5mj28p4apvj"))))
@@ -145,11 +146,12 @@ by no means limited to these applications.)  This package provides XML DTDs.")
                    (use-modules (guix build utils))
 
                    (let* ((bzip2  (assoc-ref %build-inputs "bzip2"))
+                          (xz     (assoc-ref %build-inputs "xz"))
                           (tar    (assoc-ref %build-inputs "tar"))
                           (source (assoc-ref %build-inputs "source"))
                           (out    (assoc-ref %outputs "out"))
                           (xsl    (string-append out "/xml/xsl")))
-                     (setenv "PATH" (string-append bzip2 "/bin"))
+                     (setenv "PATH" (string-append bzip2 "/bin" ":" xz "/bin"))
                      (system* (string-append tar "/bin/tar") "xvf" source)
 
                      (mkdir-p xsl)
@@ -162,6 +164,7 @@ by no means limited to these applications.)  This package provides XML DTDs.")
                                        name-version "/")))))
                  #:modules ((guix build utils))))
     (native-inputs `(("bzip2" ,bzip2)
+                     ("xz" ,xz)
                      ("tar" ,tar)))
     (home-page "http://docbook.org")
     (synopsis "DocBook XSL style sheets for document authoring")
diff --git a/gnu/packages/patches/docbook-xsl-nonrecursive-string-subst.patch b/gnu/packages/patches/docbook-xsl-nonrecursive-string-subst.patch
new file mode 100644
index 000000000..4199dd18a
--- /dev/null
+++ b/gnu/packages/patches/docbook-xsl-nonrecursive-string-subst.patch
@@ -0,0 +1,39 @@
+Use a non-recursive replace function when the parser supports it.
+
+https://bugs.gnu.org/29782
+https://bugzilla.samba.org/show_bug.cgi?id=9515
+https://bugzilla.gnome.org/show_bug.cgi?id=736077 (for xsltproc)
+
+Patch copied from Debian:
+https://anonscm.debian.org/cgit/collab-maint/docbook-xsl.git/tree/debian/patches/765567_non-recursive_string_subst.patch
+
+Description: use EXSLT "replace" function when available
+ A recursive implementation  of string.subst is problematic,
+ long strings with many matches will cause stack overflows.
+Author: Peter De Wachter <[email-masked]>
+Bug-Debian: https://bugs.debian.org/750593
+
+--- a/lib/lib.xsl
++++ b/lib/lib.xsl
+@@ -10,7 +10,10 @@
+      This module implements DTD-independent functions
+ 
+      ******************************************************************** -->
+-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
++<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
++                xmlns:str="http://exslt.org/strings"
++                exclude-result-prefixes="str"
++                version="1.0">
+ 
+ <xsl:template name="dot.count">
+   <!-- Returns the number of "." characters in a string -->
+@@ -56,6 +59,9 @@
+   <xsl:param name="replacement"/>
+ 
+   <xsl:choose>
++    <xsl:when test="function-available('str:replace')">
++      <xsl:value-of select="str:replace($string, string($target), string($replacement))"/>
++    </xsl:when>
+     <xsl:when test="contains($string, $target)">
+       <xsl:variable name="rest">
+         <xsl:call-template name="string.subst">
-- 
2.15.1

[0] https://bugzilla.samba.org/show_bug.cgi?id=9515