1 Author: Svante Signell <svante.signell@telia.com>
2 Author: Petter Reinholdtsen <pere@hungry.com>
3 Author: Magnus Holmgren <magnus@debian.org>
4 Bug-Debian: http://bugs.debian.org/657116
5 Description: Fix FTBFS on Hurd by dynamically allocating path names.
6 Depends on no_static_buffers.patch, which introduced the th_pathname field.
8 --- a/compat/basename.c
9 +++ b/compat/basename.c
10 @@ -34,13 +34,25 @@ static char rcsid[] = "$OpenBSD: basenam
13 #include <sys/param.h>
17 openbsd_basename(path)
20 - static char bname[MAXPATHLEN];
21 + static char *bname = NULL;
22 + static size_t allocated = 0;
23 register const char *endp, *startp;
28 + bname = malloc(allocated);
35 /* Empty or NULL string gets treated as "." */
36 if (path == NULL || *path == '\0') {
37 @@ -64,11 +76,19 @@ openbsd_basename(path)
38 while (startp > path && *(startp - 1) != '/')
41 - if (endp - startp + 1 > sizeof(bname)) {
42 - errno = ENAMETOOLONG;
44 + len = endp - startp + 1;
46 + if (len + 1 > allocated) {
47 + size_t new_allocated = 2*(len+1);
48 + void *new_bname = malloc(new_allocated);
51 + allocated = new_allocated;
55 - (void)strncpy(bname, startp, endp - startp + 1);
56 - bname[endp - startp + 1] = '\0';
58 + (void)strncpy(bname, startp, len);
62 --- a/compat/dirname.c
63 +++ b/compat/dirname.c
64 @@ -34,13 +34,25 @@ static char rcsid[] = "$OpenBSD: dirname
67 #include <sys/param.h>
74 - static char bname[MAXPATHLEN];
75 + static char *bname = NULL;
76 + static size_t allocated = 0;
77 register const char *endp;
82 + bname = malloc(allocated);
89 /* Empty or NULL string gets treated as "." */
90 if (path == NULL || *path == '\0') {
91 @@ -67,11 +79,19 @@ openbsd_dirname(path)
92 } while (endp > path && *endp == '/');
95 - if (endp - path + 1 > sizeof(bname)) {
96 - errno = ENAMETOOLONG;
98 + len = endp - path + 1;
100 + if (len + 1 > allocated) {
101 + size_t new_allocated = 2*(len+1);
102 + void *new_bname = malloc(new_allocated);
105 + allocated = new_allocated;
109 - (void)strncpy(bname, path, endp - path + 1);
110 - bname[endp - path + 1] = '\0';
112 + (void)strncpy(bname, path, len);
118 @@ -38,7 +38,7 @@ typedef struct tar_dev tar_dev_t;
122 - char ti_name[MAXPATHLEN];
125 typedef struct tar_ino tar_ino_t;
127 @@ -61,7 +61,7 @@ tar_append_file(TAR *t, const char *real
129 tar_dev_t *td = NULL;
130 tar_ino_t *ti = NULL;
131 - char path[MAXPATHLEN];
135 printf("==> tar_append_file(TAR=0x%lx (\"%s\"), realname=\"%s\", "
136 @@ -126,34 +126,39 @@ tar_append_file(TAR *t, const char *real
142 printf("+++ adding entry: device (0x%lx,0x%lx), inode %ld "
143 "(\"%s\")...\n", major(s.st_dev), minor(s.st_dev),
146 - ti = (tar_ino_t *)calloc(1, sizeof(tar_ino_t));
147 + name = savename ? savename : realname;
148 + ti = (tar_ino_t *)calloc(1, sizeof(tar_ino_t) + strlen(name) + 1);
151 ti->ti_ino = s.st_ino;
152 - snprintf(ti->ti_name, sizeof(ti->ti_name), "%s",
153 - savename ? savename : realname);
154 + snprintf(ti->ti_name, strlen(name) + 1, "%s", name);
155 libtar_hash_add(td->td_h, ti);
158 /* check if it's a symlink */
161 - i = readlink(realname, path, sizeof(path));
162 + if ((path = malloc(s.st_size + 1)) == NULL)
164 + i = readlink(realname, path, s.st_size);
169 - if (i >= MAXPATHLEN)
170 - i = MAXPATHLEN - 1;
174 printf(" tar_append_file(): encoding symlink \"%s\" -> "
175 "\"%s\"...\n", realname, path);
177 th_set_link(t, path);
181 /* print file info */
184 @@ -33,7 +33,8 @@ th_get_pathname(TAR *t)
185 /* allocate the th_pathname buffer if not already */
186 if (t->th_pathname == NULL)
188 - t->th_pathname = malloc(MAXPATHLEN * sizeof(char));
189 + /* Allocate the maximum length of prefix + '/' + name + '\0' */
190 + t->th_pathname = malloc(155 + 1 + 100 + 1);
191 if (t->th_pathname == NULL)
194 @@ -41,11 +42,11 @@ th_get_pathname(TAR *t)
196 if (t->th_buf.prefix[0] == '\0')
198 - snprintf(t->th_pathname, MAXPATHLEN, "%.100s", t->th_buf.name);
199 + sprintf(t->th_pathname, "%.100s", t->th_buf.name);
203 - snprintf(t->th_pathname, MAXPATHLEN, "%.155s/%.100s",
204 + sprintf(t->th_pathname, "%.155s/%.100s",
205 t->th_buf.prefix, t->th_buf.name);
212 #include <sys/param.h>
220 path_hashfunc(char *key, int numbuckets)
222 - char buf[MAXPATHLEN];
231 - return (((unsigned int)p[0]) % numbuckets);
232 + i = ((unsigned int)p[0]) % numbuckets;
238 @@ -77,15 +80,26 @@ ino_hash(ino_t *inode)
240 mkdirhier(char *path)
242 - char src[MAXPATHLEN], dst[MAXPATHLEN] = "";
243 - char *dirp, *nextp = src;
245 + char *src, *dst = NULL;
246 + char *dirp, *nextp = NULL;
247 + int retval = 1, len;
249 + len = strlen(path);
250 + if ((src = strdup(path)) == NULL)
257 - if (strlcpy(src, path, sizeof(src)) > sizeof(src))
258 + /* Make room for // with absolute paths */
259 + if ((dst = malloc(len + 2)) == NULL)
261 - errno = ENAMETOOLONG;
270 @@ -102,12 +116,18 @@ mkdirhier(char *path)
271 if (mkdir(dst, 0777) == -1)
292 #include <sys/param.h>
299 @@ -26,8 +27,8 @@ int
300 tar_extract_glob(TAR *t, char *globname, char *prefix)
303 - char buf[MAXPATHLEN];
308 while ((i = th_read(t)) == 0)
310 @@ -41,11 +42,25 @@ tar_extract_glob(TAR *t, char *globname,
311 if (t->options & TAR_VERBOSE)
314 - snprintf(buf, sizeof(buf), "%s/%s", prefix, filename);
316 + len = strlen(prefix) + 1 + strlen(filename);
317 + if ((buf = malloc(len + 1)) == NULL)
319 + sprintf(buf, "%s/%s", prefix, filename);
322 - strlcpy(buf, filename, sizeof(buf));
324 + len = strlen(filename);
325 + if ((buf = malloc(len + 1)) == NULL)
327 + strcpy(buf, filename);
329 if (tar_extract_file(t, buf) != 0)
337 return (i == 1 ? 0 : -1);
338 @@ -56,8 +71,9 @@ int
339 tar_extract_all(TAR *t, char *prefix)
342 - char buf[MAXPATHLEN];
345 + size_t bufsize = 0;
349 printf("==> tar_extract_all(TAR *t, \"%s\")\n",
350 @@ -73,15 +89,29 @@ tar_extract_all(TAR *t, char *prefix)
351 if (t->options & TAR_VERBOSE)
354 - snprintf(buf, sizeof(buf), "%s/%s", prefix, filename);
356 + len = strlen(prefix) + 1 + strlen(filename);
357 + if ((buf = malloc(len + 1)) == NULL)
359 + sprintf(buf, "%s/%s", prefix, filename);
362 - strlcpy(buf, filename, sizeof(buf));
364 + len = strlen(filename);
365 + if ((buf = malloc(len + 1)) == NULL)
367 + strcpy(buf, filename);
370 printf(" tar_extract_all(): calling tar_extract_file(t, "
373 if (tar_extract_file(t, buf) != 0)
381 return (i == 1 ? 0 : -1);
382 @@ -91,11 +121,14 @@ tar_extract_all(TAR *t, char *prefix)
384 tar_append_tree(TAR *t, char *realdir, char *savedir)
386 - char realpath[MAXPATHLEN];
387 - char savepath[MAXPATHLEN];
388 + char *realpath = NULL;
389 + size_t realpathsize = 0;
390 + char *savepath = NULL;
391 + size_t savepathsize = 0;
398 printf("==> tar_append_tree(0x%lx, \"%s\", \"%s\")\n",
399 @@ -122,11 +155,21 @@ tar_append_tree(TAR *t, char *realdir, c
400 strcmp(dent->d_name, "..") == 0)
403 - snprintf(realpath, MAXPATHLEN, "%s/%s", realdir,
404 + len = strlen(realdir) + 1 + strlen(dent->d_name);
405 + if ((realpath = malloc(len + 1)) == NULL)
407 + snprintf(realpath, len + 1, "%s/%s", realdir,
410 - snprintf(savepath, MAXPATHLEN, "%s/%s", savedir,
412 + len = strlen(savedir) + 1 + strlen(dent->d_name);
413 + if ((savepath = malloc(len + 1)) == NULL) {
417 + snprintf(savepath, len + 1, "%s/%s", savedir,
421 if (lstat(realpath, &s) != 0)
423 @@ -135,13 +178,23 @@ tar_append_tree(TAR *t, char *realdir, c
425 if (tar_append_tree(t, realpath,
426 (savedir ? savepath : NULL)) != 0)
435 if (tar_append_file(t, realpath,
436 (savedir ? savepath : NULL)) != 0)
447 --- a/libtar/libtar.c
448 +++ b/libtar/libtar.c
449 @@ -111,8 +111,9 @@ create(char *tarfile, char *rootdir, lib
453 - char buf[MAXPATHLEN];
458 if (tar_open(&t, tarfile,
460 @@ -133,17 +134,29 @@ create(char *tarfile, char *rootdir, lib
462 pathname = (char *)libtar_listptr_data(&lp);
463 if (pathname[0] != '/' && rootdir != NULL)
464 - snprintf(buf, sizeof(buf), "%s/%s", rootdir, pathname);
466 + len = strlen(rootdir) + 1 + strlen(pathname);
467 + if ((buf = malloc(len + 1)) == NULL)
469 + snprintf(buf, len + 1, "%s/%s", rootdir, pathname);
472 - strlcpy(buf, pathname, sizeof(buf));
474 + len = strlen(pathname);
475 + if ((buf = malloc(len + 1)) == NULL)
477 + strlcpy(buf, pathname, len + 1);
479 if (tar_append_tree(t, buf, pathname) != 0)
482 "tar_append_tree(\"%s\", \"%s\"): %s\n", buf,
483 pathname, strerror(errno));
491 if (tar_append_eof(t) != 0)