commit-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1-103-g2aea8


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1-103-g2aea8c1
Date: Wed, 30 May 2012 21:11:25 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Inetutils ".

The branch, master has been updated
       via  2aea8c1ea8e0ce1f4dc173ab84dd34bd7e9782eb (commit)
       via  b0a461970ae42ede3460ac3dd58f73e0fd8329b4 (commit)
      from  0a66bdd5a5318bd9a2a6861e423040ed99cb069e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=2aea8c1ea8e0ce1f4dc173ab84dd34bd7e9782eb


commit 2aea8c1ea8e0ce1f4dc173ab84dd34bd7e9782eb
Author: Mats Erik Andersson <address@hidden>
Date:   Wed May 30 12:36:56 2012 +0200

    Incomplete variadic printing.
    
    Missing va_start() and va_end() cause crashes.

diff --git a/ChangeLog b/ChangeLog
index d7360ff..faabde2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+ 2012-05-30  Mats Erik Andersson  <address@hidden>
+
+       Incomplete coding of variadic printing.  Each such command
+       consumes the pointer, leaving it in an undefined state.
+       Some 64-bit systems are sensitive to these mistakes.
+
+       * ftpd/ftpd.c (reply, lreply): Missing va_end(). Give each
+       vprintf() and vsyslog() a separate pair va_start()/va_end().
+       * src/rcp.c (run_err): Likewise for vfprintf().
+       * src/rshd.c (rshd_error): Missing va_end().
+
 2012-05-30  Mats Erik Andersson  <address@hidden>
 
        ftpd: Allow 64-bit offsets and file sizes.  Restrict
diff --git a/ftpd/ftpd.c b/ftpd/ftpd.c
index ba5560e..b33c246 100644
--- a/ftpd/ftpd.c
+++ b/ftpd/ftpd.c
@@ -1568,12 +1568,15 @@ reply (int n, const char *fmt, ...)
   va_start (ap, fmt);
   printf ("%d ", n);
   vprintf (fmt, ap);
+  va_end (ap);
   printf ("\r\n");
   fflush (stdout);
   if (debug)
     {
       syslog (LOG_DEBUG, "<--- %d ", n);
+      va_start (ap, fmt);
       vsyslog (LOG_DEBUG, fmt, ap);
+      va_end (ap);
     }
 }
 
@@ -1584,12 +1587,15 @@ lreply (int n, const char *fmt, ...)
   va_start (ap, fmt);
   printf ("%d- ", n);
   vprintf (fmt, ap);
+  va_end (ap);
   printf ("\r\n");
   fflush (stdout);
   if (debug)
     {
       syslog (LOG_DEBUG, "<--- %d- ", n);
+      va_start (ap, fmt);
       vsyslog (LOG_DEBUG, fmt, ap);
+      va_end (ap);
     }
 }
 
diff --git a/src/rcp.c b/src/rcp.c
index cd0c25b..3907c53 100644
--- a/src/rcp.c
+++ b/src/rcp.c
@@ -1111,17 +1111,18 @@ run_err (const char *fmt, ...)
   fprintf (fp, "%c", 0x01);
   fprintf (fp, "rcp: ");
   vfprintf (fp, fmt, ap);
+  va_end (ap);
   fprintf (fp, "\n");
   fflush (fp);
 
   if (!iamremote)
     {
       fprintf (stderr, "%s: ", program_invocation_name);
+      va_start (ap, fmt);
       vfprintf (stderr, fmt, ap);
+      va_end (ap);
       fprintf (stderr, "\n");
     }
-
-  va_end (ap);
 }
 
 char *
diff --git a/src/rshd.c b/src/rshd.c
index e5df05f..c0cd7db 100644
--- a/src/rshd.c
+++ b/src/rshd.c
@@ -1212,6 +1212,7 @@ rshd_error (const char *fmt, ...)
   else
     len = 0;
   vsnprintf (bp, sizeof (buf) - 1, fmt, ap);
+  va_end (ap);
   write (STDERR_FILENO, buf, len + strlen (bp));
 }
 

http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=b0a461970ae42ede3460ac3dd58f73e0fd8329b4


commit b0a461970ae42ede3460ac3dd58f73e0fd8329b4
Author: Mats Erik Andersson <address@hidden>
Date:   Wed May 30 12:30:55 2012 +0200

    ftpd: Grave binary mode issues.
    
    Empty buffer allocation and 64-bit artifacts.

