Source: xml-security-c
Version: 1.7.2-2
Severity: important
Tags: patch
User: [email protected]
Usertags: hurd

Hi,

xml-security-c currently FTBFS on GNU/Hurd due to PATH_MAX issues, see
https://buildd.debian.org/status/fetch.php?pkg=xml-security-c&arch=hurd-i386&ver=1.7.2-2&stamp=1389227253

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 freed later on. Similarly the string baseURI
is malloced and freed. As a fallback, when this is not supported, the
code falls back to the old solution using PATH_MAX, assuming it is
defined.

Thanks!
--- 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 for required functionality
+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
--- 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,9 @@ int evaluate(int argc, char ** argv) {
 		XMLCh * baseURIXMLCh = XMLString::transcode(baseURI);
 
 		XMLUri uri(MAKE_UNICODE_STRING(baseURI));
+#if HAVE_GETCWD_DYN
+		free(baseURI);
+#endif
 
 		if (useAnonymousResolver == true) {
 			// AnonymousResolver takes precedence
--- 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,9 @@ int evaluate(int argc, char ** argv) {
 				baseURI[lastSlash + 1] = '\0';
 
 				XMLCh * uriT = XMLString::transcode(baseURI);
+#if HAVE_GETCWD_DYN
+				free(baseURI);
+#endif
 
 				XencInteropResolver ires(doc, &(uriT[8]));
 				XSEC_RELEASE_XMLCH(uriT);
--- 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,9 @@ int main(int argc, char **argv) {
 
 	theResolver->setBaseURI(MAKE_UNICODE_STRING(baseURI));
 	sig->setURIResolver(theResolver);
+#if HAVE_GETCWD_DYN
+	free(baseURI);
+#endif
 
 	try {
 		sig->load();
--- 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,9 @@ int main(int argc, char **argv) {
 	baseURI[lastSlash + 1] = '\0';
 
 	theResolver.setBaseURI(MAKE_UNICODE_STRING(baseURI));
-
+#if HAVE_GETCWD_DYN
+	free(baseURI);
+#endif
 	sig->setURIResolver(&theResolver);
 
 

Reply via email to