|
From: | Rachid Koucha |
Subject: | [bug-inetutils] Bug in inetutils-1.6: FTPD transfers files with a size of 0 |
Date: | Tue, 13 Jan 2009 23:04:12 +0100 |
User-agent: | Thunderbird 2.0.0.19 (X11/20090105) |
Hi, On platforms where HAVE_MMAP is not defined, FTPD transfers file with a size of 0. Here is an analysis that I have done for my company (Alcatel-Lucent). The RETR command sent by the client to the server to get a file, triggers the following:
{ if ($2 && $4 != NULL) retrieve((char *) 0, $4); if ($4 != NULL) free($4);
if (cmd == 0) { fin = fopen (name, "r"), closefunc = fclose; st.st_size = 0; }
{ reply (550, "%s: not a plain file.", name); goto done; }
#define HAVE_MMAP 1
case TYPE_L: #ifdef HAVE_MMAP if (file_size > 0 && curpos >= 0 && buf != MAP_FAILED) { bp = buf; len = filesize; do { cnt = write (netfd, bp, len); len -= cnt; bp += cnt; if (cnt > 0) byte_count += cnt; } while (cnt > 0 && len > 0); transflag = 0; munmap (buf, (size_t) filesize); if (cnt < 0) goto data_err; reply (226, "Transfer complete with mmap (blksize = %u).", (u_int)blksize); return; } #endif
if (buf == NULL) { transflag = 0; perror_reply (451, "Local resource failure: malloc"); return; } while ((cnt = read (filefd, buf, (u_int) blksize)) > 0 && write (netfd, buf, cnt) == cnt) byte_count += cnt; transflag = 0; free (buf); if (cnt != 0) { if (cnt < 0) goto file_err; goto data_err; } reply (226, "Transfer complete."); return; So, I would propose the following patch:
retrieve (const char *cmd, const char *name) { FILE *fin, *dout; struct stat st; int (*closefunc) (FILE *); size_t buffer_size = 0; if (cmd == 0) { fin = fopen (name, "r"), closefunc = fclose; st.st_size = 0; buffer_size = 4096; } else { char line[BUFSIZ]; snprintf (line, sizeof line, cmd, name); name = line; fin = ftpd_popen (line, "r"), closefunc = ftpd_pclose; st.st_size = -1; buffer_size = BUFSIZ; } I tried it with HAVE_MMAP not defined in "config.h" and it works. Regards. Rachid Koucha. |
[Prev in Thread] | Current Thread | [Next in Thread] |