mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-23 21:21:05 +01:00
Move determination of socket buffer sizes from startup to the first time a
socket is used. The previous code structure assumed that AF_INET sockets were always available, which is an invalid assumption on IPv6-only systems. This merges the fololowing revisions from NetBSD: src/usr.bin/ftp/main.c 1.120 src/usr.bin/ftp/util.c 1.156 PR: bin/162661 Tested by: bz Obtained from: NetBSD MFC after: 1 week
This commit is contained in:
parent
6975edd9d0
commit
49e49bdbc1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=232779
@ -146,9 +146,8 @@ main(int volatile argc, char **volatile argv)
|
||||
struct passwd *pw;
|
||||
char *cp, *ep, *anonpass, *upload_path, *src_addr;
|
||||
const char *anonuser;
|
||||
int dumbterm, s, isupload;
|
||||
int dumbterm, isupload;
|
||||
size_t len;
|
||||
socklen_t slen;
|
||||
|
||||
tzset();
|
||||
#if 0 /* tnftp */ /* XXX */
|
||||
@ -213,35 +212,6 @@ main(int volatile argc, char **volatile argv)
|
||||
if (cp != NULL && strlcpy(netrc, cp, sizeof(netrc)) >= sizeof(netrc))
|
||||
errx(1, "$NETRC `%s': %s", cp, strerror(ENAMETOOLONG));
|
||||
|
||||
/*
|
||||
* Get the default socket buffer sizes if we don't already have them.
|
||||
* It doesn't matter which socket we do this to, because on the first
|
||||
* call no socket buffer sizes will have been modified, so we are
|
||||
* guaranteed to get the system defaults.
|
||||
*/
|
||||
s = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (s == -1)
|
||||
err(1, "Can't create socket to determine default socket sizes");
|
||||
slen = sizeof(rcvbuf_size);
|
||||
if (getsockopt(s, SOL_SOCKET, SO_RCVBUF,
|
||||
(void *)&rcvbuf_size, &slen) == -1)
|
||||
err(1, "Unable to get default rcvbuf size");
|
||||
slen = sizeof(sndbuf_size);
|
||||
if (getsockopt(s, SOL_SOCKET, SO_SNDBUF,
|
||||
(void *)&sndbuf_size, &slen) == -1)
|
||||
err(1, "Unable to get default sndbuf size");
|
||||
(void)close(s);
|
||||
/* sanity check returned buffer sizes */
|
||||
if (rcvbuf_size <= 0)
|
||||
rcvbuf_size = 8 * 1024;
|
||||
if (sndbuf_size <= 0)
|
||||
sndbuf_size = 8 * 1024;
|
||||
|
||||
if (sndbuf_size > 8 * 1024 * 1024)
|
||||
sndbuf_size = 8 * 1024 * 1024;
|
||||
if (rcvbuf_size > 8 * 1024 * 1024)
|
||||
rcvbuf_size = 8 * 1024 * 1024;
|
||||
|
||||
marg_sl = ftp_sl_init();
|
||||
if ((tmpdir = getenv("TMPDIR")) == NULL)
|
||||
tmpdir = _PATH_TMP;
|
||||
|
@ -1060,6 +1060,32 @@ strsuftoi(const char *arg)
|
||||
void
|
||||
setupsockbufsize(int sock)
|
||||
{
|
||||
socklen_t slen;
|
||||
|
||||
if (0 == rcvbuf_size) {
|
||||
slen = sizeof(rcvbuf_size);
|
||||
if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF,
|
||||
(void *)&rcvbuf_size, &slen) == -1)
|
||||
err(1, "Unable to determine rcvbuf size");
|
||||
if (rcvbuf_size <= 0)
|
||||
rcvbuf_size = 8 * 1024;
|
||||
if (rcvbuf_size > 8 * 1024 * 1024)
|
||||
rcvbuf_size = 8 * 1024 * 1024;
|
||||
DPRINTF("setupsockbufsize: rcvbuf_size determined as %d\n",
|
||||
rcvbuf_size);
|
||||
}
|
||||
if (0 == sndbuf_size) {
|
||||
slen = sizeof(sndbuf_size);
|
||||
if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF,
|
||||
(void *)&sndbuf_size, &slen) == -1)
|
||||
err(1, "Unable to determine sndbuf size");
|
||||
if (sndbuf_size <= 0)
|
||||
sndbuf_size = 8 * 1024;
|
||||
if (sndbuf_size > 8 * 1024 * 1024)
|
||||
sndbuf_size = 8 * 1024 * 1024;
|
||||
DPRINTF("setupsockbufsize: sndbuf_size determined as %d\n",
|
||||
sndbuf_size);
|
||||
}
|
||||
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
|
||||
(void *)&sndbuf_size, sizeof(sndbuf_size)) == -1)
|
||||
|
Loading…
Reference in New Issue
Block a user