[rtems commit] ftpd: Check return status of getsockname()
Sebastian Huber
sebh at rtems.org
Tue Oct 9 05:44:11 UTC 2018
Module: rtems
Branch: master
Commit: 2f784d72d35f2712e1c8053327caf6e240837f3c
Changeset: http://git.rtems.org/rtems/commit/?id=2f784d72d35f2712e1c8053327caf6e240837f3c
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Mon Oct 8 08:14:40 2018 +0200
ftpd: Check return status of getsockname()
Update #3530.
---
cpukit/ftpd/ftpd.c | 40 ++++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/cpukit/ftpd/ftpd.c b/cpukit/ftpd/ftpd.c
index 08c39da..4657949 100644
--- a/cpukit/ftpd/ftpd.c
+++ b/cpukit/ftpd/ftpd.c
@@ -1531,27 +1531,31 @@ command_pasv(FTPD_SessionInfo_t *info)
syslog(LOG_ERR, "ftpd: Error binding PASV socket: %s", serr());
else if (0 > listen(s, 1))
syslog(LOG_ERR, "ftpd: Error listening on PASV socket: %s", serr());
- else if(set_socket_timeout(s, info->idle))
+ else if (set_socket_timeout(s, info->idle))
{
- char buf[FTPD_BUFSIZE];
- unsigned char const *ip, *p;
-
- getsockname(s, (struct sockaddr *)&addr, &addrLen);
- ip = (unsigned char const*)&(addr.sin_addr);
- p = (unsigned char const*)&(addr.sin_port);
- snprintf(buf, FTPD_BUFSIZE, "Entering passive mode (%u,%u,%u,%u,%u,%u).",
- ip[0], ip[1], ip[2], ip[3], p[0], p[1]);
- send_reply(info, 227, buf);
-
- info->pasv_socket = accept(s, (struct sockaddr *)&addr, &addrLen);
- if (0 > info->pasv_socket)
- syslog(LOG_ERR, "ftpd: Error accepting PASV connection: %s", serr());
- else
+ if (0 == getsockname(s, (struct sockaddr *)&addr, &addrLen))
{
- close_socket(s);
- s = -1;
- err = 0;
+ char buf[FTPD_BUFSIZE];
+ unsigned char const *ip, *p;
+
+ ip = (unsigned char const*)&(addr.sin_addr);
+ p = (unsigned char const*)&(addr.sin_port);
+ snprintf(buf, FTPD_BUFSIZE, "Entering passive mode (%u,%u,%u,%u,%u,%u).",
+ ip[0], ip[1], ip[2], ip[3], p[0], p[1]);
+ send_reply(info, 227, buf);
+
+ info->pasv_socket = accept(s, (struct sockaddr *)&addr, &addrLen);
+ if (0 > info->pasv_socket)
+ syslog(LOG_ERR, "ftpd: Error accepting PASV connection: %s", serr());
+ else
+ {
+ close_socket(s);
+ s = -1;
+ err = 0;
+ }
}
+ else
+ syslog(LOG_ERR, "ftpd: Cannot get socket name: %s", serr());
}
}
if(err)
More information about the vc
mailing list