summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sbin/restore/extern.h4
-rw-r--r--sbin/restore/interactive.c34
-rw-r--r--sbin/restore/main.c12
3 files changed, 28 insertions, 22 deletions
diff --git a/sbin/restore/extern.h b/sbin/restore/extern.h
index d287ffba8b3..0bd784480ce 100644
--- a/sbin/restore/extern.h
+++ b/sbin/restore/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.5 2002/02/17 19:42:29 millert Exp $ */
+/* $OpenBSD: extern.h,v 1.6 2003/04/04 22:12:35 deraadt Exp $ */
/* $NetBSD: extern.h,v 1.4 1995/03/18 14:59:43 cgd Exp $ */
/*-
@@ -40,7 +40,7 @@ struct entry *addentry(char *, ino_t, int);
long addfile(char *, ino_t, int);
int addwhiteout(char *);
void badentry(struct entry *, char *);
-void canon(char *, char *);
+void canon(char *, char *, size_t);
void checkrestore(void);
void cleanup(void);
void closemt(void);
diff --git a/sbin/restore/interactive.c b/sbin/restore/interactive.c
index 8d6a8ac3965..7bc82c25654 100644
--- a/sbin/restore/interactive.c
+++ b/sbin/restore/interactive.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: interactive.c,v 1.14 2002/02/16 21:27:37 millert Exp $ */
+/* $OpenBSD: interactive.c,v 1.15 2003/04/04 22:12:35 deraadt Exp $ */
/* $NetBSD: interactive.c,v 1.10 1997/03/19 08:42:52 lukem Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)interactive.c 8.3 (Berkeley) 9/13/94";
#else
-static char rcsid[] = "$OpenBSD: interactive.c,v 1.14 2002/02/16 21:27:37 millert Exp $";
+static char rcsid[] = "$OpenBSD: interactive.c,v 1.15 2003/04/04 22:12:35 deraadt Exp $";
#endif
#endif /* not lint */
@@ -90,7 +90,7 @@ struct arglist {
static char *copynext(char *, char *);
static int fcmp(const void *, const void *);
static void formatf(struct afile *, int);
-static void getcmd(char *, char *, char *, struct arglist *);
+static void getcmd(char *, char *, size_t, char *, size_t, struct arglist *);
struct dirent *glob_readdir(RST_DIR *dirp);
static int glob_stat(const char *, struct stat *);
static void mkentry(char *, struct direct *, struct afile *);
@@ -117,7 +117,7 @@ runcmdshell()
arglist.glob.gl_closedir = (void *)rst_closedir;
arglist.glob.gl_lstat = glob_stat;
arglist.glob.gl_stat = glob_stat;
- canon("/", curdir);
+ canon("/", curdir, sizeof curdir);
loop:
if (setjmp(reset) != 0) {
if (arglist.freeglob != 0) {
@@ -129,7 +129,7 @@ loop:
volno = 0;
}
runshell = 1;
- getcmd(curdir, cmd, name, &arglist);
+ getcmd(curdir, cmd, sizeof cmd, name, sizeof name, &arglist);
switch (cmd[0]) {
/*
* Add elements to the extraction list.
@@ -308,8 +308,11 @@ loop:
* eliminate any embedded ".." components.
*/
static void
-getcmd(curdir, cmd, name, ap)
- char *curdir, *cmd, *name;
+getcmd(curdir, cmd, cmdlen, name, namelen, ap)
+ char *curdir, *cmd;
+ size_t cmdlen;
+ char *name;
+ size_t namelen;
struct arglist *ap;
{
char *cp;
@@ -334,7 +337,7 @@ getcmd(curdir, cmd, name, ap)
(void)fgets(input, BUFSIZ, terminal);
} while (!feof(terminal) && input[0] == '\n');
if (feof(terminal)) {
- (void)strcpy(cmd, "quit");
+ (void)strlcpy(cmd, "quit", cmdlen);
return;
}
for (cp = &input[strlen(input) - 2]; *cp == ' ' || *cp == '\t'; cp--)
@@ -366,14 +369,14 @@ getnext:
* If it is an absolute pathname, canonicalize it and return it.
*/
if (rawname[0] == '/') {
- canon(rawname, name);
+ canon(rawname, name, namelen);
} else {
/*
* For relative pathnames, prepend the current directory to
* it then canonicalize and return it.
*/
snprintf(output, sizeof(output), "%s/%s", curdir, rawname);
- canon(output, name);
+ canon(output, name, namelen);
}
if ((globretval = glob(name, GLOB_ALTDIRFUNC | GLOB_NOESCAPE,
NULL, &ap->glob)) < 0) {
@@ -463,18 +466,19 @@ copynext(input, output)
* remove any imbedded "." and ".." components.
*/
void
-canon(rawname, canonname)
+canon(rawname, canonname, canonnamelen)
char *rawname, *canonname;
+ size_t canonnamelen;
{
char *cp, *np;
if (strcmp(rawname, ".") == 0 || strncmp(rawname, "./", 2) == 0)
- (void)strcpy(canonname, "");
+ (void)strlcpy(canonname, "", canonnamelen);
else if (rawname[0] == '/')
- (void)strcpy(canonname, ".");
+ (void)strlcpy(canonname, ".", canonnamelen);
else
- (void)strcpy(canonname, "./");
- (void)strlcat(canonname, rawname, MAXPATHLEN);
+ (void)strlcpy(canonname, "./", canonnamelen);
+ (void)strlcat(canonname, rawname, canonnamelen);
/*
* Eliminate multiple and trailing '/'s
*/
diff --git a/sbin/restore/main.c b/sbin/restore/main.c
index 706f7ff729d..372d36b36b9 100644
--- a/sbin/restore/main.c
+++ b/sbin/restore/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.11 2002/02/16 21:27:37 millert Exp $ */
+/* $OpenBSD: main.c,v 1.12 2003/04/04 22:12:35 deraadt Exp $ */
/* $NetBSD: main.c,v 1.13 1997/07/01 05:37:51 lukem Exp $ */
/*
@@ -255,7 +255,7 @@ main(argc, argv)
extractdirs(0);
initsymtable(NULL);
while (argc--) {
- canon(*argv++, name);
+ canon(*argv++, name, sizeof name);
ino = dirlookup(name);
if (ino == 0)
continue;
@@ -270,7 +270,7 @@ main(argc, argv)
extractdirs(1);
initsymtable(NULL);
while (argc--) {
- canon(*argv++, name);
+ canon(*argv++, name, sizeof name);
ino = dirlookup(name);
if (ino == 0)
continue;
@@ -312,6 +312,7 @@ obsolete(argcp, argvp)
{
int argc, flags;
char *ap, **argv, *flagsp, **nargv, *p;
+ size_t len;
/* Setup. */
argv = *argvp;
@@ -339,11 +340,12 @@ obsolete(argcp, argvp)
warnx("option requires an argument -- %c", *ap);
usage();
}
- if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL)
+ len = strlen(*argv) + 2 + 1;
+ if ((nargv[0] = malloc(len)) == NULL)
err(1, NULL);
nargv[0][0] = '-';
nargv[0][1] = *ap;
- (void)strcpy(&nargv[0][2], *argv);
+ (void)strlcpy(&nargv[0][2], *argv, len-2);
++argv;
++nargv;
break;