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