summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-09-16 11:01:25 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-09-16 11:01:25 +0000
commit6f8727ec54463955317419f91e8695daa6aa9d45 (patch)
tree3af6e9fed2d56880b35a97e242533fc13620d0a6
parent09ee7c2c261c3af64d5de451da1a1dfa7b83f4bc (diff)
strcpy whacking; ci.c and expand.c need more work
-rw-r--r--usr.bin/sup/src/errmsg.c5
-rw-r--r--usr.bin/sup/src/path.c15
-rw-r--r--usr.bin/sup/src/scan.c11
-rw-r--r--usr.bin/sup/src/scm.c5
-rw-r--r--usr.bin/sup/src/stree.c6
-rw-r--r--usr.bin/sup/src/supcmain.c9
-rw-r--r--usr.bin/sup/src/supcmeat.c9
-rw-r--r--usr.bin/sup/src/supcmisc.c23
-rw-r--r--usr.bin/sup/src/supextern.h4
-rw-r--r--usr.bin/sup/src/supfilesrv.c15
-rw-r--r--usr.bin/sup/src/supscan.c6
11 files changed, 63 insertions, 45 deletions
diff --git a/usr.bin/sup/src/errmsg.c b/usr.bin/sup/src/errmsg.c
index 44f6b1c71ee..b8de4d0836a 100644
--- a/usr.bin/sup/src/errmsg.c
+++ b/usr.bin/sup/src/errmsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: errmsg.c,v 1.3 1997/04/01 07:34:59 todd Exp $ */
+/* $OpenBSD: errmsg.c,v 1.4 1997/09/16 11:01:15 deraadt Exp $ */
/*
* Copyright (c) 1991 Carnegie Mellon University
@@ -65,7 +65,8 @@ int cod;
if((cod >= 0) && (cod < sys_nerr))
return(sys_errlist[cod]);
- strcpy(unk,unkmsg);
+ strncpy(unk,unkmsg,sizeof unk-1);
+ unk[sizeof unk-1] = '\0';
*itoa(&unk[sizeof(unkmsg)-1],cod) = '\0';
return(unk);
diff --git a/usr.bin/sup/src/path.c b/usr.bin/sup/src/path.c
index 8becc2e50fa..eb1e8801736 100644
--- a/usr.bin/sup/src/path.c
+++ b/usr.bin/sup/src/path.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: path.c,v 1.3 1997/04/01 07:35:13 todd Exp $ */
+/* $OpenBSD: path.c,v 1.4 1997/09/16 11:01:15 deraadt Exp $ */
/*
* Copyright (c) 1991 Carnegie Mellon University
@@ -26,11 +26,12 @@
*/
/* path -- break filename into directory and file
*
- * path (filename,direc,file);
+ * path (filename,direc,file,filen);
* char *filename,*direc,*file;
+ * int filen;
* filename is input; direc and file are output (user-supplied).
* file will not have any trailing /; direc might.
- *
+ * filen is the length of the file buffer.
* Note these rules:
* 1. trailing / are ignored (except as first character)
* 2. x/y is x;y where y contains no / (x may contain /)
@@ -62,8 +63,9 @@
#include "supextern.h"
void
-path (original,direc,file)
+path (original,direc,file, filen)
char *original,*direc,*file;
+int filen;
{
register char *y;
/* x is direc */
@@ -91,8 +93,9 @@ char *original,*direc,*file;
}
/* find file name part */
- if (*y) strcpy (file,y);
- else strcpy (file,".");
+ if (*y) strncpy (file,y, filen-1);
+ else strncpy (file,".", filen-1);
+ file[filen-1] = '\0';
/* find directory part */
if (direc == y) strcpy (direc,".");
diff --git a/usr.bin/sup/src/scan.c b/usr.bin/sup/src/scan.c
index 5ae3dbe57a0..094e92f6c4e 100644
--- a/usr.bin/sup/src/scan.c
+++ b/usr.bin/sup/src/scan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scan.c,v 1.7 1997/09/16 10:42:51 deraadt Exp $ */
+/* $OpenBSD: scan.c,v 1.8 1997/09/16 11:01:16 deraadt Exp $ */
/*
* Copyright (c) 1992 Carnegie Mellon University
@@ -721,8 +721,10 @@ int always;
ename[i] = 0;
if (*newname)
(void) snprintf (filename,sizeof filename,"%s/%s",newname,ename);
- else
- (void) strcpy (filename,ename);
+ else {
+ (void) strncpy (filename,ename,sizeof filename-1);
+ filename[sizeof filename-1] = '\0';
+ }
listentry(ename,filename,newname,always);
}
closedir (dirp);
@@ -976,7 +978,8 @@ void *v;
{
FILE *scanF = v;
char fname[MAXPATHLEN*4+1];
- strcpy(fname, t->Tname);
+ strncpy(fname, t->Tname, sizeof fname-1);
+ fname[sizeof fname-1] = '\0';
fprintf(scanF,"X%s\n",fname);
return (SCMOK);
}
diff --git a/usr.bin/sup/src/scm.c b/usr.bin/sup/src/scm.c
index b7f096efb85..f5349b48643 100644
--- a/usr.bin/sup/src/scm.c
+++ b/usr.bin/sup/src/scm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scm.c,v 1.5 1997/07/25 21:05:42 mickey Exp $ */
+/* $OpenBSD: scm.c,v 1.6 1997/09/16 11:01:17 deraadt Exp $ */
/*
* Copyright (c) 1992 Carnegie Mellon University
@@ -432,7 +432,8 @@ char *myhost () /* find my host name */
return (NULL);
if ((h = gethostbyname (name)) == NULL)
return (NULL);
- (void) strcpy (name,h->h_name);
+ (void) strncpy (name,h->h_name,sizeof name-1);
+ name[sizeof name-1] = '\0';
}
return (name);
}
diff --git a/usr.bin/sup/src/stree.c b/usr.bin/sup/src/stree.c
index 4a7d7413aca..e27f6432227 100644
--- a/usr.bin/sup/src/stree.c
+++ b/usr.bin/sup/src/stree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: stree.c,v 1.4 1997/04/01 07:35:27 todd Exp $ */
+/* $OpenBSD: stree.c,v 1.5 1997/09/16 11:01:18 deraadt Exp $ */
/*
* Copyright (c) 1992 Carnegie Mellon University
@@ -255,7 +255,7 @@ TREE *t;
char *p;
{
register TREE *x;
- char buf[MAXPATHLEN+1];
+ char buf[MAXPATHLEN];
if (p == NULL)
return (NULL);
@@ -269,7 +269,7 @@ char *p;
if (*p != '/' && (x = Tsearch (t,".")) != NULL)
return (x);
(void) strncpy(buf, p, sizeof(buf)-1);
- buf[MAXPATHLEN] = '\0';
+ buf[sizeof buf-1] = '\0';
while ((p = strrchr(buf, '/')) != NULL) {
while (p >= buf && *(p-1) == '/')
p--;
diff --git a/usr.bin/sup/src/supcmain.c b/usr.bin/sup/src/supcmain.c
index 9c5009cd1fa..65c9eb99a9b 100644
--- a/usr.bin/sup/src/supcmain.c
+++ b/usr.bin/sup/src/supcmain.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: supcmain.c,v 1.6 1997/09/16 10:42:52 deraadt Exp $ */
+/* $OpenBSD: supcmain.c,v 1.7 1997/09/16 11:01:19 deraadt Exp $ */
/*
* Copyright (c) 1992 Carnegie Mellon University
@@ -623,9 +623,10 @@ char **argv;
argv++;
}
if ((p = (char *)getlogin()) ||
- ((pw = getpwuid ((int)getuid())) && (p = pw->pw_name)))
- (void) strcpy (username,p);
- else
+ ((pw = getpwuid ((int)getuid())) && (p = pw->pw_name))) {
+ (void) strncpy (username,p, sizeof username-1);
+ username[sizeof username-1] = '\0';
+ } else
*username = '\0';
if (*supfname) {
f = fopen (supfname,"r");
diff --git a/usr.bin/sup/src/supcmeat.c b/usr.bin/sup/src/supcmeat.c
index eae71b0c8f8..f0cafda6ffa 100644
--- a/usr.bin/sup/src/supcmeat.c
+++ b/usr.bin/sup/src/supcmeat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: supcmeat.c,v 1.7 1997/09/16 10:42:54 deraadt Exp $ */
+/* $OpenBSD: supcmeat.c,v 1.8 1997/09/16 11:01:20 deraadt Exp $ */
/*
* Copyright (c) 1992 Carnegie Mellon University
@@ -919,7 +919,7 @@ register struct stat *statp;
t->Tname);
return (TRUE); /* mark upgrade as nogood */
}
- path (t->Tname,dirpart,filepart);
+ path (t->Tname,dirpart,filepart,sizeof filepart);
(void) snprintf (filename,sizeof filename,
FILEBACKUP,dirpart,filepart);
fout = fopen (filename,"w");
@@ -1060,7 +1060,7 @@ char *from; /* 0 if reading from network */
/* Now try hard to find a temp file name. Try VERY hard. */
for (;;) {
/* try destination directory */
- path (to,dpart,fpart);
+ path (to,dpart,fpart,sizeof fpart);
(void) snprintf (tname,sizeof tname,
"%s/#%d.sup",dpart,thispid);
tof = open (tname,(O_WRONLY|O_CREAT|O_TRUNC),0600);
@@ -1255,7 +1255,8 @@ int x;
"%s-%s",collname,release);
} else {
relsufix[0] = '\0';
- (void) strcpy (collrelname,collname);
+ (void) strncpy (collrelname,collname,sizeof collrelname-1);
+ collrelname[sizeof collrelname-1] = '\0';
}
dontjump = TRUE; /* once here, no more longjmp */
(void) netcrypt ((char *)NULL);
diff --git a/usr.bin/sup/src/supcmisc.c b/usr.bin/sup/src/supcmisc.c
index cc4e962a126..52d1d16e308 100644
--- a/usr.bin/sup/src/supcmisc.c
+++ b/usr.bin/sup/src/supcmisc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: supcmisc.c,v 1.5 1997/09/16 10:42:55 deraadt Exp $ */
+/* $OpenBSD: supcmisc.c,v 1.6 1997/09/16 11:01:21 deraadt Exp $ */
/*
* Copyright (c) 1992 Carnegie Mellon University
@@ -82,8 +82,8 @@ prtime ()
logerr ("Can't change to base directory %s for collection %s",
thisC->Cbase,thisC->Cname);
twhen = getwhen(thisC->Cname,relsufix);
- (void) strcpy (buf,ctime (&twhen));
- buf[strlen(buf)-1] = '\0';
+ (void) strncpy (buf,ctime (&twhen), sizeof buf-1);
+ buf[sizeof buf-1] = '\0';
loginfo ("Last update occurred at %s for collection %s",
buf,thisC->Cname);
}
@@ -92,7 +92,7 @@ int establishdir (fname)
char *fname;
{
char dpart[STRINGLENGTH],fpart[STRINGLENGTH];
- path (fname,dpart,fpart);
+ path (fname,dpart,fpart,sizeof fpart);
return (estabd (fname,dpart));
}
@@ -104,7 +104,7 @@ char *fname,*dname;
register int x;
if (stat (dname,&sbuf) >= 0) return (FALSE); /* exists */
- path (dname,dpart,fpart);
+ path (dname,dpart,fpart,sizeof fpart);
if (strcmp (fpart,".") == 0) { /* dname is / or . */
notify ("SUP: Can't create directory %s for %s\n",dname,fname);
return (TRUE);
@@ -262,8 +262,10 @@ va_dcl
if ((thisC->Cflags&CFURELSUF) && thisC->Crelease)
(void) snprintf (collrelname,sizeof collrelname,
"%s-%s",collname,thisC->Crelease);
- else
- (void) strcpy (collrelname,collname);
+ else {
+ (void) strncpy (collrelname,collname,sizeof collrelname-1);
+ collrelname[sizeof collrelname-1] = '\0';
+ }
if (noteF == NULL) {
if ((thisC->Cflags&CFMAIL) && thisC->Cnotify) {
@@ -314,9 +316,10 @@ time_t time;
static char buf[STRINGLENGTH];
int len;
- (void) strcpy (buf,ctime (&time));
+ (void) strncpy (buf,ctime (&time), sizeof buf-1);
+ buf[sizeof buf-1] = '\0';
len = strlen(buf+4)-6;
- (void) strncpy (buf,buf+4,len);
- buf[len] = '\0';
+ (void) strncpy (buf,buf+4,len); /* XXX TDR */
+ buf[sizeof buf-1] = '\0';
return (buf);
}
diff --git a/usr.bin/sup/src/supextern.h b/usr.bin/sup/src/supextern.h
index d1a13d941e2..50f4d82d9ef 100644
--- a/usr.bin/sup/src/supextern.h
+++ b/usr.bin/sup/src/supextern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: supextern.h,v 1.1 1997/04/01 07:35:41 todd Exp $ */
+/* $OpenBSD: supextern.h,v 1.2 1997/09/16 11:01:22 deraadt Exp $ */
#ifndef __P
#ifdef __STDC__
@@ -44,7 +44,7 @@ void encode __P((char *, char *, int));
char *nxtarg __P((char **, char *));
/* path.c */
-void path __P((char *, char *, char *));
+void path __P((char *, char *, char *, int));
/* quit.c */
void quit __P((int, char *, ...));
diff --git a/usr.bin/sup/src/supfilesrv.c b/usr.bin/sup/src/supfilesrv.c
index 3676d7e071a..785669c9823 100644
--- a/usr.bin/sup/src/supfilesrv.c
+++ b/usr.bin/sup/src/supfilesrv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: supfilesrv.c,v 1.10 1997/09/16 10:42:59 deraadt Exp $ */
+/* $OpenBSD: supfilesrv.c,v 1.11 1997/09/16 11:01:23 deraadt Exp $ */
/*
* Copyright (c) 1992 Carnegie Mellon University
@@ -1464,12 +1464,16 @@ int fileuid,filegid;
return (errbuf);
}
grp = getgrgid (filegid);
- if (grp) group = strcpy (nbuf,grp->gr_name);
+ if (grp) {
+ group = strncpy (nbuf,grp->gr_name, sizeof nbuf-1);
+ nbuf[sizeof nbuf-1] = '\0';
+ }
else group = NULL;
account = NULL;
pswdp = NULL;
} else {
- (void) strcpy (nbuf,namep);
+ (void) strncpy (nbuf,namep, sizeof nbuf-1);
+ nbuf[sizeof nbuf-1] = '\0';
account = group = strchr (nbuf,',');
if (group != NULL) {
*group++ = '\0';
@@ -1666,9 +1670,10 @@ time_t time;
static char buf[STRINGLENGTH];
int len;
- (void) strcpy (buf,ctime (&time));
+ (void) strncpy (buf,ctime (&time), sizeof buf-1);
+ buf[sizeof buf-1] = '\0';
len = strlen(buf+4)-6;
- (void) strncpy (buf,buf+4,len);
+ (void) strncpy (buf,buf+4,len); /* XXX TDR */
buf[len] = '\0';
return (buf);
}
diff --git a/usr.bin/sup/src/supscan.c b/usr.bin/sup/src/supscan.c
index 19afba97438..00de100f10a 100644
--- a/usr.bin/sup/src/supscan.c
+++ b/usr.bin/sup/src/supscan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: supscan.c,v 1.7 1997/09/16 10:43:01 deraadt Exp $ */
+/* $OpenBSD: supscan.c,v 1.8 1997/09/16 11:01:24 deraadt Exp $ */
/*
* Copyright (c) 1992 Carnegie Mellon University
@@ -236,7 +236,7 @@ char **argv;
usage ();
firstC = NULL;
c = &firstC;
- (void) snprintf (buf,sizeof buf,sizeof buf,FILEHOSTS,DEFDIR);
+ (void) snprintf (buf,sizeof buf,FILEHOSTS,DEFDIR);
if ((f = fopen (buf,"r")) == NULL)
quit (1,"supscan: Unable to open %s\n",buf);
while ((p = fgets (buf,STRINGLENGTH,f)) != NULL) {
@@ -300,7 +300,7 @@ register char *filename,*collname,*basedir;
(void) fclose (f);
}
if (basedir == NULL) {
- (void) snprintf (buf,sizeof buf,sizeof buf,
+ (void) snprintf (buf,sizeof buf,
FILEBASEDEFAULT,collname);
basedir = salloc (buf);
}