|
|||||||||||
|
First hunk of diffs
From: Warner Losh <imp(at)village.org>
Date: Tue Apr 29 1997 - 18:51:28 EDT I've been running with these diffs now for some time. These seem sane. Comments? Warner Here's a digest of what I'm doing.
libc/db/btree/bt_open.c
libc/gen/glob.c >From OpenBSD: Working file: glob.c revision 1.3 date: 1996/09/11 19:22:46; author: deraadt; state: Exp; lines: +2 -2 protect $HOME expansion; from das33@cornell.edu
libc/net/res_comp.c
libc/net/res_init.c >From OpenBSD: Working file: res_init.c revision 1.6 date: 1996/08/27 03:32:53; author: deraadt; state: Exp; lines: +4 -1 use strncpy correctly revision 1.5 date: 1996/08/25 10:11:02; author: deraadt; state: Exp; lines: +5 -4 use issetugid() libc/nls/msgcat.c >From OpenBSD: Working file: catopen.c revision 1.6 date: 1996/08/26 00:17:20; author: deraadt; state: Exp; lines: +6 -8 use issetugid() to protect against bad getenv libc/stdio/mktemp.c libc/stdio/tempnam.c libc/stdio/tmpnam.c >From OpenBSD: 95% of common uses of these are incorrect and insecure. correct use is incredibly rare. Time for some education! Also, 1.3 and 1.4 from OpenBSD's tempname have been merged in. These only cause TMPDIR env to be fetched when we aren't running setuid or setgid. libc/stdtime/localtime.c >From OpenBSD: Working file: localtime.c revision 1.10 date: 1997/04/02 03:57:30; author: deraadt; state: Exp; lines: +6 -2 correctly code the classes of permitted TZ specifications for the issetugid() case. thanks bitblt and tholo revision 1.6 date: 1996/09/05 12:28:23; author: deraadt; state: Exp; lines: +2 -2 1 char oflow revision 1.5 date: 1996/08/25 10:11:11; author: deraadt; state: Exp; lines: +2 -2 use issetugid() And some unknown witespace change that shouldn't be there.... libedit/el.c >From OpenBSD: Working file: el.c revision 1.2 date: 1996/08/26 00:17:22; author: deraadt; state: Exp; lines: +2 -2 use issetugid() to protect against bad getenv libftpio/ftpio.c
>From Julian A:
libskey/skeyaccess.c
>From Julian A:
Also, fix 1 character overflow (which may also be in OpenBSD). Index: libc/db/btree/bt_open.c RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/db/btree/bt_open.c,v retrieving revision 1.4 diff -u -r1.4 bt_open.c --- bt_open.c 1996/07/12 18:53:13 1.4 +++ bt_open.c 1997/04/28 20:00:02 @@ -388,10 +388,11 @@ {
sigset_t set, oset;
int fd;
- char *envtmp;
+ char *envtmp = NULL;
char path[MAXPATHLEN];
- envtmp = getenv("TMPDIR");
+ if (issetugid() == 0)
+ envtmp = getenv("TMPDIR");
(void)snprintf(path,
sizeof(path), "%s/bt.XXXXXX", envtmp ? envtmp : "/tmp");
Index: libc/gen/glob.c RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/gen/glob.c,v retrieving revision 1.8 diff -u -r1.8 glob.c --- glob.c 1997/04/04 19:16:08 1.8 +++ glob.c 1997/04/28 20:05:28 Index: libc/net/res_comp.c RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/net/res_comp.c,v retrieving revision 1.10 diff -u -r1.10 res_comp.c --- res_comp.c 1997/02/22 15:00:29 1.10 +++ res_comp.c 1997/03/28 17:17:55 @@ -95,7 +95,7 @@ dn = exp_dn; cp = comp_dn; - eom = exp_dn + length; + eom = exp_dn + (length > MAXDNAME ? MAXDNAME : length); /* * fetch next label in domain name */ Index: libc/net/res_init.c RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/net/res_init.c,v retrieving revision 1.12 diff -u -r1.12 res_init.c --- res_init.c 1997/02/22 15:00:32 1.12 +++ res_init.c 1997/04/28 20:15:17 if ((*cp == '\0') || (*cp == '\n')) continue; strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); + _res.defdname[sizeof(_res.defdname) - 1] = '\0'; if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) *cp = '\0'; havesearch = 0; @@ -246,6 +248,7 @@ if ((*cp == '\0') || (*cp == '\n')) continue; strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); + _res.defdname[sizeof(_res.defdname) - 1] = '\0'; if ((cp = strchr(_res.defdname, '\n')) != NULL) *cp = '\0'; /* @@ -379,7 +382,9 @@ #endif /* !RFC1535 */ }
Index: libc/stdio/mktemp.c RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/stdio/mktemp.c,v retrieving revision 1.7 diff -u -r1.7 mktemp.c --- mktemp.c 1997/04/07 18:01:10 1.7 +++ mktemp.c 1997/04/26 18:49:42 @@ -59,10 +59,20 @@ }
char *
char *path;
return(_gettemp(path, (int *)NULL) ? path : (char *)NULL);
+}
+
+__warn_references(mktemp,
+ "warning: mktemp() possibly used unsafely; consider using mkstemp()");
+
+char *
+mktemp(path)
+ char *path;
+{
+ return(_mktemp(path));
}
static int
RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/stdio/tempnam.c,v retrieving revision 1.5 diff -u -r1.5 tempnam.c --- tempnam.c 1997/02/22 15:02:37 1.5 +++ tempnam.c 1997/04/28 19:51:28 @@ -47,6 +47,11 @@ #include <unistd.h> #include <paths.h> +__warn_references(tempnam, + "warning: tempnam() possibly used unsafely; consider using mkstemp()"); + +extern char *_mktemp __P((char *)); + char * tempnam(dir, pfx)
const char *dir, *pfx;
if (!pfx)
pfx = "tmp.";
- if ((f = getenv("TMPDIR"))) {
+ if (issetugid() == 0 && (f = getenv("TMPDIR"))) {
(void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
*(f + strlen(f) - 1) == '/'? "": "/", pfx);
if ((f = mktemp(name)))
Index: libc/stdio/tmpnam.c RCS file: /home/imp/FreeBSD/CVS/src/lib/libc/stdio/tmpnam.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 tmpnam.c --- tmpnam.c 1994/05/27 04:57:32 1.1.1.1 +++ tmpnam.c 1997/04/28 19:52:25 @@ -43,6 +43,11 @@ #include <stdio.h> #include <unistd.h> +__warn_references(tmpnam, + "warning: tmpnam() possibly used unsafely; consider using mkstemp()"); + +extern char *_mktemp __P((char *)); + char * tmpnam(s)
char *s;
RCS file: /home/imp/FreeBSD/CVS/src/lib/libedit/el.c,v retrieving revision 1.3 diff -u -r1.3 el.c --- el.c 1997/03/23 23:17:22 1.3 +++ el.c 1997/04/28 20:23:05
#ifdef DEBUG
el->el_errfile = fopen(tty, "w");
if (el->el_errfile == NULL) {
extern errno;
Index: libftpio/ftpio.c RCS file: /home/imp/FreeBSD/CVS/src/lib/libftpio/ftpio.c,v retrieving revision 1.25 diff -u -r1.25 ftpio.c --- ftpio.c 1997/02/22 15:06:50 1.25 +++ ftpio.c 1997/03/22 05:07:29 @@ -35,6 +35,7 @@ #include#include <string.h> #include <unistd.h> +#include <sys/param.h> #define SUCCESS 0 #define FAILURE -1 @@ -701,7 +702,7 @@ return FAILURE; } ftp->addrtype = sin.sin_family = he->h_addrtype; - bcopy(he->h_addr, (char *)&sin.sin_addr, he->h_length); + bcopy(he->h_addr, (char *)&sin.sin_addr, MIN(he->h_length,sizeof(sin.sin_addr))); } sin.sin_port = htons(port); Index: libskey/skeyaccess.c RCS file: /home/imp/FreeBSD/CVS/src/lib/libskey/skeyaccess.c,v retrieving revision 1.7 diff -u -r1.7 skeyaccess.c --- skeyaccess.c 1996/10/17 21:49:34 1.7 +++ skeyaccess.c 1997/03/22 05:08:11 @@ -408,12 +408,11 @@
for (i = 0; i < MAX_ADDR && hp->h_addr_list[i]; i++)
memcpy((char *) &list[i],
- hp->h_addr_list[i], hp->h_length);
+ hp->h_addr_list[i], (length=MIN(hp->h_length, sizeof(struct in_addr))));
list[i].s_addr = 0;
strncpy(buf, hp->h_name, MAXHOSTNAMELEN);
- buf[MAXHOSTNAMELEN] = 0;
- length = hp->h_length; + buf[MAXHOSTNAMELEN - 1] = 0;
/*
* Wipe addresses that appear to belong to someone else. We will get
Received on Tue Apr 29 15:51:37 1997This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 12:41:02 EDT |
||||||||||
|
|||||||||||