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

dwarves-dfsg: FTBFS on hurd-i386 (for review)



Source: dwarves-dfsg
Version: 1.10-2
Severity: important
Tags: patch
User: debian-hurd@lists.debian.org
Usertags: hurd

Hi,

Currently dwarves-dfsg fails to build from source due to PATH_MAX being
used, and that constant is not defined on GNU/Hurd. The attached patch
avoid using PATH_MAX by allocating strings by malloc and free them when
not needed any longer.

Thanks!
--- a/dwarves.c.orig	2012-03-20 17:17:25.000000000 +0100
+++ b/dwarves.c	2014-04-02 11:05:36.000000000 +0200
@@ -1365,14 +1365,17 @@
 
 	err = 0;
 	while ((entry = readdir(dir)) != NULL) {
-		char pathname[PATH_MAX];
+		char *pathname;
+		int len;
 		struct stat st;
 
 		if (strcmp(entry->d_name, ".") == 0 ||
 		    strcmp(entry->d_name, "..") == 0)
 		    continue;
 
-		snprintf(pathname, sizeof(pathname), "%s/%s",
+		len = strlen(dirname) + 1 + strlen(entry->d_name) + 1;
+		pathname = malloc(len);
+		snprintf(pathname, len, "%s/%s",
 			 dirname, entry->d_name);
 
 		err = lstat(pathname, &st);
@@ -1392,6 +1395,7 @@
 			if (err != 0)
 				break;
 		}
+		free (pathname);
 	}
 
 	if (err == -1)
--- a/libctf.c.orig	2012-03-20 17:17:25.000000000 +0100
+++ b/libctf.c	2014-04-02 11:09:04.000000000 +0200
@@ -723,8 +723,11 @@ found_SUNW_ctf_str:
 	gelf_update_shdr(newscn, &shdr_mem);
 	elf_flagshdr(newscn, ELF_C_SET, ELF_F_DIRTY);
 #else
-	char pathname[PATH_MAX];
-	snprintf(pathname, sizeof(pathname), "%s.SUNW_ctf", self->filename);
+	int len;
+	char *pathname;
+	len = strlen(self->filename) + 9 + 1;
+	pathname = malloc(len);
+	snprintf(pathname, len, "%s.SUNW_ctf", self->filename);
 	fd = creat(pathname, S_IRUSR | S_IWUSR);
 	if (fd == -1) {
 		fprintf(stderr, "%s: open(%s) failed!\n", __func__, pathname);
@@ -736,13 +739,16 @@ found_SUNW_ctf_str:
 	if (close(fd) < 0)
 		goto out_unlink;
 
-	char cmd[PATH_MAX];
+	char *cmd;
+	len = 32 + strlen(pathname) + 1 + strlen(self->filename) + 1;
 	snprintf(cmd, sizeof(cmd), "objcopy --add-section .SUNW_ctf=%s %s",
 		 pathname, self->filename);
 	if (system(cmd) == 0)
 		err = 0;
 out_unlink:
 	unlink(pathname);
+	free(pathname);
+	free(cmd);
 	return err;
 #endif
 out_update:
@@ -758,6 +764,8 @@ out_update:
 	elf_end(elf);
 	err = 0;
 out_close:
+	free(pathname);
+	free(cmd);
 	if (bf != self->buf)
 		free(bf);
 	close(fd);
--- a/ctracer.c.orig	2012-03-20 17:17:25.000000000 +0100
+++ b/ctracer.c	2014-04-02 11:12:09.000000000 +0200
@@ -964,14 +964,14 @@ static struct argp ctracer__argp = {
 
 int main(int argc, char *argv[])
 {
-	int remaining, err;
+	int remaining, err, len;
 	struct tag *class;
 	struct cu *cu;
 	char *filename;
-	char functions_filename[PATH_MAX];
-	char methods_filename[PATH_MAX];
-	char collector_filename[PATH_MAX];
-	char classes_filename[PATH_MAX];
+	char *functions_filename;
+	char *methods_filename;
+	char *collector_filename;
+	char *classes_filename;
 	struct structure *pos;
 	FILE *fp_functions;
 	int rc = EXIT_FAILURE;
@@ -1048,7 +1048,10 @@ failure:
 		goto out;
 	}
 
-	snprintf(functions_filename, sizeof(functions_filename),
+	len = strlen(src_dir) + 1 +
+	  strlen(class__name(tag__class(class), cu)) + 10 + 1;
+	functions_filename = malloc(len);
+	snprintf(functions_filename, len,
 		 "%s/%s.functions", src_dir, class__name(tag__class(class), cu));
 	fp_functions = fopen(functions_filename, "w");
 	if (fp_functions == NULL) {
@@ -1057,7 +1060,9 @@ failure:
 		goto out;
 	}
 
-	snprintf(methods_filename, sizeof(methods_filename),
+	len = strlen(src_dir) + 20 + 1; 
+	methods_filename = malloc(len);
+	snprintf(methods_filename, len,
 		 "%s/ctracer_methods.stp", src_dir);
 	fp_methods = fopen(methods_filename, "w");
 	if (fp_methods == NULL) {
@@ -1066,7 +1071,9 @@ failure:
 		goto out;
 	}
 
-	snprintf(collector_filename, sizeof(collector_filename),
+	len = strlen(src_dir) + 20 + 1; 
+	collector_filename = malloc(len);
+	snprintf(collector_filename, len,
 		 "%s/ctracer_collector.c", src_dir);
 	fp_collector = fopen(collector_filename, "w");
 	if (fp_collector == NULL) {
@@ -1075,7 +1082,9 @@ failure:
 		goto out;
 	}
 
-	snprintf(classes_filename, sizeof(classes_filename),
+	len = strlen(src_dir) + 18 + 1; 
+	classes_filename = malloc(len);
+	snprintf(classes_filename, len,
 		 "%s/ctracer_classes.h", src_dir);
 	fp_classes = fopen(classes_filename, "w");
 	if (fp_classes == NULL) {
@@ -1144,6 +1153,10 @@ failure:
 
 	rc = EXIT_SUCCESS;
 out:
+	free(functions_filename);
+	free(methods_filename);
+	free(collector_filename);
+	free(classes_filename);
 	cus__delete(methods_cus);
 	dwarves__exit();
 	return rc;

Reply to: