diff options
author | 2000-05-03 19:50:41 +0000 | |
---|---|---|
committer | 2000-05-03 19:50:41 +0000 | |
commit | 05c3fd20657590a65a39c76cbb4a01d519f1fb84 (patch) | |
tree | d52744dbce42f3b0e1140cb0690bcba8cedefb8b | |
parent | sync (diff) | |
download | wireguard-openbsd-05c3fd20657590a65a39c76cbb4a01d519f1fb84.tar.xz wireguard-openbsd-05c3fd20657590a65a39c76cbb4a01d519f1fb84.zip |
if no /etc/services file, use defaults. found by millert, fixed by itojun
-rw-r--r-- | usr.bin/ftp/fetch.c | 14 | ||||
-rw-r--r-- | usr.bin/ftp/ftp.c | 21 |
2 files changed, 31 insertions, 4 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index 66eb3567b6c..164678e867c 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.29 2000/05/02 00:54:53 itojun Exp $ */ +/* $OpenBSD: fetch.c,v 1.30 2000/05/03 19:50:41 deraadt Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- @@ -38,7 +38,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: fetch.c,v 1.29 2000/05/02 00:54:53 itojun Exp $"; +static char rcsid[] = "$OpenBSD: fetch.c,v 1.30 2000/05/03 19:50:41 deraadt Exp $"; #endif /* not lint */ /* @@ -290,6 +290,16 @@ url_get(origline, proxyenv, outfile) hints.ai_socktype = SOCK_STREAM; port = portnum ? portnum : httpport; error = getaddrinfo(host, port, &hints, &res0); + if (error == EAI_SERVICE && port == httpport) { + /* + * If the services file is corrupt/missing, fall back + * on our hard-coded defines. + */ + char pbuf[NI_MAXSERV]; + + snprintf(pbuf, sizeof(pbuf), "%d", HTTP_PORT); + error = getaddrinfo(host, pbuf, &hints, &res0); + } if (error) { warnx("%s: %s", gai_strerror(error), host); goto cleanup_url_get; diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c index b4f81b67d92..ff7d41394d4 100644 --- a/usr.bin/ftp/ftp.c +++ b/usr.bin/ftp/ftp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ftp.c,v 1.34 1999/12/08 12:57:06 itojun Exp $ */ +/* $OpenBSD: ftp.c,v 1.35 2000/05/03 19:50:41 deraadt Exp $ */ /* $NetBSD: ftp.c,v 1.27 1997/08/18 10:20:23 lukem Exp $ */ /* @@ -67,7 +67,7 @@ #if 0 static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94"; #else -static char rcsid[] = "$OpenBSD: ftp.c,v 1.34 1999/12/08 12:57:06 itojun Exp $"; +static char rcsid[] = "$OpenBSD: ftp.c,v 1.35 2000/05/03 19:50:41 deraadt Exp $"; #endif #endif /* not lint */ @@ -145,6 +145,23 @@ hookup(host, port) hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = 0; error = getaddrinfo(host, port, &hints, &res0); + if (error == EAI_SERVICE) { + /* + * If the services file is corrupt/missing, fall back + * on our hard-coded defines. + */ + char pbuf[NI_MAXSERV]; + + pbuf[0] = '\0'; + if (strcmp(port, "ftp") == 0) + snprintf(pbuf, sizeof(pbuf), "%d", FTP_PORT); + else if (strcmp(port, "ftpgate") == 0) + snprintf(pbuf, sizeof(pbuf), "%d", GATE_PORT); + else if (strcmp(port, "http") == 0) + snprintf(pbuf, sizeof(pbuf), "%d", HTTP_PORT); + if (pbuf[0]) + error = getaddrinfo(host, pbuf, &hints, &res0); + } if (error) { warn(gai_strerror(error)); code = -1; |