diff --git a/ChangeLog b/ChangeLog
index 528339e..d7360ff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2012-05-30  Mats Erik Andersson  <address@hidden>
+
+       ftpd: Allow 64-bit offsets and file sizes.  Restrict
+       file size for use of mmap() and only null offset, since
+       Solaris and Linux demand page size alignment.  Assign
+       a positive malloc size for use in data transmission.
+
+       * ftpd/ftpcmd.y: Include <inttypes.h> or <stdint.h>.
+       (token union): Use `intmax_t i' instead of `int i' in order
+       to handle 64-bit offsets and sizes.
+       (cmd, rcmd, host_port, sizecmd): Use format strings `%jd'
+       and `%ju'.  Append `LL' to numerical constants.
+       (yylex) <ARGS>: Convert numeric strings using strtoimax().
+       * ftpd/ftpd.c (retrieve): Initialise BUFFER_SIZE to `BUFSIZ'
+       in all cases.  Essential correction, since malloc() would
+       otherwise allocate 0 bytes in binary mode.
+       (IU_MMAP_SIZE): New macro.
+       (send_data): Initialise BUF to `MAP_FAILED'.  Change LEN
+       and FILESIZE to be `off_t'.  Add debug logging about offsets
+       and transmission modes `ascii/image/mmap'.
+       [HAVE_MMAP]: Attempt mapping only if file size is less than
+       IU_MMAP_SIZE and only when `restart_point == 0'.
+
 2012-05-26  Mats Erik Andersson  <address@hidden>
 
        * tests/ftp-localhost.sh (do_transfer, GETME, PUTME):
diff --git a/ftpd/ftpcmd.y b/ftpd/ftpcmd.y
index dc88350..533a827 100644
--- a/ftpd/ftpcmd.y
+++ b/ftpd/ftpcmd.y
@@ -78,6 +78,11 @@
 #include <pwd.h>
 #include <setjmp.h>
 #include <signal.h>
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h> /* strtoimax */
+#elif defined HAVE_STDINT_H
+# include <stdint.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -126,7 +131,7 @@ static void yyerror       (const char *s);
 %}
 
 %union {
-       int     i;
+       intmax_t i;
        char   *s;
 }
 
@@ -607,7 +612,7 @@ cmd
                                        struct addrinfo hints, *res;
 
                                        memset (&hints, 0, sizeof (hints));
-                                       snprintf (p, sizeof (p), "%u", $9 & 
0xffff);
+                                       snprintf (p, sizeof (p), "%jd", $9 & 
0xffffLL);
                                        hints.ai_family = $5;
                                        hints.ai_socktype = SOCK_STREAM;
                                        hints.ai_flags = AI_NUMERICHOST | 
AI_NUMERICSERV;
@@ -733,11 +738,9 @@ rcmd
                {
                        free (fromname);
                        fromname = (char *) 0;
-                       restart_point = $3;     /* XXX $3 is only "int" */
-                       reply(350,
-                             (sizeof(restart_point) > sizeof(long)
-                              ? "Restarting at %lld. %s"
-                              : "Restarting at %ld. %s"), restart_point,
+                       restart_point = $3;
+                       reply(350, "Restarting at %jd. %s",
+                           (intmax_t) restart_point,
                            "Send STORE or RETRIEVE to initiate transfer.");
                }
        ;
@@ -787,10 +790,10 @@ host_port
                        char a[INET6_ADDRSTRLEN], p[8];
                        struct addrinfo hints, *res;
 
-                       snprintf (a, sizeof (a), "%u.%u.%u.%u",
-                               $1 & 0xff, $3 & 0xff, $5 & 0xff, $7 & 0xff);
-                       snprintf (p, sizeof (p), "%u",
-                               (($9 & 0xff) << 8) + ($11 & 0xff));
+                       snprintf (a, sizeof (a), "%jd.%jd.%jd.%jd",
+                                 $1 & 0xffLL, $3 & 0xffLL, $5 & 0xffLL, $7 & 
0xffLL);
+                       snprintf (p, sizeof (p), "%jd",
+                                 (($9 & 0xffLL) << 8) + ($11 & 0xffLL));
                        memset (&hints, 0, sizeof (hints));
                        hints.ai_family = his_addr.ss_family;
                        hints.ai_socktype = SOCK_STREAM;
@@ -802,8 +805,8 @@ host_port
 #ifdef AI_V4MAPPED
                            hints.ai_flags |= AI_V4MAPPED;
 #endif
-                           snprintf (a, sizeof (a), "::ffff:%u.%u.%u.%u",
-                                     $1 & 0xff, $3 & 0xff, $5 & 0xff, $7 & 
0xff);
+                           snprintf (a, sizeof (a), "::ffff:%jd.%jd.%jd.%jd",
+                                     $1 & 0xffLL, $3 & 0xffLL, $5 & 0xffLL, $7 
& 0xffLL);
                        }
 
                        err = getaddrinfo (a, p, &hints, &res);
@@ -1352,7 +1355,7 @@ yylex(void)
                                        ;
                                c = cbuf[cpos];
                                cbuf[cpos] = '\0';
-                               yylval.i = atoi(cp);
+                               yylval.i = strtoimax (cp, NULL, 10);    /* 
off_t */
                                cbuf[cpos] = c;
                                return (NUMBER);
                        }
@@ -1523,9 +1526,7 @@ sizecmd(char *filename)
                if (stat(filename, &stbuf) < 0 || !S_ISREG(stbuf.st_mode))
                        reply(550, "%s: not a plain file.", filename);
                else
-                       reply(213,
-                             (sizeof (stbuf.st_size) > sizeof(long)
-                              ? "%llu" : "%lu"), stbuf.st_size);
+                       reply(213, "%ju", (uintmax_t) stbuf.st_size);
                break; }
        case TYPE_A: {
                FILE *fin;
@@ -1551,8 +1552,7 @@ sizecmd(char *filename)
                }
                 fclose(fin);
 
-               reply(213, sizeof(count) > sizeof(long) ? "%lld" : "%ld",
-                     count);
+               reply(213, "%jd", (intmax_t) count);
                break; }
        default:
                reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
diff --git a/ftpd/ftpd.c b/ftpd/ftpd.c
index 3693a21..ba5560e 100644
--- a/ftpd/ftpd.c
+++ b/ftpd/ftpd.c
@@ -876,7 +876,7 @@ retrieve (const char *cmd, const char *name)
   FILE *fin, *dout;
   struct stat st;
   int (*closefunc) (FILE *);
-  size_t buffer_size = 0;
+  const size_t buffer_size = BUFSIZ;   /* Dynamic buffer.  */
 
   if (cmd == 0)
     {
@@ -891,7 +891,6 @@ retrieve (const char *cmd, const char *name)
       name = line;
       fin = ftpd_popen (line, "r"), closefunc = ftpd_pclose;
       st.st_size = -1;
-      buffer_size = BUFSIZ;
     }
 
   if (fin == NULL)
@@ -1198,6 +1197,8 @@ dataconn (const char *name, off_t size, const char *mode)
   return file;
 }
 
+#define IU_MMAP_SIZE 0x800000  /* 8 MByte */
+
 /* Tranfer the contents of "instr" to "outstr" peer using the appropriate
    encapsulation of the data subject * to Mode, Structure, and Type.
 
@@ -1206,9 +1207,9 @@ static void
 send_data (FILE * instr, FILE * outstr, off_t blksize)
 {
   int c, cnt, filefd, netfd;
-  char *buf, *bp;
+  char *buf = MAP_FAILED, *bp;
   off_t curpos;
-  size_t len, filesize;
+  off_t len, filesize;
 
   transflag++;
   if (setjmp (urgcatch))
@@ -1220,9 +1221,16 @@ send_data (FILE * instr, FILE * outstr, off_t blksize)
   netfd = fileno (outstr);
   filefd = fileno (instr);
 #ifdef HAVE_MMAP
-  if (file_size > 0)
+  /* Last argument in mmap() must be page aligned,
+   * at least for Solaris and Linux, so use mmap()
+   * only with null offset retrievals.
+   */
+  if (file_size > 0 && file_size < IU_MMAP_SIZE && restart_point == 0)
     {
       curpos = lseek (filefd, 0, SEEK_CUR);
+      if (debug)
+       syslog (LOG_DEBUG, "Position is %jd. Attempting mmap call.",
+               curpos);
       if (curpos >= 0)
        {
          filesize = file_size - curpos;
@@ -1238,6 +1246,8 @@ send_data (FILE * instr, FILE * outstr, off_t blksize)
 #ifdef HAVE_MMAP
       if (file_size > 0 && curpos >= 0 && buf != MAP_FAILED)
        {
+         if (debug)
+           syslog (LOG_DEBUG, "Reading file as ascii in mmap mode.");
          len = 0;
          while (len < filesize)
            {
@@ -1260,6 +1270,8 @@ send_data (FILE * instr, FILE * outstr, off_t blksize)
          return;
        }
 #endif
+      if (debug)
+       syslog (LOG_DEBUG, "Reading file as ascii in byte mode.");
       while ((c = getc (instr)) != EOF)
        {
          byte_count++;
@@ -1285,6 +1297,8 @@ send_data (FILE * instr, FILE * outstr, off_t blksize)
 #ifdef HAVE_MMAP
       if (file_size > 0 && curpos >= 0 && buf != MAP_FAILED)
        {
+         if (debug)
+           syslog (LOG_DEBUG, "Reading file as image in mmap mode.");
          bp = buf;
          len = filesize;
          do
@@ -1304,6 +1318,16 @@ send_data (FILE * instr, FILE * outstr, off_t blksize)
          return;
        }
 #endif
+      if (debug)
+       {
+         syslog (LOG_DEBUG, "Reading file as image in block mode.");
+         curpos = lseek (filefd, 0, SEEK_CUR);
+         if (curpos < 0)
+           syslog (LOG_DEBUG, "Input file: %m");
+         else
+           syslog (LOG_DEBUG, "Starting at position %jd.", curpos);
+       }
+
       buf = malloc ((u_int) blksize);
       if (buf == NULL)
        {
@@ -1314,6 +1338,7 @@ send_data (FILE * instr, FILE * outstr, off_t blksize)
       while ((cnt = read (filefd, buf, (u_int) blksize)) > 0 &&
             write (netfd, buf, cnt) == cnt)
        byte_count += cnt;
+
       transflag = 0;
       free (buf);
       if (cnt != 0)

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog     |   34 ++++++++++++++++++++++++++++++++++
 ftpd/ftpcmd.y |   38 +++++++++++++++++++-------------------
 ftpd/ftpd.c   |   41 ++++++++++++++++++++++++++++++++++++-----
 src/rcp.c     |    5 +++--
 src/rshd.c    |    1 +
 5 files changed, 93 insertions(+), 26 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]