Various fixes from Nicholas Marriott sent to openbsd-tech and in private email:

* Prevent segfault if a .netrc token is too long.
* Prevent segfault when using a macro from an empty macdef.
* Check more return values.
This commit is contained in:
lukem 2007-04-12 01:28:13 +00:00
parent 20341ba8ef
commit b1e08b00c3
2 changed files with 40 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ruserpass.c,v 1.31 2006/01/31 20:01:23 christos Exp $ */
/* $NetBSD: ruserpass.c,v 1.32 2007/04/12 01:28:13 lukem Exp $ */
/*
* Copyright (c) 1985, 1993, 1994
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)ruserpass.c 8.4 (Berkeley) 4/27/95";
#else
__RCSID("$NetBSD: ruserpass.c,v 1.31 2006/01/31 20:01:23 christos Exp $");
__RCSID("$NetBSD: ruserpass.c,v 1.32 2007/04/12 01:28:13 lukem Exp $");
#endif
#endif /* not lint */
@ -102,7 +102,7 @@ ruserpass(const char *host, char **aname, char **apass, char **aacct)
if ((mydomain = strchr(myname, '.')) == NULL)
mydomain = "";
next:
while ((t = token())) switch(t) {
while ((t = token()) > 0) switch(t) {
case DEFAULT:
usedefault = 1;
@ -110,7 +110,9 @@ ruserpass(const char *host, char **aname, char **apass, char **aacct)
case MACH:
if (!usedefault) {
if (token() != ID)
if ((t = token()) == -1)
goto bad;
if (t != ID)
continue;
/*
* Allow match either for user's input host name
@ -134,10 +136,13 @@ ruserpass(const char *host, char **aname, char **apass, char **aacct)
continue;
}
match:
while ((t = token()) && t != MACH && t != DEFAULT) switch(t) {
while ((t = token()) > 0 &&
t != MACH && t != DEFAULT) switch(t) {
case LOGIN:
if (token()) {
if ((t = token()) == -1)
goto bad;
if (t) {
if (*aname == NULL)
*aname = ftp_strdup(tokval);
else {
@ -154,7 +159,9 @@ ruserpass(const char *host, char **aname, char **apass, char **aacct)
warnx("Remove password or make file unreadable by others.");
goto bad;
}
if (token() && *apass == NULL)
if ((t = token()) == -1)
goto bad;
if (t && *apass == NULL)
*apass = ftp_strdup(tokval);
break;
case ACCOUNT:
@ -164,7 +171,9 @@ ruserpass(const char *host, char **aname, char **apass, char **aacct)
warnx("Remove account or make file unreadable by others.");
goto bad;
}
if (token() && *aacct == NULL)
if ((t = token()) == -1)
goto bad;
if (t && *aacct == NULL)
*aacct = ftp_strdup(tokval);
break;
case MACDEF:
@ -225,9 +234,13 @@ ruserpass(const char *host, char **aname, char **apass, char **aacct)
}
*tmp = c;
if (*tmp == '\n') {
if (*(tmp-1) == '\0') {
macros[macnum++].mac_end = tmp - 1;
break;
if (tmp == macros[macnum].mac_start) {
macros[macnum++].mac_end = tmp;
break;
} else if (*(tmp - 1) == '\0') {
macros[macnum++].mac_end =
tmp - 1;
break;
}
*tmp = '\0';
}
@ -246,6 +259,8 @@ ruserpass(const char *host, char **aname, char **apass, char **aacct)
goto done;
}
done:
if (t == -1)
goto bad;
(void)fclose(cfile);
return (0);
bad:
@ -271,16 +286,26 @@ token(void)
if (c == '"') {
while ((c = getc(cfile)) != EOF && c != '"') {
if (c == '\\')
c = getc(cfile);
if ((c = getc(cfile)) == EOF)
break;
*cp++ = c;
if (cp == tokval + sizeof(tokval)) {
warnx("Token in .netrc too long");
return (-1);
}
}
} else {
*cp++ = c;
while ((c = getc(cfile)) != EOF
&& c != '\n' && c != '\t' && c != ' ' && c != ',') {
if (c == '\\')
c = getc(cfile);
if ((c = getc(cfile)) == EOF)
break;
*cp++ = c;
if (cp == tokval + sizeof(tokval)) {
warnx("Token in .netrc too long");
return (-1);
}
}
}
*cp = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: version.h,v 1.60 2007/04/11 05:03:25 lukem Exp $ */
/* $NetBSD: version.h,v 1.61 2007/04/12 01:28:13 lukem Exp $ */
/*-
* Copyright (c) 1999-2007 The NetBSD Foundation, Inc.
* All rights reserved.
@ -40,5 +40,5 @@
#endif
#ifndef FTP_VERSION
#define FTP_VERSION "20070411"
#define FTP_VERSION "20070412"
#endif