Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/ftp Prevent an overly-long input line causing a core...



details:   https://anonhg.NetBSD.org/src/rev/6cb005e5dab7
branches:  trunk
changeset: 580836:6cb005e5dab7
user:      lukem <lukem%NetBSD.org@localhost>
date:      Tue May 10 22:59:52 2005 +0000

description:
Prevent an overly-long input line causing a core dump when editing is enabled.
Issue noted by Ryoji Kanai in FreeBSD Problem Report # 77158.

diffstat:

 usr.bin/ftp/main.c    |  24 ++++++++++++++----------
 usr.bin/ftp/version.h |   4 ++--
 2 files changed, 16 insertions(+), 12 deletions(-)

diffs (75 lines):

diff -r e66f1182d274 -r 6cb005e5dab7 usr.bin/ftp/main.c
--- a/usr.bin/ftp/main.c        Tue May 10 21:58:03 2005 +0000
+++ b/usr.bin/ftp/main.c        Tue May 10 22:59:52 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.91 2005/04/11 01:49:31 lukem Exp $  */
+/*     $NetBSD: main.c,v 1.92 2005/05/10 22:59:52 lukem Exp $  */
 
 /*-
  * Copyright (c) 1996-2004 The NetBSD Foundation, Inc.
@@ -104,7 +104,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.91 2005/04/11 01:49:31 lukem Exp $");
+__RCSID("$NetBSD: main.c,v 1.92 2005/05/10 22:59:52 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -655,7 +655,8 @@
                                        break;
                                line[num] = '\0';
                        } else if (num == sizeof(line) - 2) {
-                               fputs("sorry, input line too long.\n", ttyout);
+                               fputs("Sorry, input line is too long.\n",
+                                   ttyout);
                                while ((num = getchar()) != '\n' && num != EOF)
                                        /* void */;
                                break;
@@ -666,20 +667,23 @@
                        HistEvent ev;
                        cursor_pos = NULL;
 
-                       if ((buf = el_gets(el, &num)) == NULL || num == 0) {
+                       buf = el_gets(el, &num);
+                       if (buf == NULL || num == 0) {
                                if (fromatty)
                                        putc('\n', ttyout);
                                quit(0, NULL);
                        }
-                       if (buf[--num] == '\n') {
-                               if (num == 0)
-                                       break;
-                       } else if (num >= sizeof(line)) {
-                               fputs("sorry, input line too long.\n", ttyout);
+                       if (num >= sizeof(line)) {
+                               fputs("Sorry, input line is too long.\n",
+                                   ttyout);
                                break;
                        }
                        memcpy(line, buf, num);
-                       line[num] = '\0';
+                       if (line[--num] == '\n') {
+                               line[num] = '\0';
+                               if (num == 0)
+                                       break;
+                       }
                        history(hist, &ev, H_ENTER, buf);
                }
 #endif /* !NO_EDITCOMPLETE */
diff -r e66f1182d274 -r 6cb005e5dab7 usr.bin/ftp/version.h
--- a/usr.bin/ftp/version.h     Tue May 10 21:58:03 2005 +0000
+++ b/usr.bin/ftp/version.h     Tue May 10 22:59:52 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: version.h,v 1.46 2005/04/11 01:43:31 lukem Exp $       */
+/*     $NetBSD: version.h,v 1.47 2005/05/10 22:59:52 lukem Exp $       */
 /*-
  * Copyright (c) 1999-2005 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -40,5 +40,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define        FTP_VERSION     "20050411"
+#define        FTP_VERSION     "20050510"
 #endif



Home | Main Index | Thread Index | Old Index