Bug 815 - SEGFAULT in archival/tar.c found
Summary: SEGFAULT in archival/tar.c found
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: 1.16.x
Hardware: Other Linux
: P2 trivial
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-17 21:33 UTC by Douglas
Modified: 2009-12-18 11:37 UTC (History)
1 user (show)

See Also:
Host: powerpc-gnu-linux-uclibc
Target: powerpc-gnu-linux-uclibc
Build: powerpc-gnu-linux-uclibc


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Douglas 2009-12-17 21:33:09 UTC
How to reproduce:
just 'tar' (yep, it must be busybox's tar)

What you'll get:
a segfault

The fix is trivial; all you need is *not* to argv[1][0] int tar_main(int argc, char **argv) w/o any knowledge of number of arguments passed.

The working version is:

int tar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int tar_main(int argc, char **argv)
{
	char FAST_FUNC (*get_header_ptr)(archive_handle_t *) = get_header_tar;
	archive_handle_t *tar_handle;
	char *base_dir = NULL;
	const char *tar_filename = "-";
	unsigned opt;
	int verboseFlag = 0;
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
	llist_t *excludes = NULL;
#endif

	/* Initialise default values */
	tar_handle = init_handle();
	tar_handle->ah_flags = ARCHIVE_CREATE_LEADING_DIRS
	                     | ARCHIVE_RESTORE_DATE
	                     | ARCHIVE_UNLINK_OLD;

	/* Apparently only root's tar preserves perms (see bug 3844) */
	if (getuid() != 0)
		tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_PERM;

	/* Prepend '-' to the first argument if required */
	opt_complementary = "--:" // first arg is options
		"tt:vv:" // count -t,-v
		"?:" // bail out with usage instead of error return
		"X::T::" // cumulative lists
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
		"\xff::" // cumulative lists for --exclude
#endif
		IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
		IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
		IF_NOT_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
	applet_long_options = tar_longopts;
#endif
#if ENABLE_DESKTOP
	if ((argc > 1) && (argv[1][0] != '-')) {
		/* Compat:
		 * 1st argument without dash handles options with parameters
Comment 1 Denys Vlasenko 2009-12-18 11:37:09 UTC
Fixed in git, thanks for finding it!