1 --- src/ftpd.c.00 Wed Jan 29 12:00:12 2003
2 +++ src/ftpd.c Wed Jan 29 12:20:53 2003
11 @@ -4873,32 +4874,41 @@
15 - file = getdatasock(mode);
17 - reply(425, "Can't create data socket (%s,%d): %s.",
18 - inet_ntoa(data_source.sin_addr),
19 - ntohs(data_source.sin_port), strerror(errno));
22 - data = fileno(file);
23 - (void) signal(SIGALRM, alarm_signal);
24 - alarm(timeout_connect);
25 - while (connect(data, (struct sockaddr *) &data_dest,
26 - sizeof(data_dest)) < 0) {
28 + file = getdatasock(mode);
30 + reply(425, "Can't create data socket (%s,%d): %s.",
31 + inet_ntoa(data_source.sin_addr),
32 + ntohs(data_source.sin_port), strerror(errno));
35 + data = fileno(file);
36 + (void) signal(SIGALRM, alarm_signal);
37 + alarm(timeout_connect);
38 + cval = connect(data, (struct sockaddr *) &data_dest, sizeof(data_dest));
41 - if ((errno == EADDRINUSE || errno == EINTR) && retry < swaitmax) {
42 - sleep((unsigned) swaitint);
44 - (void) signal(SIGALRM, alarm_signal);
45 - alarm(timeout_connect);
49 + * When connect fails, the state of the socket is unspecified so
50 + * it should be closed and a new socket created for each connection
51 + * attempt. This also prevents denial of service problems when
52 + * running on operating systems that only allow one non-connected
53 + * socket bound to the same local address.
55 + (void) fclose(file);
58 + if ((errno == EADDRINUSE || errno == EINTR) && retry < swaitmax) {
59 + sleep((unsigned) swaitint);
63 + perror_reply(425, "Can't build data connection");
67 - perror_reply(425, "Can't build data connection");
68 - (void) fclose(file);
73 + } while (cval == -1);
75 (void) setsockopt(pdata, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on));