[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#645346: pax: FTBFS on hurd-i386



Package: pax
Version: 20090728-2
Severity: important
Tags: patch
Usertags: hurd

Attached is a small patch to make pax-20090728 build under GNU/Hurd.
The first part is using the already issued lstat(2) call to find out
the size for a dynamic allocation of a character string, avoiding the
MAXPATHLEN issue. Secondly the reaplath(3) call is conditionally
replaced with canonicalize_file_name(3).

Thanks!
diff -ur pax-20090728/file_subs.c pax-20090728.modified/file_subs.c
--- pax-20090728/file_subs.c	2009-07-28 17:38:28.000000000 +0000
+++ pax-20090728.modified/file_subs.c	2011-10-13 14:45:13.000000000 +0000
@@ -351,7 +351,7 @@
 	int pass = 0;
 	mode_t file_mode;
 	struct stat sb;
-	char target[MAXPATHLEN];
+	char *target = NULL;
 	char *nm = arcn->name;
 	int len;
 
@@ -374,8 +374,15 @@
 			if (strcmp(NM_TAR, argv0) == 0 && Lflag) {
 				while (lstat(nm, &sb) == 0 &&
 				    S_ISLNK(sb.st_mode)) {
+					target = malloc(sb.st_size + 1);
+					if (target == NULL) {
+						oerrno = ENOMEM;
+						syswarn(1, oerrno,
+						    "Insufficient memory");
+						return(-1);
+					}
 					len = readlink(nm, target,
-					    sizeof target - 1);
+					    strlen(target));
 					if (len == -1) {
 						syswarn(0, errno,
 						   "cannot follow symlink %s in chain for %s",
@@ -411,6 +418,7 @@
 			paxwarn(0,
 			    "%s skipped. Sockets cannot be copied or extracted",
 			    nm);
+			free(target);
 			return(-1);
 		case PAX_SLK:
 			res = symlink(arcn->ln_name, nm);
@@ -425,6 +433,7 @@
 			 */
 			paxwarn(0, "%s has an unknown file type, skipping",
 				nm);
+			free(target);
 			return(-1);
 		}
 
@@ -440,14 +449,17 @@
 		 * we failed to make the node
 		 */
 		oerrno = errno;
-		if ((ign = unlnk_exist(nm, arcn->type)) < 0)
+		if ((ign = unlnk_exist(nm, arcn->type)) < 0) {
+			free(target);
 			return(-1);
+		}
 
 		if (++pass <= 1)
 			continue;
 
 		if (nodirs || chk_path(nm,arcn->sb.st_uid,arcn->sb.st_gid) < 0) {
 			syswarn(1, oerrno, "Could not create: %s", nm);
+			free(target);
 			return(-1);
 		}
 	}
@@ -517,6 +529,7 @@
 
 	if (patime || pmtime)
 		set_ftime(nm, arcn->sb.st_mtime, arcn->sb.st_atime, 0);
+	free(target);
 	return(0);
 }
 
diff -ur pax-20090728/tables.c pax-20090728.modified/tables.c
--- pax-20090728/tables.c	2009-07-28 17:38:28.000000000 +0000
+++ pax-20090728.modified/tables.c	2011-10-13 14:20:10.000000000 +0000
@@ -1126,13 +1126,21 @@
 add_dir(char *name, struct stat *psb, int frc_mode)
 {
 	DIRDATA *dblk;
+#ifdef __GNU__
+	char *rp = NULL;
+#else
 	char realname[MAXPATHLEN], *rp;
+#endif
 
 	if (dirp == NULL)
 		return;
 
 	if (havechd && *name != '/') {
+#ifdef __GNU__
+		if ((rp = canonicalize_file_name(name)) == NULL) {
+#else
 		if ((rp = realpath(name, realname)) == NULL) {
+#endif
 			paxwarn(1, "Cannot canonicalize %s", name);
 			return;
 		}
@@ -1143,6 +1151,9 @@
 		if (dblk == NULL) {
 			paxwarn(1, "Unable to store mode and times for created"
 			    " directory: %s", name);
+#ifdef __GNU__
+			free(rp);
+#endif
 			return;
 		}
 		dirp = dblk;
@@ -1152,6 +1163,9 @@
 	if ((dblk->name = strdup(name)) == NULL) {
 		paxwarn(1, "Unable to store mode and times for created"
 		    " directory: %s", name);
+#ifdef __GNU__
+		free(rp);
+#endif
 		return;
 	}
 	dblk->mode = psb->st_mode & 0xffff;
@@ -1159,6 +1173,9 @@
 	dblk->atime = psb->st_atime;
 	dblk->frc_mode = frc_mode;
 	++dircnt;
+#ifdef __GNU__
+	free(rp);
+#endif
 }
 
 /*

Reply to: