[xml-security-c] 03/05: Add patch to avoid PATH_MAX where possible

Russ Allbery rra at stanford.edu
Tue Apr 8 00:27:45 UTC 2014


This is an automated email from the git hooks/post-receive script.

rra pushed a commit to branch master
in repository xml-security-c.

commit 820fd20199920b400b86df09cf0344a41a3c04b7
Author: Russ Allbery <rra at debian.org>
Date:   Mon Apr 7 16:58:00 2014 -0700

    Add patch to avoid PATH_MAX where possible
    
    * Avoid use of PATH_MAX where possible by using getcwd to allocate the
      appropriate size string.  Fixes FTBFS on GNU/Hurd.  Patch from Svante
      Signell.  (Closes: #735162)
---
 debian/changelog                                   |   3 +
 ...0002-Avoid-use-of-PATH_MAX-where-possible.patch | 211 +++++++++++++++++++++
 debian/patches/series                              |   1 +
 3 files changed, 215 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 181b15b..b9f29c1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,8 @@
 xml-security-c (1.7.2-3) UNRELEASED; urgency=medium
 
+  * Avoid use of PATH_MAX where possible by using getcwd to allocate the
+    appropriate size string.  Fixes FTBFS on GNU/Hurd.  Patch from Svante
+    Signell.  (Closes: #735162)
   * Convert all Debian patches to separate patch files managed via gbp pq.
 
  -- Russ Allbery <rra at debian.org>  Mon, 07 Apr 2014 16:56:34 -0700
diff --git a/debian/patches/0002-Avoid-use-of-PATH_MAX-where-possible.patch b/debian/patches/0002-Avoid-use-of-PATH_MAX-where-possible.patch
new file mode 100644
index 0000000..8bfedd3
--- /dev/null
+++ b/debian/patches/0002-Avoid-use-of-PATH_MAX-where-possible.patch
@@ -0,0 +1,211 @@
+From: Svante Signell <svante.signell at gmail.com>
+Date: Mon, 7 Apr 2014 16:53:28 -0700
+Subject: Avoid use of PATH_MAX where possible
+
+xml-security-c currently FTBFS on GNU/Hurd due to PATH_MAX issues.
+
+The attached patch fixes this problem by adding a check in
+configure.ac for a working path = getcwd(NULL, 0), allocating
+the string length required dynamically, and freeing it later on.
+Similarly, the string baseURI is malloced and freed. As a fallback,
+when this is not supported, the code uses the old solution that
+assumes PATH_MAX is defined.
+---
+ configure.ac                             | 11 +++++++++++
+ xsec/tools/checksig/checksig.cpp         | 17 ++++++++++++-----
+ xsec/tools/cipher/cipher.cpp             | 17 ++++++++++++-----
+ xsec/tools/templatesign/templatesign.cpp | 17 ++++++++++++-----
+ xsec/tools/txfmout/txfmout.cpp           | 18 ++++++++++++------
+ 5 files changed, 59 insertions(+), 21 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 09e478e..8c7f9c3 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -73,6 +73,17 @@ AC_CHECK_HEADERS(unistd.h direct.h)
+ 
+ AC_CHECK_DECL(strcasecmp,[AC_DEFINE([XSEC_HAVE_STRCASECMP],[1],[Define to 1 if strcasecmp present.])],,[#include <string.h>]) 
+ 
++# Check whether getcwd can dynamically allocate memory.
++AC_MSG_CHECKING([whether getcwd(NULL, 0) works])
++AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdlib.h>
++     #include <unistd.h>],
++[char *cwd = getcwd(NULL, 0);
++return (cwd != NULL) ? EXIT_SUCCESS : EXIT_FAILURE;])],
++     [AC_MSG_RESULT(yes)
++      AC_DEFINE([HAVE_GETCWD_DYN], [1],
++         [Define to 1 if getcwd(NULL, 0) works])],
++     [AC_MSG_RESULT(no)])
++
+ AC_LANG(C++)
+ 
+ # Xerces is required
+diff --git a/xsec/tools/checksig/checksig.cpp b/xsec/tools/checksig/checksig.cpp
+index db81d27..fc4ac41 100644
+--- a/xsec/tools/checksig/checksig.cpp
++++ b/xsec/tools/checksig/checksig.cpp
+@@ -57,7 +57,6 @@
+ 
+ #if defined(HAVE_UNISTD_H)
+ # include <unistd.h>
+-# define _MAX_PATH PATH_MAX
+ #else
+ # if defined(HAVE_DIRECT_H)
+ #  include <direct.h>
+@@ -438,10 +437,14 @@ int evaluate(int argc, char ** argv) {
+ 		AnonymousResolver theAnonymousResolver;
+ 		     
+ 		// Map out base path of the file
+-		char path[_MAX_PATH];
+-		char baseURI[(_MAX_PATH * 2) + 10];
+-		getcwd(path, _MAX_PATH);
+-
++#if HAVE_GETCWD_DYN
++		char *path = getcwd(NULL, 0);
++		char *baseURI = (char*)malloc(strlen(path) + 8 + 1 + strlen(filename) + 1);
++#else
++		char path[PATH_MAX];
++		char baseURI[(PATH_MAX * 2) + 10];
++		getcwd(path, PATH_MAX);
++#endif
+ 		strcpy(baseURI, "file:///");		
+ 
+ 		// Ugly and nasty but quick
+@@ -471,6 +474,10 @@ int evaluate(int argc, char ** argv) {
+ 		XMLCh * baseURIXMLCh = XMLString::transcode(baseURI);
+ 
+ 		XMLUri uri(MAKE_UNICODE_STRING(baseURI));
++#if HAVE_GETCWD_DYN
++		free(path);
++		free(baseURI);
++#endif
+ 
+ 		if (useAnonymousResolver == true) {
+ 			// AnonymousResolver takes precedence
+diff --git a/xsec/tools/cipher/cipher.cpp b/xsec/tools/cipher/cipher.cpp
+index ec10a2a..d081c98 100644
+--- a/xsec/tools/cipher/cipher.cpp
++++ b/xsec/tools/cipher/cipher.cpp
+@@ -60,7 +60,6 @@
+ 
+ #if defined(HAVE_UNISTD_H)
+ # include <unistd.h>
+-# define _MAX_PATH PATH_MAX
+ #else
+ # if defined(HAVE_DIRECT_H)
+ #  include <direct.h>
+@@ -639,10 +638,14 @@ int evaluate(int argc, char ** argv) {
+ 			if (useInteropResolver == true) {
+ 
+ 				// Map out base path of the file
+-				char path[_MAX_PATH];
+-				char baseURI[(_MAX_PATH * 2) + 10];
+-				getcwd(path, _MAX_PATH);
+-
++#if HAVE_GETCWD_DYN
++				char *path = getcwd(NULL, 0);
++				char *baseURI = (char*)malloc(strlen(path) + 8 + 1 + strlen(filename) + 1);
++#else
++				char path[PATH_MAX];
++				char baseURI[(PATH_MAX * 2) + 10];
++				getcwd(path, PATH_MAX);
++#endif
+ 				strcpy(baseURI, "file:///");		
+ 
+ 				// Ugly and nasty but quick
+@@ -671,6 +674,10 @@ int evaluate(int argc, char ** argv) {
+ 				baseURI[lastSlash + 1] = '\0';
+ 
+ 				XMLCh * uriT = XMLString::transcode(baseURI);
++#if HAVE_GETCWD_DYN
++				free(path);
++				free(baseURI);
++#endif
+ 
+ 				XencInteropResolver ires(doc, &(uriT[8]));
+ 				XSEC_RELEASE_XMLCH(uriT);
+diff --git a/xsec/tools/templatesign/templatesign.cpp b/xsec/tools/templatesign/templatesign.cpp
+index ef56b8b..953fdcb 100644
+--- a/xsec/tools/templatesign/templatesign.cpp
++++ b/xsec/tools/templatesign/templatesign.cpp
+@@ -74,7 +74,6 @@
+ 
+ #if defined(HAVE_UNISTD_H)
+ # include <unistd.h>
+-# define _MAX_PATH PATH_MAX
+ #else
+ # if defined(HAVE_DIRECT_H)
+ #  include <direct.h>
+@@ -1169,10 +1168,14 @@ int main(int argc, char **argv) {
+      
+ 	// Map out base path of the file
+ 	char * filename=argv[argc-1];
+-	char path[_MAX_PATH];
+-	char baseURI[(_MAX_PATH * 2) + 10];
+-	getcwd(path, _MAX_PATH);
+-
++#if HAVE_GETCWD_DYN
++	char *path = getcwd(NULL, 0);
++	char *baseURI = (char*)malloc(strlen(path) + 8 + 1 + strlen(filename) + 1);
++#else
++	char path[PATH_MAX];
++	char baseURI[(PATH_MAX * 2) + 10];
++	getcwd(path, PATH_MAX);
++#endif
+ 	strcpy(baseURI, "file:///");		
+ 
+ 	// Ugly and nasty but quick
+@@ -1202,6 +1205,10 @@ int main(int argc, char **argv) {
+ 
+ 	theResolver->setBaseURI(MAKE_UNICODE_STRING(baseURI));
+ 	sig->setURIResolver(theResolver);
++#if HAVE_GETCWD_DYN
++	free(path);
++	free(baseURI);
++#endif
+ 
+ 	try {
+ 		sig->load();
+diff --git a/xsec/tools/txfmout/txfmout.cpp b/xsec/tools/txfmout/txfmout.cpp
+index b91a164..86eeb37 100644
+--- a/xsec/tools/txfmout/txfmout.cpp
++++ b/xsec/tools/txfmout/txfmout.cpp
+@@ -57,7 +57,6 @@
+ 
+ #if defined(HAVE_UNISTD_H)
+ # include <unistd.h>
+-# define _MAX_PATH PATH_MAX
+ #else
+ # if defined(HAVE_DIRECT_H)
+ #  include <direct.h>
+@@ -502,10 +501,14 @@ int main(int argc, char **argv) {
+ 		theResolver;
+ 		 
+ 	// Map out base path of the file
+-	char path[_MAX_PATH];
+-	char baseURI[(_MAX_PATH * 2) + 10];
+-	getcwd(path, _MAX_PATH);
+-
++#if HAVE_GETCWD_DYN
++	char *path = getcwd(NULL, 0);
++	char *baseURI = (char*)malloc(strlen(path) + 8 + 1 + strlen(filename) + 1);
++#else
++	char path[PATH_MAX];
++	char baseURI[(PATH_MAX * 2) + 10];
++	getcwd(path, PATH_MAX);
++#endif
+ 	strcpy(baseURI, "file:///");
+ 	strcat(baseURI, path);
+ 	strcat(baseURI, "/");
+@@ -526,7 +529,10 @@ int main(int argc, char **argv) {
+ 	baseURI[lastSlash + 1] = '\0';
+ 
+ 	theResolver.setBaseURI(MAKE_UNICODE_STRING(baseURI));
+-
++#if HAVE_GETCWD_DYN
++	free(path);
++	free(baseURI);
++#endif
+ 	sig->setURIResolver(&theResolver);
+ 
+ 
diff --git a/debian/patches/series b/debian/patches/series
index 819815e..1b1bcea 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
 0001-Add-xsec-prefix-to-utilities.patch
+0002-Avoid-use-of-PATH_MAX-where-possible.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-shibboleth/xml-security-c.git



More information about the Pkg-shibboleth-devel mailing list