summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_install
diff options
context:
space:
mode:
authorAnil Madhavapeddy <avsm@cvs.openbsd.org>2003-04-04 08:56:02 +0000
committerAnil Madhavapeddy <avsm@cvs.openbsd.org>2003-04-04 08:56:02 +0000
commitdf767a3328525b26a79f2a28f9984a9259766282 (patch)
tree1c7d7fd6c5f59e11b46e5779f919d0654e080ee8 /usr.sbin/pkg_install
parent8f22089b34ec737d4331b517d8cf690df9544655 (diff)
some more strcpy/strcat -> strlcpy/strlcat conversions
ok and tweaks by ho@
Diffstat (limited to 'usr.sbin/pkg_install')
-rw-r--r--usr.sbin/pkg_install/add/perform.c14
-rw-r--r--usr.sbin/pkg_install/create/main.c6
-rw-r--r--usr.sbin/pkg_install/create/pl.c10
-rw-r--r--usr.sbin/pkg_install/delete/perform.c10
-rw-r--r--usr.sbin/pkg_install/info/perform.c14
-rw-r--r--usr.sbin/pkg_install/info/show.c6
-rw-r--r--usr.sbin/pkg_install/lib/file.c16
-rw-r--r--usr.sbin/pkg_install/lib/lib.h6
-rw-r--r--usr.sbin/pkg_install/lib/pen.c22
-rw-r--r--usr.sbin/pkg_install/lib/plist.c6
-rw-r--r--usr.sbin/pkg_install/lib/str.c15
11 files changed, 62 insertions, 63 deletions
diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c
index 93ee1c96280..b46e269cd8f 100644
--- a/usr.sbin/pkg_install/add/perform.c
+++ b/usr.sbin/pkg_install/add/perform.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: perform.c,v 1.23 2003/04/03 19:42:53 avsm Exp $ */
+/* $OpenBSD: perform.c,v 1.24 2003/04/04 08:56:01 avsm Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: perform.c,v 1.23 2003/04/03 19:42:53 avsm Exp $";
+static const char *rcsid = "$OpenBSD: perform.c,v 1.24 2003/04/04 08:56:01 avsm Exp $";
#endif
/*
@@ -61,9 +61,9 @@ static char *Home;
/* called to see if pkg is already installed as some other version */
/* note found version in "note" */
static int
-check_if_installed(const char *found, char *note)
+check_if_installed(const char *found, char *note, int len)
{
- strcpy(note, found);
+ strlcpy(note, found, len);
return 0;
}
@@ -256,7 +256,7 @@ pkg_do(char *pkg)
}
strlcpy(buf+(s-PkgName+1), isdigit(s[1]) ? "[0-9]*" : "*", sizeof(buf)-(s-PkgName+1));
- if (findmatchingname(dbdir, buf, check_if_installed, installed)) {
+ if (findmatchingname(dbdir, buf, check_if_installed, installed, sizeof(installed))) {
pwarnx("other version '%s' already installed", installed);
if (find_plist_option(&Plist, "no-default-conflict") != NULL) {
pwarnx("proceeding with installation anyway");
@@ -279,7 +279,7 @@ pkg_do(char *pkg)
/* was: */
/* if (!vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) {*/
- if(findmatchingname(dbdir, p->name, check_if_installed, installed)){
+ if(findmatchingname(dbdir, p->name, check_if_installed, installed, sizeof(installed))){
pwarnx("Conflicting package installed, please use\n\t\"pkg_delete %s\" first to remove it!\n", installed);
++code;
}
@@ -294,7 +294,7 @@ pkg_do(char *pkg)
if (Verbose)
printf("Package `%s' depends on `%s'\n", PkgName, p->name);
/* if (vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) { */
- if (!findmatchingname(dbdir, p->name, check_if_installed, installed)) {
+ if (!findmatchingname(dbdir, p->name, check_if_installed, installed, sizeof(installed))) {
char path[FILENAME_MAX], *cp = NULL;
if (!Fake) {
diff --git a/usr.sbin/pkg_install/create/main.c b/usr.sbin/pkg_install/create/main.c
index d3ff7c44439..f39e5876e5e 100644
--- a/usr.sbin/pkg_install/create/main.c
+++ b/usr.sbin/pkg_install/create/main.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: main.c,v 1.10 2002/02/16 21:28:06 millert Exp $ */
+/* $OpenBSD: main.c,v 1.11 2003/04/04 08:56:01 avsm Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: main.c,v 1.10 2002/02/16 21:28:06 millert Exp $";
+static const char *rcsid = "$OpenBSD: main.c,v 1.11 2003/04/04 08:56:01 avsm Exp $";
#endif
/*
@@ -91,7 +91,7 @@ main(int argc, char **argv)
break;
case 't':
- strcpy(PlayPen, optarg);
+ strlcpy(PlayPen, optarg, PlayPenSize);
break;
case 'X':
diff --git a/usr.sbin/pkg_install/create/pl.c b/usr.sbin/pkg_install/create/pl.c
index f40926efa3e..66e615a58af 100644
--- a/usr.sbin/pkg_install/create/pl.c
+++ b/usr.sbin/pkg_install/create/pl.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: pl.c,v 1.7 2001/06/06 20:03:08 espie Exp $ */
+/* $OpenBSD: pl.c,v 1.8 2003/04/04 08:56:01 avsm Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: pl.c,v 1.7 2001/06/06 20:03:08 espie Exp $";
+static const char *rcsid = "$OpenBSD: pl.c,v 1.8 2003/04/04 08:56:01 avsm Exp $";
#endif
/*
@@ -98,14 +98,14 @@ trylink(const char *from, const char *to)
#define TOOBIG(str) strlen(str) + 6 + strlen(home) + where_count > maxargs
#define PUSHOUT() /* push out string */ \
if (where_count > sizeof(STARTSTRING)-1) { \
- strcat(where_args, "|tar xpf -"); \
+ strlcat(where_args, "|tar xpf -", maxargs); \
if (system(where_args)) { \
cleanup(0); \
errx(2, "can't invoke tar pipeline"); \
} \
memset(where_args, 0, maxargs); \
last_chdir = NULL; \
- strcpy(where_args, STARTSTRING); \
+ strlcpy(where_args, STARTSTRING, maxargs); \
where_count = sizeof(STARTSTRING)-1; \
}
@@ -134,7 +134,7 @@ copy_plist(char *home, package_t *plist)
}
memset(where_args, 0, maxargs);
- strcpy(where_args, STARTSTRING);
+ strlcpy(where_args, STARTSTRING, maxargs);
where_count = sizeof(STARTSTRING)-1;
last_chdir = 0;
diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c
index 6090641b198..856ad26ff02 100644
--- a/usr.sbin/pkg_install/delete/perform.c
+++ b/usr.sbin/pkg_install/delete/perform.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: perform.c,v 1.11 2001/11/26 05:04:33 deraadt Exp $ */
+/* $OpenBSD: perform.c,v 1.12 2003/04/04 08:56:01 avsm Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: perform.c,v 1.11 2001/11/26 05:04:33 deraadt Exp $";
+static const char *rcsid = "$OpenBSD: perform.c,v 1.12 2003/04/04 08:56:01 avsm Exp $";
#endif
/*
@@ -32,7 +32,7 @@ static const char *rcsid = "$OpenBSD: perform.c,v 1.11 2001/11/26 05:04:33 deraa
static int pkg_do(char *);
static void sanity_check(char *);
-static int undepend(const char *, char *);
+static int undepend(const char *, char *, int);
static char LogDir[FILENAME_MAX];
@@ -238,7 +238,7 @@ try_again:
if (Verbose)
printf("Attempting to remove dependency on package `%s'\n", p->name);
if (!Fake)
- findmatchingname(dbdir, p->name, undepend, pkg);
+ findmatchingname(dbdir, p->name, undepend, pkg, 0);
}
return 0;
}
@@ -263,7 +263,7 @@ cleanup(int sig)
* findmatchingname(), deppkgname is expanded from a (possible) pattern.
*/
int
-undepend(const char *deppkgname, char *pkg2delname)
+undepend(const char *deppkgname, char *pkg2delname, int unused)
{
char fname[FILENAME_MAX], ftmp[FILENAME_MAX];
char fbuf[FILENAME_MAX];
diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c
index 14d987277b6..370a63bb8af 100644
--- a/usr.sbin/pkg_install/info/perform.c
+++ b/usr.sbin/pkg_install/info/perform.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: perform.c,v 1.11 2001/11/26 05:04:33 deraadt Exp $ */
+/* $OpenBSD: perform.c,v 1.12 2003/04/04 08:56:01 avsm Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: perform.c,v 1.11 2001/11/26 05:04:33 deraadt Exp $";
+static const char *rcsid = "$OpenBSD: perform.c,v 1.12 2003/04/04 08:56:01 avsm Exp $";
#endif
/* This is OpenBSD pkg_install, based on:
@@ -84,7 +84,7 @@ pkg_do(char *pkg)
if (isURL(pkg)) {
if ((cp = fileGetURL(NULL, pkg)) != NULL) {
- strcpy(fname, cp);
+ strlcpy(fname, cp, sizeof(fname));
isTMP = TRUE;
}
} else if (fexists(pkg) && isfile(pkg)) {
@@ -97,7 +97,7 @@ pkg_do(char *pkg)
len = strlen(fname);
snprintf(&fname[len], FILENAME_MAX - len, "/%s", pkg);
} else
- strcpy(fname, pkg);
+ strlcpy(fname, pkg, sizeof(fname));
cp = fname;
} else {
if ((cp = fileFindByPath(NULL, pkg)) != NULL) {
@@ -115,7 +115,7 @@ pkg_do(char *pkg)
if (cp) {
if (isURL(pkg)) {
/* file is already unpacked by fileGetURL() */
- strcpy(PlayPen, cp);
+ strlcpy(PlayPen, cp, PlayPenSize);
} else {
/*
* Apply a crude heuristic to see how much space the package will
@@ -219,7 +219,7 @@ bail:
/* fn to be called for pkgs found */
static int
-foundpkg(const char *found, char *data)
+foundpkg(const char *found, char *data, int unused)
{
if(!Quiet)
printf("%s\n", found);
@@ -235,7 +235,7 @@ check4pkg(char *pkgspec, char *dbdir)
/* expensive (pattern) match */
int found;
- found=findmatchingname(dbdir, pkgspec, foundpkg, NULL);
+ found=findmatchingname(dbdir, pkgspec, foundpkg, NULL, 0);
return !found;
} else {
/* simple match */
diff --git a/usr.sbin/pkg_install/info/show.c b/usr.sbin/pkg_install/info/show.c
index 457f4a11c5a..bccb7f260d4 100644
--- a/usr.sbin/pkg_install/info/show.c
+++ b/usr.sbin/pkg_install/info/show.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: show.c,v 1.10 2001/11/07 20:57:23 espie Exp $ */
+/* $OpenBSD: show.c,v 1.11 2003/04/04 08:56:01 avsm Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: show.c,v 1.10 2001/11/07 20:57:23 espie Exp $";
+static const char *rcsid = "$OpenBSD: show.c,v 1.11 2003/04/04 08:56:01 avsm Exp $";
#endif
/*
@@ -85,7 +85,7 @@ show_index(char *title, char *fname)
FILE *fp;
char line[MAXINDEXSIZE+2];
- strcpy(line, "???\n");
+ strlcpy(line, "???\n", sizeof(line));
if (!Quiet) {
printf("%s%-18s ", InfoPrefix, title);
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c
index 21848a7a64e..4cdf07bba89 100644
--- a/usr.sbin/pkg_install/lib/file.c
+++ b/usr.sbin/pkg_install/lib/file.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: file.c,v 1.15 2001/07/09 07:05:03 deraadt Exp $ */
+/* $OpenBSD: file.c,v 1.16 2003/04/04 08:56:01 avsm Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: file.c,v 1.15 2001/07/09 07:05:03 deraadt Exp $";
+static const char *rcsid = "$OpenBSD: file.c,v 1.16 2003/04/04 08:56:01 avsm Exp $";
#endif
/*
@@ -374,7 +374,7 @@ fileFindByPath(char *base, char *fname)
if (ispkgpattern(fname)) {
if ((cp=findbestmatchingname(".",fname)) != NULL) {
- strcpy (tmp, cp);
+ strlcpy(tmp, cp, sizeof(tmp));
return tmp;
}
} else {
@@ -385,7 +385,7 @@ fileFindByPath(char *base, char *fname)
}
if (base) {
- strcpy(tmp, base);
+ strlcpy(tmp, base, sizeof(tmp));
cp = strrchr(tmp, '/');
if (cp) {
@@ -601,14 +601,14 @@ unpack(char *pkg, char *flist)
if (strcmp(pkg, "-")) {
cp = strrchr(pkg, '.');
if (cp) {
- strcpy(suff, cp + 1);
+ strlcpy(suff, cp + 1, sizeof(suff));
if (strchr(suff, 'z') || strchr(suff, 'Z'))
- strcpy(args, "-z");
+ strlcpy(args, "-z", sizeof(args));
}
}
else
- strcpy(args, "z");
- strcat(args, "xpf");
+ strlcpy(args, "z", sizeof(args));
+ strlcat(args, "xpf", sizeof(args));
if (vsystem("tar %s %s %s", args, pkg, flist ? flist : "")) {
pwarnx("tar extract of %s failed!", pkg);
return 1;
diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h
index 075ded9c77c..d3d65bb2692 100644
--- a/usr.sbin/pkg_install/lib/lib.h
+++ b/usr.sbin/pkg_install/lib/lib.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: lib.h,v 1.11 2001/11/07 20:57:24 espie Exp $ */
+/* $OpenBSD: lib.h,v 1.12 2003/04/04 08:56:01 avsm Exp $ */
/*
* FreeBSD install - a package for the installation and maintainance
@@ -132,7 +132,7 @@ enum {
/* type of function to be handed to findmatchingname; return value of this
* is currently ignored */
-typedef int (*matchfn)(const char *found, char *data);
+typedef int (*matchfn)(const char *found, char *data, int len);
/* Prototypes */
/* Misc */
@@ -155,7 +155,7 @@ char *basename_of(char *);
char *dirname_of(const char *);
char *strconcat(char *, char *);
int pmatch(const char *, const char *);
-int findmatchingname(const char *, const char *, matchfn, char *); /* doesn't really belong here */
+int findmatchingname(const char *, const char *, matchfn, char *, int); /* doesn't really belong here */
char *findbestmatchingname(const char *, const char *); /* neither */
int ispkgpattern(const char *);
char *strnncpy(char *to, size_t tosize, char *from, size_t cc);
diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c
index 9b8749d2f8d..189b091fa84 100644
--- a/usr.sbin/pkg_install/lib/pen.c
+++ b/usr.sbin/pkg_install/lib/pen.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: pen.c,v 1.11 2002/02/18 00:18:07 millert Exp $ */
+/* $OpenBSD: pen.c,v 1.12 2003/04/04 08:56:01 avsm Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: pen.c,v 1.11 2002/02/18 00:18:07 millert Exp $";
+static const char *rcsid = "$OpenBSD: pen.c,v 1.12 2003/04/04 08:56:01 avsm Exp $";
#endif
/*
@@ -53,8 +53,8 @@ save_dirs(char **c, char **p)
void
restore_dirs(char *c, char *p)
{
- strcpy(Current, c); free(c);
- strcpy(Previous, p); free(p);
+ strlcpy(Current, c, sizeof(Current)); free(c);
+ strlcpy(Previous, p, sizeof(Previous)); free(p);
}
char *
@@ -77,11 +77,11 @@ find_play_pen(char *pen, size_t pensize, size_t sz)
else if ((cp = getenv("TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz))
(void) snprintf(pen, pensize, "%s/instmp.XXXXXXXXXX", cp);
else if (stat("/var/tmp", &sb) != FAIL && min_free("/var/tmp") >= sz)
- strcpy(pen, "/var/tmp/instmp.XXXXXXXXXX");
+ strlcpy(pen, "/var/tmp/instmp.XXXXXXXXXX", pensize);
else if (stat("/tmp", &sb) != FAIL && min_free("/tmp") >= sz)
- strcpy(pen, "/tmp/instmp.XXXXXXXXXX");
+ strlcpy(pen, "/tmp/instmp.XXXXXXXXXX", pensize);
else if ((stat("/usr/tmp", &sb) == SUCCESS || mkdir("/usr/tmp", 01777) == SUCCESS) && min_free("/usr/tmp") >= sz)
- strcpy(pen, "/usr/tmp/instmp.XXXXXXXXXX");
+ strlcpy(pen, "/usr/tmp/instmp.XXXXXXXXXX", pensize);
else {
cleanup(0);
errx(2,
@@ -119,7 +119,7 @@ make_playpen(char *pen, size_t pensize, size_t sz)
"with more space and\ntry the command again", pen);
}
if (Current[0])
- strcpy(Previous, Current);
+ strlcpy(Previous, Current, sizeof(Previous));
else if (!getcwd(Previous, FILENAME_MAX)) {
cleanup(0);
err(1, "fatal error during execution: getcwd");
@@ -128,7 +128,7 @@ make_playpen(char *pen, size_t pensize, size_t sz)
cleanup(0);
errx(2, "can't chdir to '%s'", pen);
}
- strcpy(Current, pen);
+ strlcpy(Current, pen, sizeof(Current));
return Previous;
}
@@ -153,10 +153,10 @@ leave_playpen(char *save)
}
if (vsystem("rm -rf %s", Current))
pwarnx("couldn't remove temporary dir '%s'", Current);
- strcpy(Current, Previous); /* XXX */
+ strlcpy(Current, Previous, sizeof(Current)); /* XXX */
}
if (save)
- strcpy(Previous, save); /* XXX */
+ strlcpy(Previous, save, sizeof(Previous)); /* XXX */
else
Previous[0] = '\0';
signal(SIGINT, oldsig);
diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c
index 49ace232160..957135fa331 100644
--- a/usr.sbin/pkg_install/lib/plist.c
+++ b/usr.sbin/pkg_install/lib/plist.c
@@ -1,6 +1,6 @@
-/* $OpenBSD: plist.c,v 1.13 2001/11/07 20:57:24 espie Exp $ */
+/* $OpenBSD: plist.c,v 1.14 2003/04/04 08:56:01 avsm Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: plist.c,v 1.13 2001/11/07 20:57:24 espie Exp $";
+static const char *rcsid = "$OpenBSD: plist.c,v 1.14 2003/04/04 08:56:01 avsm Exp $";
#endif
/*
@@ -210,7 +210,7 @@ plist_cmd(char *s, char **arg)
char *cp;
char *sp;
- (void) strcpy(cmd, s);
+ (void) strlcpy(cmd, s, sizeof(cmd));
str_lowercase(cmd);
for (cp = cmd, sp = s ; *cp ; cp++, sp++) {
if (isspace(*cp)) {
diff --git a/usr.sbin/pkg_install/lib/str.c b/usr.sbin/pkg_install/lib/str.c
index fe9e653910e..b3b6a2a0141 100644
--- a/usr.sbin/pkg_install/lib/str.c
+++ b/usr.sbin/pkg_install/lib/str.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: str.c,v 1.6 2002/03/14 06:51:42 mpech Exp $ */
+/* $OpenBSD: str.c,v 1.7 2003/04/04 08:56:01 avsm Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: str.c,v 1.6 2002/03/14 06:51:42 mpech Exp $";
+static const char *rcsid = "$OpenBSD: str.c,v 1.7 2003/04/04 08:56:01 avsm Exp $";
#endif
/*
@@ -300,7 +300,7 @@ pmatch(const char *pattern, const char *pkg)
/* let's hope there's only one ... - HF */
/* returns -1 on error, 1 if found, 0 otherwise. */
int
-findmatchingname(const char *dir, const char *pattern, matchfn f, char *data)
+findmatchingname(const char *dir, const char *pattern, matchfn f, char *data, int len)
{
struct dirent *dp;
DIR *dirp;
@@ -318,7 +318,7 @@ findmatchingname(const char *dir, const char *pattern, matchfn f, char *data)
}
if (pmatch(pattern, dp->d_name)) {
if(f)
- f(dp->d_name, data);
+ f(dp->d_name, data, len);
found=1;
}
}
@@ -337,7 +337,7 @@ ispkgpattern(const char *pkg)
/* auxiliary function called by findbestmatchingname() */
static int
-findbestmatchingname_fn(const char *pkg, char *data)
+findbestmatchingname_fn(const char *pkg, char *data, int len)
{
/* if pkg > data */
char *s1, *s2;
@@ -346,7 +346,7 @@ findbestmatchingname_fn(const char *pkg, char *data)
s2=strrchr(data, '-')+1;
if(data[0] == '\0' || deweycmp(s1, GT, s2))
- strcpy(data, pkg);
+ strlcpy(data, pkg, len);
return 0;
}
@@ -361,8 +361,7 @@ findbestmatchingname(const char *dir, const char *pattern)
char buf[FILENAME_MAX];
buf[0]='\0';
- if (findmatchingname(dir, pattern, findbestmatchingname_fn, buf) > 0
- && buf[0] != '\0') {
+ if (findmatchingname(dir, pattern, findbestmatchingname_fn, buf, sizeof(buf)) > 0 && buf[0] != '\0') {
return strdup(buf);
}
return NULL;