Bug#744847: dwarves-dfsg: FTBFS on hurd-i386
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 with malloc and free them when
not needed any longer.
Thanks!
--- a/dwarves.c
+++ b/dwarves.c
@@ -1365,33 +1365,48 @@ int cus__load_dir(struct cus *self, stru
err = 0;
while ((entry = readdir(dir)) != NULL) {
- char pathname[PATH_MAX];
+ char *pathname;
+ size_t 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);
+ if (pathname == NULL) {
+ err = -1;
+ break;
+ }
+ snprintf(pathname, len, "%s/%s",
dirname, entry->d_name);
err = lstat(pathname, &st);
- if (err != 0)
+ if (err != 0) {
+ free(pathname);
break;
+ }
if (S_ISDIR(st.st_mode)) {
- if (!recursive)
+ if (!recursive) {
+ free(pathname);
continue;
-
+ }
err = cus__load_dir(self, conf, pathname,
filename_mask, recursive);
- if (err != 0)
+ if (err != 0) {
+ free(pathname);
break;
+ }
} else if (fnmatch(filename_mask, entry->d_name, 0) == 0) {
err = cus__load_file(self, conf, pathname);
- if (err != 0)
+ if (err != 0) {
+ free(pathname);
break;
+ }
}
+ free(pathname);
}
if (err == -1)
--- a/libctf.c
+++ b/libctf.c
@@ -723,26 +723,46 @@ 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);
+ size_t len;
+ char *pathname;
+ static const char *ctf_name = ".SUNW_ctf";
+
+ len = strlen(self->filename) + strlen(ctf_name) + 1;
+ pathname = malloc(len);
+ if (pathname == NULL)
+ goto out_close;
+ snprintf(pathname, len, "%s%s", self->filename, ctf_name);
fd = creat(pathname, S_IRUSR | S_IWUSR);
if (fd == -1) {
fprintf(stderr, "%s: open(%s) failed!\n", __func__, pathname);
+ free(pathname);
goto out_close;
}
- if (write(fd, bf, size) != size)
+ if (write(fd, bf, size) != size) {
+ free(pathname);
goto out_close;
+ }
if (close(fd) < 0)
goto out_unlink;
- char cmd[PATH_MAX];
- snprintf(cmd, sizeof(cmd), "objcopy --add-section .SUNW_ctf=%s %s",
+ char *cmd;
+ static const char *ctf_command = "objcopy --add-section ";
+
+ len = strlen(ctf_command) + strlen(ctf_name) + 1 +
+ strlen(pathname) + 1 + strlen(self->filename) + 1;
+ cmd = malloc(len);
+ if (cmd == NULL)
+ goto out_unlink;
+
+ snprintf(cmd, len, "%s%s=%s %s", ctf_command, ctf_name,
pathname, self->filename);
if (system(cmd) == 0)
err = 0;
+ free(cmd);
out_unlink:
unlink(pathname);
+ free(pathname);
return err;
#endif
out_update:
--- a/ctracer.c
+++ b/ctracer.c
@@ -965,13 +965,14 @@ static struct argp ctracer__argp = {
int main(int argc, char *argv[])
{
int remaining, err;
+ size_t 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 = NULL;
+ char *methods_filename = NULL;
+ char *collector_filename = NULL;
+ char *classes_filename = NULL;
struct structure *pos;
FILE *fp_functions;
int rc = EXIT_FAILURE;
@@ -1048,8 +1049,17 @@ failure:
goto out;
}
- snprintf(functions_filename, sizeof(functions_filename),
- "%s/%s.functions", src_dir, class__name(tag__class(class), cu));
+ static const char *functions_ext = ".functions";
+ len = strlen(src_dir) + 1 +
+ strlen(class__name(tag__class(class), cu)) +
+ strlen(functions_ext) + 1;
+ functions_filename = malloc(len);
+ if (functions_filename == NULL) {
+ fprintf(stderr, "ctracer: malloc failed allocating space for functions_filename\n");
+ goto out;
+ }
+ snprintf(functions_filename, len, "%s/%s%s",
+ src_dir, class__name(tag__class(class), cu), functions_ext);
fp_functions = fopen(functions_filename, "w");
if (fp_functions == NULL) {
fprintf(stderr, "ctracer: couldn't create %s\n",
@@ -1057,8 +1067,15 @@ failure:
goto out;
}
- snprintf(methods_filename, sizeof(methods_filename),
- "%s/ctracer_methods.stp", src_dir);
+ static const char *methods_name = "ctracer_methods.stp";
+ len = strlen(src_dir) + 1 + strlen(methods_name) + 1;
+ methods_filename = malloc(len);
+ if (methods_filename == NULL) {
+ fprintf(stderr, "ctracer: malloc failed allocating space for methods_filename\n");
+ goto out;
+ }
+ snprintf(methods_filename, len,
+ "%s/%s", src_dir, methods_name);
fp_methods = fopen(methods_filename, "w");
if (fp_methods == NULL) {
fprintf(stderr, "ctracer: couldn't create %s\n",
@@ -1066,8 +1083,15 @@ failure:
goto out;
}
- snprintf(collector_filename, sizeof(collector_filename),
- "%s/ctracer_collector.c", src_dir);
+ static const char *collector_name = "ctracer_collector.c";
+ len = strlen(src_dir) + 1 + strlen(collector_name) + 1;
+ collector_filename = malloc(len);
+ if (collector_filename == NULL) {
+ fprintf(stderr, "ctracer: malloc failed allocating space for collector_filename\n");
+ goto out;
+ }
+ snprintf(collector_filename, len,
+ "%s/%s", src_dir, collector_name);
fp_collector = fopen(collector_filename, "w");
if (fp_collector == NULL) {
fprintf(stderr, "ctracer: couldn't create %s\n",
@@ -1075,8 +1099,15 @@ failure:
goto out;
}
- snprintf(classes_filename, sizeof(classes_filename),
- "%s/ctracer_classes.h", src_dir);
+ static const char *classes_name = "ctracer_classes.h";
+ len = strlen(src_dir) + 1 + strlen(classes_name) + 1;
+ classes_filename = malloc(len);
+ if (classes_filename == NULL) {
+ fprintf(stderr, "ctracer: malloc failed allocating space for classes_filename\n");
+ goto out;
+ }
+ snprintf(classes_filename, len,
+ "%s/%s", src_dir, classes_name);
fp_classes = fopen(classes_filename, "w");
if (fp_classes == NULL) {
fprintf(stderr, "ctracer: couldn't create %s\n",
@@ -1144,6 +1175,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: