aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-12-09 09:04:58 +0000
committerRon Yorston <rmy@pobox.com>2017-12-09 09:04:58 +0000
commitbcf14b82e442e797fdd370afc80a82ef295ac1b0 (patch)
tree133c2b3df5445c508953fee17576ed932af07c7a
parent65e9c0ad92a316e36efbc584b72b96a7eb8fa9db (diff)
parenta07fead8235c479f428dd5265e4f3539abb9c3fe (diff)
downloadbusybox-w32-bcf14b82e442e797fdd370afc80a82ef295ac1b0.tar.gz
busybox-w32-bcf14b82e442e797fdd370afc80a82ef295ac1b0.tar.bz2
busybox-w32-bcf14b82e442e797fdd370afc80a82ef295ac1b0.zip
Merge branch 'busybox' into merge
-rw-r--r--archival/tar.c168
-rw-r--r--archival/unzip.c17
-rw-r--r--libbb/lineedit.c16
-rw-r--r--networking/inetd.c2
-rw-r--r--util-linux/unshare.c8
5 files changed, 115 insertions, 96 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 6332bb6ee..be688a81d 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -49,7 +49,7 @@
49//config: tarballs. Currently it works only on files (not pipes etc). 49//config: tarballs. Currently it works only on files (not pipes etc).
50//config: 50//config:
51//config:config FEATURE_TAR_FROM 51//config:config FEATURE_TAR_FROM
52//config: bool "Enable -X (exclude from) and -T (include from) options)" 52//config: bool "Enable -X (exclude from) and -T (include from) options"
53//config: default y 53//config: default y
54//config: depends on TAR 54//config: depends on TAR
55//config: help 55//config: help
@@ -156,7 +156,9 @@ typedef struct TarBallInfo {
156 int tarFd; /* Open-for-write file descriptor 156 int tarFd; /* Open-for-write file descriptor
157 * for the tarball */ 157 * for the tarball */
158 int verboseFlag; /* Whether to print extra stuff or not */ 158 int verboseFlag; /* Whether to print extra stuff or not */
159# if ENABLE_FEATURE_TAR_FROM
159 const llist_t *excludeList; /* List of files to not include */ 160 const llist_t *excludeList; /* List of files to not include */
161# endif
160 HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */ 162 HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
161 HardLinkInfo *hlInfo; /* Hard Link Info for the current file */ 163 HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
162//TODO: save only st_dev + st_ino 164//TODO: save only st_dev + st_ino
@@ -278,7 +280,7 @@ static void chksum_and_xwrite(int fd, struct tar_header_t* hp)
278 xwrite(fd, hp, sizeof(*hp)); 280 xwrite(fd, hp, sizeof(*hp));
279} 281}
280 282
281#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS 283# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
282static void writeLongname(int fd, int type, const char *name, int dir) 284static void writeLongname(int fd, int type, const char *name, int dir)
283{ 285{
284 static const struct { 286 static const struct {
@@ -318,7 +320,7 @@ static void writeLongname(int fd, int type, const char *name, int dir)
318 memset(&header, 0, size); 320 memset(&header, 0, size);
319 xwrite(fd, &header, size); 321 xwrite(fd, &header, size);
320} 322}
321#endif 323# endif
322 324
323/* Write out a tar header for the specified file/directory/whatever */ 325/* Write out a tar header for the specified file/directory/whatever */
324static int writeTarHeader(struct TarBallInfo *tbInfo, 326static int writeTarHeader(struct TarBallInfo *tbInfo,
@@ -347,30 +349,30 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
347 header.typeflag = LNKTYPE; 349 header.typeflag = LNKTYPE;
348 strncpy(header.linkname, tbInfo->hlInfo->name, 350 strncpy(header.linkname, tbInfo->hlInfo->name,
349 sizeof(header.linkname)); 351 sizeof(header.linkname));
350#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS 352# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
351 /* Write out long linkname if needed */ 353 /* Write out long linkname if needed */
352 if (header.linkname[sizeof(header.linkname)-1]) 354 if (header.linkname[sizeof(header.linkname)-1])
353 writeLongname(tbInfo->tarFd, GNULONGLINK, 355 writeLongname(tbInfo->tarFd, GNULONGLINK,
354 tbInfo->hlInfo->name, 0); 356 tbInfo->hlInfo->name, 0);
355#endif 357# endif
356 } else if (S_ISLNK(statbuf->st_mode)) { 358 } else if (S_ISLNK(statbuf->st_mode)) {
357 char *lpath = xmalloc_readlink_or_warn(fileName); 359 char *lpath = xmalloc_readlink_or_warn(fileName);
358 if (!lpath) 360 if (!lpath)
359 return FALSE; 361 return FALSE;
360 header.typeflag = SYMTYPE; 362 header.typeflag = SYMTYPE;
361 strncpy(header.linkname, lpath, sizeof(header.linkname)); 363 strncpy(header.linkname, lpath, sizeof(header.linkname));
362#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS 364# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
363 /* Write out long linkname if needed */ 365 /* Write out long linkname if needed */
364 if (header.linkname[sizeof(header.linkname)-1]) 366 if (header.linkname[sizeof(header.linkname)-1])
365 writeLongname(tbInfo->tarFd, GNULONGLINK, lpath, 0); 367 writeLongname(tbInfo->tarFd, GNULONGLINK, lpath, 0);
366#else 368# else
367 /* If it is larger than 100 bytes, bail out */ 369 /* If it is larger than 100 bytes, bail out */
368 if (header.linkname[sizeof(header.linkname)-1]) { 370 if (header.linkname[sizeof(header.linkname)-1]) {
369 free(lpath); 371 free(lpath);
370 bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported"); 372 bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
371 return FALSE; 373 return FALSE;
372 } 374 }
373#endif 375# endif
374 free(lpath); 376 free(lpath);
375 } else if (S_ISDIR(statbuf->st_mode)) { 377 } else if (S_ISDIR(statbuf->st_mode)) {
376 header.typeflag = DIRTYPE; 378 header.typeflag = DIRTYPE;
@@ -400,9 +402,9 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
400 * It always does unless off_t is wider than 64 bits. 402 * It always does unless off_t is wider than 64 bits.
401 */ 403 */
402 else if (ENABLE_FEATURE_TAR_GNU_EXTENSIONS 404 else if (ENABLE_FEATURE_TAR_GNU_EXTENSIONS
403#if ULLONG_MAX > 0xffffffffffffffffLL /* 2^64-1 */ 405# if ULLONG_MAX > 0xffffffffffffffffLL /* 2^64-1 */
404 && (filesize <= 0x3fffffffffffffffffffffffLL) 406 && (filesize <= 0x3fffffffffffffffffffffffLL)
405#endif 407# endif
406 ) { 408 ) {
407 /* GNU tar uses "base-256 encoding" for very large numbers. 409 /* GNU tar uses "base-256 encoding" for very large numbers.
408 * Encoding is binary, with highest bit always set as a marker 410 * Encoding is binary, with highest bit always set as a marker
@@ -429,13 +431,13 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
429 return FALSE; 431 return FALSE;
430 } 432 }
431 433
432#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS 434# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
433 /* Write out long name if needed */ 435 /* Write out long name if needed */
434 /* (we, like GNU tar, output long linkname *before* long name) */ 436 /* (we, like GNU tar, output long linkname *before* long name) */
435 if (header.name[sizeof(header.name)-1]) 437 if (header.name[sizeof(header.name)-1])
436 writeLongname(tbInfo->tarFd, GNULONGNAME, 438 writeLongname(tbInfo->tarFd, GNULONGNAME,
437 header_name, S_ISDIR(statbuf->st_mode)); 439 header_name, S_ISDIR(statbuf->st_mode));
438#endif 440# endif
439 441
440 /* Now write the header out to disk */ 442 /* Now write the header out to disk */
441 chksum_and_xwrite(tbInfo->tarFd, &header); 443 chksum_and_xwrite(tbInfo->tarFd, &header);
@@ -457,7 +459,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
457 return TRUE; 459 return TRUE;
458} 460}
459 461
460#if ENABLE_FEATURE_TAR_FROM 462# if ENABLE_FEATURE_TAR_FROM
461static int exclude_file(const llist_t *excluded_files, const char *file) 463static int exclude_file(const llist_t *excluded_files, const char *file)
462{ 464{
463 while (excluded_files) { 465 while (excluded_files) {
@@ -483,9 +485,9 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
483 485
484 return 0; 486 return 0;
485} 487}
486#else 488# else
487# define exclude_file(excluded_files, file) 0 489# define exclude_file(excluded_files, file) 0
488#endif 490# endif
489 491
490static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statbuf, 492static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statbuf,
491 void *userData, int depth UNUSED_PARAM) 493 void *userData, int depth UNUSED_PARAM)
@@ -540,12 +542,12 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
540 if (exclude_file(tbInfo->excludeList, header_name)) 542 if (exclude_file(tbInfo->excludeList, header_name))
541 return SKIP; 543 return SKIP;
542 544
543#if !ENABLE_FEATURE_TAR_GNU_EXTENSIONS 545# if !ENABLE_FEATURE_TAR_GNU_EXTENSIONS
544 if (strlen(header_name) >= NAME_SIZE) { 546 if (strlen(header_name) >= NAME_SIZE) {
545 bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported"); 547 bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
546 return TRUE; 548 return TRUE;
547 } 549 }
548#endif 550# endif
549 551
550 /* Is this a regular file? */ 552 /* Is this a regular file? */
551 if (tbInfo->hlInfo == NULL && S_ISREG(statbuf->st_mode)) { 553 if (tbInfo->hlInfo == NULL && S_ISREG(statbuf->st_mode)) {
@@ -601,13 +603,13 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
601 603
602 // On Linux, vfork never unpauses parent early, although standard 604 // On Linux, vfork never unpauses parent early, although standard
603 // allows for that. Do we want to waste bytes checking for it? 605 // allows for that. Do we want to waste bytes checking for it?
604# define WAIT_FOR_CHILD 0 606# define WAIT_FOR_CHILD 0
605 volatile int vfork_exec_errno = 0; 607 volatile int vfork_exec_errno = 0;
606 struct fd_pair gzipDataPipe; 608 struct fd_pair gzipDataPipe;
607# if WAIT_FOR_CHILD 609# if WAIT_FOR_CHILD
608 struct fd_pair gzipStatusPipe; 610 struct fd_pair gzipStatusPipe;
609 xpiped_pair(gzipStatusPipe); 611 xpiped_pair(gzipStatusPipe);
610# endif 612# endif
611 xpiped_pair(gzipDataPipe); 613 xpiped_pair(gzipDataPipe);
612 614
613 signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */ 615 signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
@@ -618,12 +620,12 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
618 /* child */ 620 /* child */
619 /* NB: close _first_, then move fds! */ 621 /* NB: close _first_, then move fds! */
620 close(gzipDataPipe.wr); 622 close(gzipDataPipe.wr);
621# if WAIT_FOR_CHILD 623# if WAIT_FOR_CHILD
622 close(gzipStatusPipe.rd); 624 close(gzipStatusPipe.rd);
623 /* gzipStatusPipe.wr will close only on exec - 625 /* gzipStatusPipe.wr will close only on exec -
624 * parent waits for this close to happen */ 626 * parent waits for this close to happen */
625 fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC); 627 fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC);
626# endif 628# endif
627 xmove_fd(gzipDataPipe.rd, 0); 629 xmove_fd(gzipDataPipe.rd, 0);
628 xmove_fd(tar_fd, 1); 630 xmove_fd(tar_fd, 1);
629 /* exec gzip/bzip2 program/applet */ 631 /* exec gzip/bzip2 program/applet */
@@ -635,7 +637,7 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
635 /* parent */ 637 /* parent */
636 xmove_fd(gzipDataPipe.wr, tar_fd); 638 xmove_fd(gzipDataPipe.wr, tar_fd);
637 close(gzipDataPipe.rd); 639 close(gzipDataPipe.rd);
638# if WAIT_FOR_CHILD 640# if WAIT_FOR_CHILD
639 close(gzipStatusPipe.wr); 641 close(gzipStatusPipe.wr);
640 while (1) { 642 while (1) {
641 char buf; 643 char buf;
@@ -647,7 +649,7 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
647 continue; /* try it again */ 649 continue; /* try it again */
648 } 650 }
649 close(gzipStatusPipe.rd); 651 close(gzipStatusPipe.rd);
650# endif 652# endif
651 if (vfork_exec_errno) { 653 if (vfork_exec_errno) {
652 errno = vfork_exec_errno; 654 errno = vfork_exec_errno;
653 bb_perror_msg_and_die("can't execute '%s'", gzip); 655 bb_perror_msg_and_die("can't execute '%s'", gzip);
@@ -677,47 +679,44 @@ static pid_t vfork_compressor(int tar_fd, const char *gzip)
677#endif /* SEAMLESS_COMPRESSION */ 679#endif /* SEAMLESS_COMPRESSION */
678 680
679 681
680#if !SEAMLESS_COMPRESSION 682# if !SEAMLESS_COMPRESSION
681/* Do not pass gzip flag to writeTarFile() */ 683/* Do not pass gzip flag to writeTarFile() */
682#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \ 684#define writeTarFile(tbInfo, recurseFlags, filelist, gzip) \
683 writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude) 685 writeTarFile(tbInfo, recurseFlags, filelist)
684#endif 686# endif
685/* gcc 4.2.1 inlines it, making code bigger */ 687/* gcc 4.2.1 inlines it, making code bigger */
686static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, 688static NOINLINE int writeTarFile(
687 int recurseFlags, const llist_t *include, 689 struct TarBallInfo *tbInfo,
688 const llist_t *exclude, const char *gzip) 690 int recurseFlags,
691 const llist_t *filelist,
692 const char *gzip)
689{ 693{
690 int errorFlag = FALSE; 694 int errorFlag = FALSE;
691 struct TarBallInfo tbInfo;
692 IF_PLATFORM_MINGW32(pid_t pid = 0;) 695 IF_PLATFORM_MINGW32(pid_t pid = 0;)
693 696
694 tbInfo.hlInfoHead = NULL; 697 /*tbInfo->hlInfoHead = NULL; - already is */
695 tbInfo.tarFd = tar_fd;
696 tbInfo.verboseFlag = verboseFlag;
697 698
698 /* Store the stat info for the tarball's file, so 699 /* Store the stat info for the tarball's file, so
699 * can avoid including the tarball into itself.... */ 700 * can avoid including the tarball into itself.... */
700 xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file"); 701 xfstat(tbInfo->tarFd, &tbInfo->tarFileStatBuf, "can't stat tar file");
701 702
702#if SEAMLESS_COMPRESSION 703# if SEAMLESS_COMPRESSION
703 if (gzip) 704 if (gzip)
704 IF_PLATFORM_MINGW32(pid = )vfork_compressor(tbInfo.tarFd, gzip); 705 IF_PLATFORM_MINGW32(pid = )vfork_compressor(tbInfo->tarFd, gzip);
705#endif 706#endif
706 707
707 tbInfo.excludeList = exclude;
708
709 /* Read the directory/files and iterate over them one at a time */ 708 /* Read the directory/files and iterate over them one at a time */
710 while (include) { 709 while (filelist) {
711 if (!recursive_action(include->data, recurseFlags, 710 if (!recursive_action(filelist->data, recurseFlags,
712 writeFileToTarball, writeFileToTarball, &tbInfo, 0) 711 writeFileToTarball, writeFileToTarball, tbInfo, 0)
713 ) { 712 ) {
714 errorFlag = TRUE; 713 errorFlag = TRUE;
715 } 714 }
716 include = include->link; 715 filelist = filelist->link;
717 } 716 }
718 /* Write two empty blocks to the end of the archive */ 717 /* Write two empty blocks to the end of the archive */
719 memset(block_buf, 0, 2*TAR_BLOCK_SIZE); 718 memset(block_buf, 0, 2*TAR_BLOCK_SIZE);
720 xwrite(tbInfo.tarFd, block_buf, 2*TAR_BLOCK_SIZE); 719 xwrite(tbInfo->tarFd, block_buf, 2*TAR_BLOCK_SIZE);
721 720
722 /* To be pedantically correct, we would check if the tarball 721 /* To be pedantically correct, we would check if the tarball
723 * is smaller than 20 tar blocks, and pad it if it was smaller, 722 * is smaller than 20 tar blocks, and pad it if it was smaller,
@@ -725,16 +724,16 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
725 * so is considered a waste of space */ 724 * so is considered a waste of space */
726 725
727 /* Close so the child process (if any) will exit */ 726 /* Close so the child process (if any) will exit */
728 close(tbInfo.tarFd); 727 close(tbInfo->tarFd);
729 728
730 /* Hang up the tools, close up shop, head home */ 729 /* Hang up the tools, close up shop, head home */
731 if (ENABLE_FEATURE_CLEAN_UP) 730 if (ENABLE_FEATURE_CLEAN_UP)
732 freeHardLinkInfo(&tbInfo.hlInfoHead); 731 freeHardLinkInfo(&tbInfo->hlInfoHead);
733 732
734 if (errorFlag) 733 if (errorFlag)
735 bb_error_msg("error exit delayed from previous errors"); 734 bb_error_msg("error exit delayed from previous errors");
736 735
737#if SEAMLESS_COMPRESSION 736# if SEAMLESS_COMPRESSION
738 if (gzip) { 737 if (gzip) {
739 int status; 738 int status;
740#if !ENABLE_PLATFORM_MINGW32 739#if !ENABLE_PLATFORM_MINGW32
@@ -747,21 +746,25 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
747 /* gzip was killed or has exited with nonzero! */ 746 /* gzip was killed or has exited with nonzero! */
748 errorFlag = TRUE; 747 errorFlag = TRUE;
749 } 748 }
750#endif 749# endif
751 return errorFlag; 750 return errorFlag;
752} 751}
752
753#else /* !FEATURE_TAR_CREATE */ 753#else /* !FEATURE_TAR_CREATE */
754
754# define writeTarFile(...) 0 755# define writeTarFile(...) 0
756
755#endif 757#endif
756 758
757#if ENABLE_FEATURE_TAR_FROM 759#if ENABLE_FEATURE_TAR_FROM
758static llist_t *append_file_list_to_list(llist_t *list) 760static llist_t *append_file_list_to_list(llist_t *list)
759{ 761{
760 FILE *src_stream;
761 char *line;
762 llist_t *newlist = NULL; 762 llist_t *newlist = NULL;
763 763
764 while (list) { 764 while (list) {
765 FILE *src_stream;
766 char *line;
767
765 src_stream = xfopen_stdin(llist_pop(&list)); 768 src_stream = xfopen_stdin(llist_pop(&list));
766 while ((line = xmalloc_fgetline(src_stream)) != NULL) { 769 while ((line = xmalloc_fgetline(src_stream)) != NULL) {
767 /* kill trailing '/' unless the string is just "/" */ 770 /* kill trailing '/' unless the string is just "/" */
@@ -777,7 +780,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
777#endif 780#endif
778 781
779//usage:#define tar_trivial_usage 782//usage:#define tar_trivial_usage
780//usage: "-[" IF_FEATURE_TAR_CREATE("c") "xt" 783//usage: IF_FEATURE_TAR_CREATE("c|") "x|t [-"
781//usage: IF_FEATURE_SEAMLESS_Z("Z") 784//usage: IF_FEATURE_SEAMLESS_Z("Z")
782//usage: IF_FEATURE_SEAMLESS_GZ("z") 785//usage: IF_FEATURE_SEAMLESS_GZ("z")
783//usage: IF_FEATURE_SEAMLESS_XZ("J") 786//usage: IF_FEATURE_SEAMLESS_XZ("J")
@@ -786,8 +789,9 @@ static llist_t *append_file_list_to_list(llist_t *list)
786//usage: IF_FEATURE_TAR_CREATE("h") 789//usage: IF_FEATURE_TAR_CREATE("h")
787//usage: IF_FEATURE_TAR_NOPRESERVE_TIME("m") 790//usage: IF_FEATURE_TAR_NOPRESERVE_TIME("m")
788//usage: "vO] " 791//usage: "vO] "
789//usage: IF_FEATURE_TAR_FROM("[-X FILE] [-T FILE] ") 792//usage: "[-f TARFILE] [-C DIR] "
790//usage: "[-f TARFILE] [-C DIR] [FILE]..." 793//usage: IF_FEATURE_TAR_FROM("[-T FILE] [-X FILE] "IF_FEATURE_TAR_LONG_OPTIONS("[--exclude PATTERN]... "))
794//usage: "[FILE]..."
791//usage:#define tar_full_usage "\n\n" 795//usage:#define tar_full_usage "\n\n"
792//usage: IF_FEATURE_TAR_CREATE("Create, extract, ") 796//usage: IF_FEATURE_TAR_CREATE("Create, extract, ")
793//usage: IF_NOT_FEATURE_TAR_CREATE("Extract ") 797//usage: IF_NOT_FEATURE_TAR_CREATE("Extract ")
@@ -798,37 +802,37 @@ static llist_t *append_file_list_to_list(llist_t *list)
798//usage: ) 802//usage: )
799//usage: "\n x Extract" 803//usage: "\n x Extract"
800//usage: "\n t List" 804//usage: "\n t List"
801//usage: "\n f Name of TARFILE ('-' for stdin/out)" 805//usage: "\n -f FILE Name of TARFILE ('-' for stdin/out)"
802//usage: "\n C Change to DIR before operation" 806//usage: "\n -C DIR Change to DIR before operation"
803//usage: "\n v Verbose" 807//usage: "\n -v Verbose"
804//usage: IF_FEATURE_SEAMLESS_Z( 808//usage: IF_FEATURE_SEAMLESS_Z(
805//usage: "\n Z (De)compress using compress" 809//usage: "\n -Z (De)compress using compress"
806//usage: ) 810//usage: )
807//usage: IF_FEATURE_SEAMLESS_GZ( 811//usage: IF_FEATURE_SEAMLESS_GZ(
808//usage: "\n z (De)compress using gzip" 812//usage: "\n -z (De)compress using gzip"
809//usage: ) 813//usage: )
810//usage: IF_FEATURE_SEAMLESS_XZ( 814//usage: IF_FEATURE_SEAMLESS_XZ(
811//usage: "\n J (De)compress using xz" 815//usage: "\n -J (De)compress using xz"
812//usage: ) 816//usage: )
813//usage: IF_FEATURE_SEAMLESS_BZ2( 817//usage: IF_FEATURE_SEAMLESS_BZ2(
814//usage: "\n j (De)compress using bzip2" 818//usage: "\n -j (De)compress using bzip2"
815//usage: ) 819//usage: )
816//usage: IF_FEATURE_SEAMLESS_LZMA( 820//usage: IF_FEATURE_SEAMLESS_LZMA(
817//usage: "\n a (De)compress using lzma" 821//usage: "\n -a (De)compress using lzma"
818//usage: ) 822//usage: )
819//usage: "\n O Extract to stdout" 823//usage: "\n -O Extract to stdout"
820//usage: IF_FEATURE_TAR_CREATE( 824//usage: IF_FEATURE_TAR_CREATE(
821//usage: "\n h Follow symlinks" 825//usage: "\n -h Follow symlinks"
822//usage: ) 826//usage: )
823//usage: IF_FEATURE_TAR_NOPRESERVE_TIME( 827//usage: IF_FEATURE_TAR_NOPRESERVE_TIME(
824//usage: "\n m Don't restore mtime" 828//usage: "\n -m Don't restore mtime"
825//usage: ) 829//usage: )
826//usage: IF_FEATURE_TAR_FROM( 830//usage: IF_FEATURE_TAR_FROM(
831//usage: "\n -T FILE File with names to include"
832//usage: "\n -X FILE File with glob patterns to exclude"
827//usage: IF_FEATURE_TAR_LONG_OPTIONS( 833//usage: IF_FEATURE_TAR_LONG_OPTIONS(
828//usage: "\n exclude File to exclude" 834//usage: "\n --exclude PATTERN Glob pattern to exclude"
829//usage: ) 835//usage: )
830//usage: "\n X File with names to exclude"
831//usage: "\n T File with names to include"
832//usage: ) 836//usage: )
833//usage: 837//usage:
834//usage:#define tar_example_usage 838//usage:#define tar_example_usage
@@ -992,11 +996,12 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
992 puts("tar (busybox) " BB_VER); 996 puts("tar (busybox) " BB_VER);
993 return 0; 997 return 0;
994 } 998 }
995 if (argv[1] && argv[1][0] != '-') { 999#endif
1000 if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') {
996 /* Compat: 1001 /* Compat:
997 * 1st argument without dash handles options with parameters 1002 * 1st argument without dash handles options with parameters
998 * differently from dashed one: it takes *next argv[i]* 1003 * differently from dashed one: it takes *next argv[i]*
999 * as paramenter even if there are more chars in 1st argument: 1004 * as parameter even if there are more chars in 1st argument:
1000 * "tar fx TARFILE" - "x" is not taken as f's param 1005 * "tar fx TARFILE" - "x" is not taken as f's param
1001 * but is interpreted as -x option 1006 * but is interpreted as -x option
1002 * "tar -xf TARFILE" - dashed equivalent of the above 1007 * "tar -xf TARFILE" - dashed equivalent of the above
@@ -1016,11 +1021,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1016 } 1021 }
1017 *f = 'f'; 1022 *f = 'f';
1018 } 1023 }
1019 } 1024 /* Prepend '-' to the first argument */
1020#endif
1021 /* Prepend '-' to the first argument if required */
1022 if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0')
1023 argv[1] = xasprintf("-%s", argv[1]); 1025 argv[1] = xasprintf("-%s", argv[1]);
1026 }
1024 opt = GETOPT32(argv, "^" 1027 opt = GETOPT32(argv, "^"
1025 "txC:f:Oopvk" 1028 "txC:f:Oopvk"
1026 IF_FEATURE_TAR_CREATE( "ch" ) 1029 IF_FEATURE_TAR_CREATE( "ch" )
@@ -1198,13 +1201,10 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1198 if (base_dir) 1201 if (base_dir)
1199 xchdir(base_dir); 1202 xchdir(base_dir);
1200 1203
1201 //if (SEAMLESS_COMPRESSION)
1202 // /* We need to know whether child (gzip/bzip/etc) exits abnormally */
1203 // signal(SIGCHLD, check_errors_in_children);
1204
1205#if ENABLE_FEATURE_TAR_CREATE 1204#if ENABLE_FEATURE_TAR_CREATE
1206 /* Create an archive */ 1205 /* Create an archive */
1207 if (opt & OPT_CREATE) { 1206 if (opt & OPT_CREATE) {
1207 struct TarBallInfo *tbInfo;
1208# if SEAMLESS_COMPRESSION 1208# if SEAMLESS_COMPRESSION
1209 const char *zipMode = NULL; 1209 const char *zipMode = NULL;
1210 if (opt & OPT_COMPRESS) 1210 if (opt & OPT_COMPRESS)
@@ -1218,12 +1218,18 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1218 if (opt & OPT_XZ) 1218 if (opt & OPT_XZ)
1219 zipMode = "xz"; 1219 zipMode = "xz";
1220# endif 1220# endif
1221 tbInfo = xzalloc(sizeof(*tbInfo));
1222 tbInfo->tarFd = tar_handle->src_fd;
1223 tbInfo->verboseFlag = verboseFlag;
1224# if ENABLE_FEATURE_TAR_FROM
1225 tbInfo->excludeList = tar_handle->reject;
1226# endif
1221 /* NB: writeTarFile() closes tar_handle->src_fd */ 1227 /* NB: writeTarFile() closes tar_handle->src_fd */
1222 return writeTarFile(tar_handle->src_fd, verboseFlag, 1228 return writeTarFile(tbInfo,
1223 (opt & OPT_DEREFERENCE ? ACTION_FOLLOWLINKS : 0) 1229 (opt & OPT_DEREFERENCE ? ACTION_FOLLOWLINKS : 0)
1224 | (opt & OPT_NORECURSION ? 0 : ACTION_RECURSE), 1230 | (opt & OPT_NORECURSION ? 0 : ACTION_RECURSE),
1225 tar_handle->accept, 1231 tar_handle->accept,
1226 tar_handle->reject, zipMode); 1232 zipMode);
1227 } 1233 }
1228#endif 1234#endif
1229 1235
diff --git a/archival/unzip.c b/archival/unzip.c
index 233487697..c5fb6a3ed 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -56,7 +56,7 @@
56//kbuild:lib-$(CONFIG_UNZIP) += unzip.o 56//kbuild:lib-$(CONFIG_UNZIP) += unzip.o
57 57
58//usage:#define unzip_trivial_usage 58//usage:#define unzip_trivial_usage
59//usage: "[-lnopq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]" 59//usage: "[-lnojpq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]"
60//usage:#define unzip_full_usage "\n\n" 60//usage:#define unzip_full_usage "\n\n"
61//usage: "Extract FILEs from ZIP archive\n" 61//usage: "Extract FILEs from ZIP archive\n"
62//usage: "\n -l List contents (with -q for short form)" 62//usage: "\n -l List contents (with -q for short form)"
@@ -808,13 +808,6 @@ int unzip_main(int argc, char **argv)
808 /* Guard against "/abspath", "/../" and similar attacks */ 808 /* Guard against "/abspath", "/../" and similar attacks */
809 overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn)); 809 overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn));
810 810
811 if (opts & OPT_j) /* Strip paths? */
812 overlapping_strcpy(dst_fn, bb_basename(dst_fn));
813
814 /* Did this strip everything ("DIR/" case)? Then skip */
815 if (!dst_fn[0])
816 goto skip_cmpsize;
817
818 /* Filter zip entries */ 811 /* Filter zip entries */
819 if (find_list_entry(zreject, dst_fn) 812 if (find_list_entry(zreject, dst_fn)
820 || (zaccept && !find_list_entry(zaccept, dst_fn)) 813 || (zaccept && !find_list_entry(zaccept, dst_fn))
@@ -879,6 +872,14 @@ int unzip_main(int argc, char **argv)
879 /* Extracting to STDOUT */ 872 /* Extracting to STDOUT */
880 goto do_extract; 873 goto do_extract;
881 } 874 }
875
876 /* Strip paths (after -l: unzip -lj a.zip lists full names) */
877 if (opts & OPT_j)
878 overlapping_strcpy(dst_fn, bb_basename(dst_fn));
879 /* Did this strip everything ("DIR/" case)? Then skip */
880 if (!dst_fn[0])
881 goto skip_cmpsize;
882
882 if (last_char_is(dst_fn, '/')) { 883 if (last_char_is(dst_fn, '/')) {
883 int mode; 884 int mode;
884 885
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index c0edb7399..3df67abb1 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -687,6 +687,18 @@ static void free_tab_completion_data(void)
687 687
688static void add_match(char *matched) 688static void add_match(char *matched)
689{ 689{
690 unsigned char *p = (unsigned char*)matched;
691 while (*p) {
692 /* ESC attack fix: drop any string with control chars */
693 if (*p < ' '
694 || (!ENABLE_UNICODE_SUPPORT && *p >= 0x7f)
695 || (ENABLE_UNICODE_SUPPORT && *p == 0x7f)
696 ) {
697 free(matched);
698 return;
699 }
700 p++;
701 }
690 matches = xrealloc_vector(matches, 4, num_matches); 702 matches = xrealloc_vector(matches, 4, num_matches);
691 matches[num_matches] = matched; 703 matches[num_matches] = matched;
692 num_matches++; 704 num_matches++;
@@ -2457,6 +2469,8 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2457 bb_error_msg("cur_history:%d cnt_history:%d", state->cur_history, state->cnt_history); 2469 bb_error_msg("cur_history:%d cnt_history:%d", state->cur_history, state->cnt_history);
2458#endif 2470#endif
2459 2471
2472 /* Get width (before printing prompt) */
2473 cmdedit_termw = get_terminal_width(STDIN_FILENO);
2460 /* Print out the command prompt, optionally ask where cursor is */ 2474 /* Print out the command prompt, optionally ask where cursor is */
2461 parse_and_put_prompt(prompt); 2475 parse_and_put_prompt(prompt);
2462 ask_terminal(); 2476 ask_terminal();
@@ -2466,8 +2480,6 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2466 S.SIGWINCH_handler.sa_flags = SA_RESTART; 2480 S.SIGWINCH_handler.sa_flags = SA_RESTART;
2467 sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler); 2481 sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler);
2468 2482
2469 cmdedit_termw = get_terminal_width(STDIN_FILENO);
2470
2471 read_key_buffer[0] = 0; 2483 read_key_buffer[0] = 0;
2472 while (1) { 2484 while (1) {
2473 /* 2485 /*
diff --git a/networking/inetd.c b/networking/inetd.c
index 67984accb..4dfa0089a 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -1488,7 +1488,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv)
1488 bb_error_msg("non-root must run services as himself"); 1488 bb_error_msg("non-root must run services as himself");
1489 goto do_exit1; 1489 goto do_exit1;
1490 } 1490 }
1491 if (pwd->pw_uid != 0) { 1491 if (pwd->pw_uid != real_uid) {
1492 if (sep->se_group) 1492 if (sep->se_group)
1493 pwd->pw_gid = grp->gr_gid; 1493 pwd->pw_gid = grp->gr_gid;
1494 /* initgroups, setgid, setuid: */ 1494 /* initgroups, setgid, setuid: */
diff --git a/util-linux/unshare.c b/util-linux/unshare.c
index 6a3da9f91..7c295da1f 100644
--- a/util-linux/unshare.c
+++ b/util-linux/unshare.c
@@ -217,7 +217,7 @@ int unshare_main(int argc UNUSED_PARAM, char **argv)
217 ":\xf3""n" 217 ":\xf3""n"
218 ":\xf4""p" 218 ":\xf4""p"
219 ":\xf5""U" 219 ":\xf5""U"
220 ":ru" /* --map-root-user or -r implies -u */ 220 ":rU" /* --map-root-user or -r implies -U */
221 ":\xfd""m" /* --mount-proc implies -m */ 221 ":\xfd""m" /* --mount-proc implies -m */
222 , unshare_longopts, 222 , unshare_longopts,
223 &proc_mnt_target, &prop_str, &setgrp_str, 223 &proc_mnt_target, &prop_str, &setgrp_str,
@@ -339,7 +339,7 @@ int unshare_main(int argc UNUSED_PARAM, char **argv)
339 } 339 }
340 340
341 if (opts & OPT_map_root) { 341 if (opts & OPT_map_root) {
342 char uidmap_buf[sizeof("%u 0 1") + sizeof(int)*3]; 342 char uidmap_buf[sizeof("0 %u 1") + sizeof(int)*3];
343 343
344 /* 344 /*
345 * Since Linux 3.19 unprivileged writing of /proc/self/gid_map 345 * Since Linux 3.19 unprivileged writing of /proc/self/gid_map
@@ -348,9 +348,9 @@ int unshare_main(int argc UNUSED_PARAM, char **argv)
348 * in that user namespace. 348 * in that user namespace.
349 */ 349 */
350 xopen_xwrite_close(PATH_PROC_SETGROUPS, "deny"); 350 xopen_xwrite_close(PATH_PROC_SETGROUPS, "deny");
351 sprintf(uidmap_buf, "%u 0 1", (unsigned)reuid); 351 sprintf(uidmap_buf, "0 %u 1", (unsigned)reuid);
352 xopen_xwrite_close(PATH_PROC_UIDMAP, uidmap_buf); 352 xopen_xwrite_close(PATH_PROC_UIDMAP, uidmap_buf);
353 sprintf(uidmap_buf, "%u 0 1", (unsigned)regid); 353 sprintf(uidmap_buf, "0 %u 1", (unsigned)regid);
354 xopen_xwrite_close(PATH_PROC_GIDMAP, uidmap_buf); 354 xopen_xwrite_close(PATH_PROC_GIDMAP, uidmap_buf);
355 } else 355 } else
356 if (setgrp_str) { 356 if (setgrp_str) {