Rev 23 | Rev 32 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 23 | magnus | 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. |
||
| 7 | |||
| 8 | --- a/compat/basename.c |
||
| 9 | +++ b/compat/basename.c |
||
| 10 | @@ -34,13 +34,25 @@ static char rcsid[] = "$OpenBSD: basenam |
||
| 11 | #include <errno.h> |
||
| 12 | #include <string.h> |
||
| 13 | #include <sys/param.h> |
||
| 14 | +#include <stdlib.h> |
||
| 15 | |||
| 16 | char * |
||
| 17 | openbsd_basename(path) |
||
| 18 | const char *path; |
||
| 19 | { |
||
| 20 | - static char bname[MAXPATHLEN]; |
||
| 21 | + static char *bname = NULL; |
||
| 22 | + static size_t allocated = 0; |
||
| 23 | register const char *endp, *startp; |
||
| 24 | + int len = 0; |
||
| 25 | + |
||
| 26 | + if (!allocated) { |
||
| 27 | + allocated = 64; |
||
| 28 | + bname = malloc(allocated); |
||
| 29 | + if (!bname) { |
||
| 30 | + allocated = 0; |
||
| 31 | + return NULL; |
||
| 32 | + } |
||
| 33 | + } |
||
| 34 | |||
| 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) != '/') |
||
| 39 | startp--; |
||
| 40 | |||
| 41 | - if (endp - startp + 1 > sizeof(bname)) { |
||
| 42 | - errno = ENAMETOOLONG; |
||
| 43 | - return(NULL); |
||
| 44 | + len = endp - startp + 1; |
||
| 45 | + |
||
| 46 | + if (len + 1 > allocated) { |
||
| 47 | + size_t new_allocated = 2*(len+1); |
||
| 48 | + void *new_bname = malloc(new_allocated); |
||
| 49 | + if (!new_bname) |
||
| 50 | + return NULL; |
||
| 51 | + allocated = new_allocated; |
||
| 52 | + free(bname); |
||
| 53 | + bname = new_bname; |
||
| 54 | } |
||
| 55 | - (void)strncpy(bname, startp, endp - startp + 1); |
||
| 56 | - bname[endp - startp + 1] = '\0'; |
||
| 57 | + |
||
| 58 | + (void)strncpy(bname, startp, len); |
||
| 59 | + bname[len] = '\0'; |
||
| 60 | return(bname); |
||
| 61 | } |
||
| 62 | --- a/compat/dirname.c |
||
| 63 | +++ b/compat/dirname.c |
||
| 64 | @@ -34,13 +34,25 @@ static char rcsid[] = "$OpenBSD: dirname |
||
| 65 | #include <errno.h> |
||
| 66 | #include <string.h> |
||
| 67 | #include <sys/param.h> |
||
| 68 | +#include <stdlib.h> |
||
| 69 | |||
| 70 | char * |
||
| 71 | openbsd_dirname(path) |
||
| 72 | const char *path; |
||
| 73 | { |
||
| 74 | - static char bname[MAXPATHLEN]; |
||
| 75 | + static char *bname = NULL; |
||
| 76 | + static size_t allocated = 0; |
||
| 77 | register const char *endp; |
||
| 78 | + int len; |
||
| 79 | + |
||
| 80 | + if (!allocated) { |
||
| 81 | + allocated = 64; |
||
| 82 | + bname = malloc(allocated); |
||
| 83 | + if (!bname) { |
||
| 84 | + allocated = 0; |
||
| 85 | + return NULL; |
||
| 86 | + } |
||
| 87 | + } |
||
| 88 | |||
| 89 | /* Empty or NULL string gets treated as "." */ |
||
| 90 | if (path == NULL || *path == '\0') { |
||
| 91 | --- a/lib/append.c |
||
| 92 | +++ b/lib/append.c |
||
| 93 | @@ -38,7 +38,7 @@ typedef struct tar_dev tar_dev_t; |
||
| 94 | struct tar_ino |
||
| 95 | { |
||
| 96 | ino_t ti_ino; |
||
| 97 | - char ti_name[MAXPATHLEN]; |
||
| 98 | + char ti_name[]; |
||
| 99 | }; |
||
| 100 | typedef struct tar_ino tar_ino_t; |
||
| 101 | |||
| 102 | @@ -61,7 +61,7 @@ tar_append_file(TAR *t, const char *real |
||
| 103 | libtar_hashptr_t hp; |
||
| 104 | tar_dev_t *td = NULL; |
||
| 105 | tar_ino_t *ti = NULL; |
||
| 106 | - char path[MAXPATHLEN]; |
||
| 107 | + char *path = NULL; |
||
| 108 | |||
| 109 | #ifdef DEBUG |
||
| 110 | printf("==> tar_append_file(TAR=0x%lx (\"%s\"), realname=\"%s\", " |
||
| 111 | @@ -126,34 +126,39 @@ tar_append_file(TAR *t, const char *real |
||
| 112 | } |
||
| 113 | else |
||
| 114 | { |
||
| 115 | + const char *name; |
||
| 116 | #ifdef DEBUG |
||
| 117 | printf("+++ adding entry: device (0x%lx,0x%lx), inode %ld " |
||
| 118 | "(\"%s\")...\n", major(s.st_dev), minor(s.st_dev), |
||
| 119 | s.st_ino, realname); |
||
| 120 | #endif |
||
| 121 | - ti = (tar_ino_t *)calloc(1, sizeof(tar_ino_t)); |
||
| 122 | + name = savename ? savename : realname; |
||
| 123 | + ti = (tar_ino_t *)calloc(1, sizeof(tar_ino_t) + strlen(name) + 1); |
||
| 124 | if (ti == NULL) |
||
| 125 | return -1; |
||
| 126 | ti->ti_ino = s.st_ino; |
||
| 127 | - snprintf(ti->ti_name, sizeof(ti->ti_name), "%s", |
||
| 128 | - savename ? savename : realname); |
||
| 129 | + snprintf(ti->ti_name, strlen(name) + 1, "%s", name); |
||
| 130 | libtar_hash_add(td->td_h, ti); |
||
| 131 | } |
||
| 132 | |||
| 133 | /* check if it's a symlink */ |
||
| 134 | if (TH_ISSYM(t)) |
||
| 135 | { |
||
| 136 | - i = readlink(realname, path, sizeof(path)); |
||
| 137 | + if ((path = malloc(s.st_size + 1)) == NULL) |
||
| 138 | + return -1; |
||
| 139 | + i = readlink(realname, path, s.st_size); |
||
| 140 | if (i == -1) |
||
| 141 | + { |
||
| 142 | + free(path); |
||
| 143 | return -1; |
||
| 144 | - if (i >= MAXPATHLEN) |
||
| 145 | - i = MAXPATHLEN - 1; |
||
| 146 | + } |
||
| 147 | path[i] = '\0'; |
||
| 148 | #ifdef DEBUG |
||
| 149 | printf(" tar_append_file(): encoding symlink \"%s\" -> " |
||
| 150 | "\"%s\"...\n", realname, path); |
||
| 151 | #endif |
||
| 152 | th_set_link(t, path); |
||
| 153 | + free(path); |
||
| 154 | } |
||
| 155 | |||
| 156 | /* print file info */ |
||
| 157 | --- a/lib/decode.c |
||
| 158 | +++ b/lib/decode.c |
||
| 30 | magnus | 159 | @@ -32,7 +32,8 @@ th_get_pathname(TAR *t) |
| 23 | magnus | 160 | /* allocate the th_pathname buffer if not already */ |
| 161 | if (t->th_pathname == NULL) |
||
| 162 | { |
||
| 163 | - t->th_pathname = malloc(MAXPATHLEN * sizeof(char)); |
||
| 30 | magnus | 164 | + /* Allocate the maximum length of prefix + '/' + name + '\0' */ |
| 165 | + t->th_pathname = malloc(155 + 1 + 100 + 1); |
||
| 23 | magnus | 166 | if (t->th_pathname == NULL) |
| 167 | /* out of memory */ |
||
| 168 | return NULL; |
||
| 30 | magnus | 169 | @@ -40,11 +41,11 @@ th_get_pathname(TAR *t) |
| 23 | magnus | 170 | |
| 171 | if (t->th_buf.prefix[0] == '\0') |
||
| 172 | { |
||
| 173 | - snprintf(t->th_pathname, MAXPATHLEN, "%.100s", t->th_buf.name); |
||
| 30 | magnus | 174 | + sprintf(t->th_pathname, "%.100s", t->th_buf.name); |
| 23 | magnus | 175 | } |
| 176 | else |
||
| 177 | { |
||
| 178 | - snprintf(t->th_pathname, MAXPATHLEN, "%.155s/%.100s", |
||
| 30 | magnus | 179 | + sprintf(t->th_pathname, "%.155s/%.100s", |
| 23 | magnus | 180 | t->th_buf.prefix, t->th_buf.name); |
| 181 | } |
||
| 182 | |||
| 183 | --- a/lib/util.c |
||
| 184 | +++ b/lib/util.c |
||
| 185 | @@ -15,6 +15,7 @@ |
||
| 186 | #include <stdio.h> |
||
| 187 | #include <sys/param.h> |
||
| 188 | #include <errno.h> |
||
| 189 | +#include <stdlib.h> |
||
| 190 | |||
| 191 | #ifdef STDC_HEADERS |
||
| 192 | # include <string.h> |
||
| 193 | @@ -25,13 +26,15 @@ |
||
| 194 | int |
||
| 195 | path_hashfunc(char *key, int numbuckets) |
||
| 196 | { |
||
| 197 | - char buf[MAXPATHLEN]; |
||
| 198 | + char *buf; |
||
| 199 | char *p; |
||
| 200 | + int i; |
||
| 201 | |||
| 202 | - strcpy(buf, key); |
||
| 203 | + buf = strdup(key); |
||
| 204 | p = basename(buf); |
||
| 205 | - |
||
| 206 | - return (((unsigned int)p[0]) % numbuckets); |
||
| 207 | + i = ((unsigned int)p[0]) % numbuckets; |
||
| 208 | + free(buf); |
||
| 209 | + return (i); |
||
| 210 | } |
||
| 211 | |||
| 212 | |||
| 213 | @@ -77,15 +80,26 @@ ino_hash(ino_t *inode) |
||
| 214 | int |
||
| 215 | mkdirhier(char *path) |
||
| 216 | { |
||
| 217 | - char src[MAXPATHLEN], dst[MAXPATHLEN] = ""; |
||
| 218 | - char *dirp, *nextp = src; |
||
| 219 | - int retval = 1; |
||
| 220 | + char *src, *dst = NULL; |
||
| 221 | + char *dirp, *nextp = NULL; |
||
| 222 | + int retval = 1, len; |
||
| 223 | + |
||
| 224 | + len = strlen(path); |
||
| 225 | + if ((src = strdup(path)) == NULL) |
||
| 226 | + { |
||
| 227 | + errno = ENOMEM; |
||
| 228 | + return -1; |
||
| 229 | + } |
||
| 230 | + nextp = src; |
||
| 231 | |||
| 232 | - if (strlcpy(src, path, sizeof(src)) > sizeof(src)) |
||
| 233 | + /* Make room for // with absolute paths */ |
||
| 234 | + if ((dst = malloc(len + 2)) == NULL) |
||
| 235 | { |
||
| 236 | - errno = ENAMETOOLONG; |
||
| 237 | + free(src); |
||
| 238 | + errno = ENOMEM; |
||
| 239 | return -1; |
||
| 240 | } |
||
| 241 | + dst[0] = '\0'; |
||
| 242 | |||
| 243 | if (path[0] == '/') |
||
| 244 | strcpy(dst, "/"); |
||
| 245 | @@ -102,12 +116,18 @@ mkdirhier(char *path) |
||
| 246 | if (mkdir(dst, 0777) == -1) |
||
| 247 | { |
||
| 248 | if (errno != EEXIST) |
||
| 249 | + { |
||
| 250 | + free(src); |
||
| 251 | + free(dst); |
||
| 252 | return -1; |
||
| 253 | + } |
||
| 254 | } |
||
| 255 | else |
||
| 256 | retval = 0; |
||
| 257 | } |
||
| 258 | |||
| 259 | + free(src); |
||
| 260 | + free(dst); |
||
| 261 | return retval; |
||
| 262 | } |
||
| 263 | |||
| 264 | --- a/lib/wrapper.c |
||
| 265 | +++ b/lib/wrapper.c |
||
| 30 | magnus | 266 | @@ -16,6 +16,7 @@ |
| 23 | magnus | 267 | #include <sys/param.h> |
| 268 | #include <dirent.h> |
||
| 269 | #include <errno.h> |
||
| 270 | +#include <stdlib.h> |
||
| 271 | |||
| 272 | #ifdef STDC_HEADERS |
||
| 273 | # include <string.h> |
||
| 30 | magnus | 274 | @@ -26,8 +27,8 @@ int |
| 23 | magnus | 275 | tar_extract_glob(TAR *t, char *globname, char *prefix) |
| 276 | { |
||
| 277 | char *filename; |
||
| 278 | - char buf[MAXPATHLEN]; |
||
| 279 | - int i; |
||
| 280 | + char *buf = NULL; |
||
| 281 | + int i, len; |
||
| 282 | |||
| 283 | while ((i = th_read(t)) == 0) |
||
| 284 | { |
||
| 30 | magnus | 285 | @@ -41,11 +42,25 @@ tar_extract_glob(TAR *t, char *globname, |
| 23 | magnus | 286 | if (t->options & TAR_VERBOSE) |
| 287 | th_print_long_ls(t); |
||
| 288 | if (prefix != NULL) |
||
| 289 | - snprintf(buf, sizeof(buf), "%s/%s", prefix, filename); |
||
| 290 | + { |
||
| 291 | + len = strlen(prefix) + 1 + strlen(filename); |
||
| 292 | + if ((buf = malloc(len + 1)) == NULL) |
||
| 293 | + return -1; |
||
| 294 | + sprintf(buf, "%s/%s", prefix, filename); |
||
| 295 | + } |
||
| 296 | else |
||
| 297 | - strlcpy(buf, filename, sizeof(buf)); |
||
| 298 | + { |
||
| 299 | + len = strlen(filename); |
||
| 300 | + if ((buf = malloc(len + 1)) == NULL) |
||
| 301 | + return -1; |
||
| 302 | + strcpy(buf, filename); |
||
| 303 | + } |
||
| 304 | if (tar_extract_file(t, buf) != 0) |
||
| 305 | + { |
||
| 306 | + free(buf); |
||
| 307 | return -1; |
||
| 308 | + } |
||
| 309 | + free(buf); |
||
| 310 | } |
||
| 311 | |||
| 312 | return (i == 1 ? 0 : -1); |
||
| 30 | magnus | 313 | @@ -56,8 +71,9 @@ int |
| 23 | magnus | 314 | tar_extract_all(TAR *t, char *prefix) |
| 315 | { |
||
| 316 | char *filename; |
||
| 317 | - char buf[MAXPATHLEN]; |
||
| 318 | - int i; |
||
| 319 | + char *buf = NULL; |
||
| 320 | + size_t bufsize = 0; |
||
| 321 | + int i, len; |
||
| 322 | |||
| 323 | #ifdef DEBUG |
||
| 324 | printf("==> tar_extract_all(TAR *t, \"%s\")\n", |
||
| 30 | magnus | 325 | @@ -73,15 +89,29 @@ tar_extract_all(TAR *t, char *prefix) |
| 23 | magnus | 326 | if (t->options & TAR_VERBOSE) |
| 327 | th_print_long_ls(t); |
||
| 328 | if (prefix != NULL) |
||
| 329 | - snprintf(buf, sizeof(buf), "%s/%s", prefix, filename); |
||
| 330 | + { |
||
| 331 | + len = strlen(prefix) + 1 + strlen(filename); |
||
| 332 | + if ((buf = malloc(len + 1)) == NULL) |
||
| 333 | + return -1; |
||
| 334 | + sprintf(buf, "%s/%s", prefix, filename); |
||
| 335 | + } |
||
| 336 | else |
||
| 337 | - strlcpy(buf, filename, sizeof(buf)); |
||
| 338 | + { |
||
| 339 | + len = strlen(filename); |
||
| 340 | + if ((buf = malloc(len + 1)) == NULL) |
||
| 341 | + return -1; |
||
| 342 | + strcpy(buf, filename); |
||
| 343 | + } |
||
| 344 | #ifdef DEBUG |
||
| 345 | printf(" tar_extract_all(): calling tar_extract_file(t, " |
||
| 346 | "\"%s\")\n", buf); |
||
| 347 | #endif |
||
| 348 | if (tar_extract_file(t, buf) != 0) |
||
| 349 | + { |
||
| 350 | + free(buf); |
||
| 351 | return -1; |
||
| 352 | + } |
||
| 353 | + free(buf); |
||
| 354 | } |
||
| 355 | |||
| 356 | return (i == 1 ? 0 : -1); |
||
| 357 | @@ -91,11 +121,14 @@ tar_extract_all(TAR *t, char *prefix) |
||
| 358 | int |
||
| 359 | tar_append_tree(TAR *t, char *realdir, char *savedir) |
||
| 360 | { |
||
| 361 | - char realpath[MAXPATHLEN]; |
||
| 362 | - char savepath[MAXPATHLEN]; |
||
| 363 | + char *realpath = NULL; |
||
| 364 | + size_t realpathsize = 0; |
||
| 365 | + char *savepath = NULL; |
||
| 366 | + size_t savepathsize = 0; |
||
| 367 | struct dirent *dent; |
||
| 368 | DIR *dp; |
||
| 369 | struct stat s; |
||
| 370 | + int len; |
||
| 371 | |||
| 372 | #ifdef DEBUG |
||
| 373 | printf("==> tar_append_tree(0x%lx, \"%s\", \"%s\")\n", |
||
| 30 | magnus | 374 | @@ -122,11 +155,21 @@ tar_append_tree(TAR *t, char *realdir, c |
| 23 | magnus | 375 | strcmp(dent->d_name, "..") == 0) |
| 376 | continue; |
||
| 377 | |||
| 378 | - snprintf(realpath, MAXPATHLEN, "%s/%s", realdir, |
||
| 379 | + len = strlen(realdir) + 1 + strlen(dent->d_name); |
||
| 380 | + if ((realpath = malloc(len + 1)) == NULL) |
||
| 381 | + return -1; |
||
| 382 | + snprintf(realpath, len + 1, "%s/%s", realdir, |
||
| 383 | dent->d_name); |
||
| 384 | if (savedir) |
||
| 385 | - snprintf(savepath, MAXPATHLEN, "%s/%s", savedir, |
||
| 386 | + { |
||
| 387 | + len = strlen(savedir) + 1 + strlen(dent->d_name); |
||
| 30 | magnus | 388 | + if ((savepath = malloc(len + 1)) == NULL) { |
| 389 | + free(realpath); |
||
| 23 | magnus | 390 | + return -1; |
| 30 | magnus | 391 | + } |
| 392 | + snprintf(savepath, len + 1, "%s/%s", savedir, |
||
| 23 | magnus | 393 | dent->d_name); |
| 394 | + } |
||
| 395 | |||
| 396 | if (lstat(realpath, &s) != 0) |
||
| 397 | return -1; |
||
| 30 | magnus | 398 | @@ -135,13 +178,23 @@ tar_append_tree(TAR *t, char *realdir, c |
| 23 | magnus | 399 | { |
| 400 | if (tar_append_tree(t, realpath, |
||
| 401 | (savedir ? savepath : NULL)) != 0) |
||
| 402 | + { |
||
| 403 | + free(realpath); |
||
| 404 | + free(savepath); |
||
| 405 | return -1; |
||
| 406 | + } |
||
| 407 | continue; |
||
| 408 | } |
||
| 409 | |||
| 410 | if (tar_append_file(t, realpath, |
||
| 411 | (savedir ? savepath : NULL)) != 0) |
||
| 412 | + { |
||
| 413 | + free(realpath); |
||
| 414 | + free(savepath); |
||
| 415 | return -1; |
||
| 416 | + } |
||
| 417 | + free(realpath); |
||
| 418 | + free(savepath); |
||
| 419 | } |
||
| 420 | |||
| 421 | closedir(dp); |
||
| 422 | --- a/libtar/libtar.c |
||
| 423 | +++ b/libtar/libtar.c |
||
| 424 | @@ -111,8 +111,9 @@ create(char *tarfile, char *rootdir, lib |
||
| 425 | { |
||
| 426 | TAR *t; |
||
| 427 | char *pathname; |
||
| 428 | - char buf[MAXPATHLEN]; |
||
| 429 | + char *buf = NULL; |
||
| 430 | libtar_listptr_t lp; |
||
| 431 | + int len; |
||
| 432 | |||
| 433 | if (tar_open(&t, tarfile, |
||
| 434 | #ifdef HAVE_LIBZ |
||
| 435 | @@ -133,17 +134,29 @@ create(char *tarfile, char *rootdir, lib |
||
| 436 | { |
||
| 437 | pathname = (char *)libtar_listptr_data(&lp); |
||
| 438 | if (pathname[0] != '/' && rootdir != NULL) |
||
| 439 | - snprintf(buf, sizeof(buf), "%s/%s", rootdir, pathname); |
||
| 440 | + { |
||
| 441 | + len = strlen(rootdir) + 1 + strlen(pathname); |
||
| 442 | + if ((buf = malloc(len + 1)) == NULL) |
||
| 443 | + return -1; |
||
| 444 | + snprintf(buf, len + 1, "%s/%s", rootdir, pathname); |
||
| 445 | + } |
||
| 446 | else |
||
| 447 | - strlcpy(buf, pathname, sizeof(buf)); |
||
| 448 | + { |
||
| 449 | + len = strlen(pathname); |
||
| 450 | + if ((buf = malloc(len + 1)) == NULL) |
||
| 451 | + return -1; |
||
| 452 | + strlcpy(buf, pathname, len + 1); |
||
| 453 | + } |
||
| 454 | if (tar_append_tree(t, buf, pathname) != 0) |
||
| 455 | { |
||
| 456 | fprintf(stderr, |
||
| 457 | "tar_append_tree(\"%s\", \"%s\"): %s\n", buf, |
||
| 458 | pathname, strerror(errno)); |
||
| 459 | tar_close(t); |
||
| 460 | + free(buf); |
||
| 461 | return -1; |
||
| 462 | } |
||
| 463 | + free(buf); |
||
| 464 | } |
||
| 465 | |||
| 466 | if (tar_append_eof(t) != 0) |