From 2d5a5da6a2757683e394685fe48e543b7e880172 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Thu, 12 Aug 1999 22:11:54 +0000 Subject: [PATCH] (send_data): avoid calling mmap with `len == 0'. Some mmap:s rather dislike that (Solaris) and some munmap get grumpy later. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@6804 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/ftp/ftpd/ftpd.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/appl/ftp/ftpd/ftpd.c b/appl/ftp/ftpd/ftpd.c index ee5863487..4941c5799 100644 --- a/appl/ftp/ftpd/ftpd.c +++ b/appl/ftp/ftpd/ftpd.c @@ -1292,22 +1292,30 @@ send_data(FILE *instr, FILE *outstr) char *chunk; int in = fileno(instr); if(fstat(in, &st) == 0 && S_ISREG(st.st_mode)) { - chunk = mmap(0, st.st_size, PROT_READ, MAP_SHARED, in, 0); - if((void *)chunk != (void *)MAP_FAILED) { - cnt = st.st_size - restart_point; - sec_write(fileno(outstr), - chunk + restart_point, - cnt); - munmap(chunk, st.st_size); - sec_fflush(outstr); - byte_count = cnt; + /* + * mmap zero bytes has potential of loosing, don't do it. + */ + if (st.st_size > 0) { + chunk = mmap(0, st.st_size, PROT_READ, + MAP_SHARED, in, 0); + if((void *)chunk != (void *)MAP_FAILED) { + cnt = st.st_size - restart_point; + sec_write(fileno(outstr), + chunk + restart_point, + cnt); + if (munmap(chunk, st.st_size) < 0) + warn ("munmap"); + sec_fflush(outstr); + byte_count = cnt; + transflag = 0; + } + } else { transflag = 0; } - } } #endif - if(transflag){ + if(transflag) { struct stat st; netfd = fileno(outstr); @@ -1495,7 +1503,7 @@ statcmd(void) struct sockaddr_in *sin; u_char *a, *p; - lreply(211, "%s FTP server status:", hostname, version); + lreply(211, "%s FTP server (%s) status:", hostname, version); printf(" %s\r\n", version); printf(" Connected to %s", remotehost); if (!isdigit(remotehost[0]))