Remove unused user_uname variable.

Add range-checking to argument of -b.

Thanks to: Tim J Robbins
This commit is contained in:
kientzle 2004-07-17 18:21:00 +00:00
parent bd6355261f
commit 8b3e9f1e03
2 changed files with 8 additions and 16 deletions

View File

@ -51,7 +51,6 @@ struct option {
#include <langinfo.h>
#endif
#include <locale.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -150,8 +149,7 @@ main(int argc, char **argv)
{
struct bsdtar *bsdtar, bsdtar_storage;
const struct option *option;
struct passwd *pwent;
int opt;
int opt, t;
char mode;
char possible_help_request;
char buff[16];
@ -172,14 +170,8 @@ main(int argc, char **argv)
mode = '\0';
possible_help_request = 0;
/* Look up uid/uname of current user for future reference */
/* Look up uid of current user for future reference */
bsdtar->user_uid = geteuid();
bsdtar->user_uname = NULL;
if ((pwent = getpwuid(bsdtar->user_uid))) {
bsdtar->user_uname = (char *)malloc(strlen(pwent->pw_name)+1);
if (bsdtar->user_uname)
strcpy(bsdtar->user_uname, pwent->pw_name);
}
/* Default: open tape drive. */
bsdtar->filename = getenv("TAPE");
@ -211,7 +203,11 @@ main(int argc, char **argv)
/* libarchive doesn't need this; just ignore it. */
break;
case 'b': /* SUSv2 */
bsdtar->bytes_per_block = 512 * atoi(optarg);
t = atoi(optarg);
if (t <= 0 || t > 1024)
bsdtar_errc(bsdtar, 1, 0,
"Argument to -b is out of range (1..1024)");
bsdtar->bytes_per_block = 512 * t;
break;
case 'C': /* GNU tar */
/* Defer first -C until after -f is opened. */
@ -414,7 +410,7 @@ main(int argc, char **argv)
only_mode(bsdtar, mode, "-o", "xc");
/* Warn about nonsensical -co combination, but ignore it. */
if (mode == 'c')
bsdtar_warnc(bsdtar, 0, "-o is incompatible with -c");
bsdtar_warnc(bsdtar, 0, "Ignoring nonsensical -o option");
}
if (bsdtar->option_no_subdirs)
only_mode(bsdtar, mode, "-n", "cru");
@ -462,9 +458,6 @@ main(int argc, char **argv)
break;
}
if (bsdtar->user_uname != NULL)
free(bsdtar->user_uname);
cleanup_exclusions(bsdtar);
return (bsdtar->return_value);
}

View File

@ -76,7 +76,6 @@ struct bsdtar {
char **argv;
size_t gs_width; /* For 'list_item' in read.c */
size_t u_width; /* for 'list_item' in read.c */
char *user_uname; /* User running this program */
uid_t user_uid; /* UID running this program */
int return_value; /* Value returned by main() */
char warned_lead_slash; /* Already displayed warning */