Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/ftp In ftpvis(), prevent incomplete escape sequences...



details:   https://anonhg.NetBSD.org/src/rev/b5a5f2f6a463
branches:  trunk
changeset: 755419:b5a5f2f6a463
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sat Jun 05 13:59:39 2010 +0000

description:
In ftpvis(), prevent incomplete escape sequences at end of dst,
and ensure NUL-termination of dst.  Also tweak for readibility.
Fix from Uwe Stuehler and Stefan Sperling, via Marc Balmer.

diffstat:

 usr.bin/ftp/util.c    |  21 +++++++++++++--------
 usr.bin/ftp/version.h |   4 ++--
 2 files changed, 15 insertions(+), 10 deletions(-)

diffs (68 lines):

diff -r 1f6c027510b7 -r b5a5f2f6a463 usr.bin/ftp/util.c
--- a/usr.bin/ftp/util.c        Sat Jun 05 07:59:13 2010 +0000
+++ b/usr.bin/ftp/util.c        Sat Jun 05 13:59:39 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.154 2010/03/05 07:41:10 lukem Exp $ */
+/*     $NetBSD: util.c,v 1.155 2010/06/05 13:59:39 lukem Exp $ */
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.154 2010/03/05 07:41:10 lukem Exp $");
+__RCSID("$NetBSD: util.c,v 1.155 2010/06/05 13:59:39 lukem Exp $");
 #endif /* not lint */
 
 /*
@@ -1098,9 +1098,8 @@
 {
        size_t  di, si;
 
-       for (di = si = 0;
-           src[si] != '\0' && di < dstlen && si < srclen;
-           di++, si++) {
+       di = si = 0;
+       while (src[si] != '\0' && di < dstlen && si < srclen) {
                switch (src[si]) {
                case '\\':
                case ' ':
@@ -1108,12 +1107,18 @@
                case '\r':
                case '\n':
                case '"':
+                       /*
+                        * Need room for two characters and NUL, avoiding
+                        * incomplete escape sequences at end of dst.
+                        */
+                       if (di >= dstlen - 3)
+                               break;
                        dst[di++] = '\\';
-                       if (di >= dstlen)
-                               break;
                        /* FALLTHROUGH */
                default:
-                       dst[di] = src[si];
+                       dst[di] = src[si++];
+                       if (di < dstlen)
+                               di++;
                }
        }
        dst[di] = '\0';
diff -r 1f6c027510b7 -r b5a5f2f6a463 usr.bin/ftp/version.h
--- a/usr.bin/ftp/version.h     Sat Jun 05 07:59:13 2010 +0000
+++ b/usr.bin/ftp/version.h     Sat Jun 05 13:59:39 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: version.h,v 1.81 2010/03/05 07:45:40 lukem Exp $       */
+/*     $NetBSD: version.h,v 1.82 2010/06/05 13:59:39 lukem Exp $       */
 
 /*-
  * Copyright (c) 1999-2009 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define        FTP_VERSION     "20100305"
+#define        FTP_VERSION     "20100605"
 #endif



Home | Main Index | Thread Index | Old Index