Fix use of history without HistEvent, causing segfaults
authorSimon Schubert <corecode@dragonflybsd.org>
Sat, 14 Jan 2006 22:58:18 +0000 (22:58 +0000)
committerSimon Schubert <corecode@dragonflybsd.org>
Sat, 14 Jan 2006 22:58:18 +0000 (22:58 +0000)
Reported-by: esmith <esmith@postmark.net>
usr.sbin/cdcontrol/cdcontrol.c
usr.sbin/lpr/lpc/lpc.c
usr.sbin/pppctl/pppctl.c

index 010338a..953078f 100644 (file)
@@ -18,7 +18,7 @@
  *              Some code style reformatting.
  *
  * $FreeBSD: src/usr.sbin/cdcontrol/cdcontrol.c,v 1.24.2.11 2002/11/20 00:26:19 njl Exp $
- * $DragonFly: src/usr.sbin/cdcontrol/cdcontrol.c,v 1.9 2005/11/13 11:58:31 corecode Exp $
+ * $DragonFly: src/usr.sbin/cdcontrol/cdcontrol.c,v 1.10 2006/01/14 22:58:17 corecode Exp $
  */
 
 #include <sys/cdio.h>
@@ -1147,6 +1147,7 @@ input(int *cmd)
 #define MAXLINE 80
        static EditLine *el = NULL;
        static History *hist = NULL;
+       static HistEvent he;
        static char buf[MAXLINE];
        int num = 0;
        int len;
@@ -1158,7 +1159,7 @@ input(int *cmd)
                        if (!el) {
                                el = el_init("cdcontrol", stdin, stdout, stderr);
                                hist = history_init();
-                               history(hist, NULL, H_SETSIZE, 100);
+                               history(hist, &he, H_SETSIZE, 100);
                                el_set(el, EL_HIST, history, hist);
                                el_set(el, EL_EDITOR, "emacs");
                                el_set(el, EL_PROMPT, cdcontrol_prompt);
@@ -1174,7 +1175,7 @@ input(int *cmd)
                        len = (num > MAXLINE) ? MAXLINE : num;
                        memcpy(buf, bp, len);
                        buf[len] = 0;
-                       history(hist, NULL, H_ENTER, bp);
+                       history(hist, &he, H_ENTER, bp);
 #undef MAXLINE
 
                } else {
index 7521f8d..023786f 100644 (file)
@@ -34,7 +34,7 @@
  * @(#) Copyright (c) 1983, 1993 The Regents of the University of California.  All rights reserved.
  * @(#)lpc.c   8.3 (Berkeley) 4/28/95
  * $FreeBSD: src/usr.sbin/lpr/lpc/lpc.c,v 1.13.2.11 2002/07/26 03:12:07 gad Exp $
- * $DragonFly: src/usr.sbin/lpr/lpc/lpc.c,v 1.6 2005/11/13 11:58:31 corecode Exp $
+ * $DragonFly: src/usr.sbin/lpr/lpc/lpc.c,v 1.7 2006/01/14 22:58:18 corecode Exp $
  */
 
 #include <sys/param.h>
@@ -143,6 +143,7 @@ cmdscanner(void)
        struct cmd *c;
        static EditLine *el;
        static History *hist;
+       static HistEvent he;
        size_t len;
        int num;
        const char *bp;
@@ -156,7 +157,7 @@ cmdscanner(void)
                        if (!el) {
                                el = el_init("lpc", stdin, stdout, stderr);
                                hist = history_init();
-                               history(hist, NULL, H_SETSIZE, 100);
+                               history(hist, &he, H_SETSIZE, 100);
                                el_set(el, EL_HIST, history, hist);
                                el_set(el, EL_EDITOR, "emacs");
                                el_set(el, EL_PROMPT, lpc_prompt);
@@ -178,7 +179,7 @@ cmdscanner(void)
                        len = (num > MAX_CMDLINE -1) ? MAX_CMDLINE -1 : num;
                        memcpy(cmdline, bp, len);
                        cmdline[len] = 0; 
-                       history(hist, NULL, H_ENTER, bp);
+                       history(hist, &he, H_ENTER, bp);
 
                } else {
                        if (fgets(cmdline, MAX_CMDLINE, stdin) == 0)
index f464768..99bacd9 100644 (file)
@@ -24,7 +24,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.sbin/pppctl/pppctl.c,v 1.21.2.2 2001/11/23 13:18:39 brian Exp $
- * $DragonFly: src/usr.sbin/pppctl/pppctl.c,v 1.6 2005/11/24 23:42:54 swildner Exp $
+ * $DragonFly: src/usr.sbin/pppctl/pppctl.c,v 1.7 2006/01/14 22:58:18 corecode Exp $
  */
 
 #include <sys/param.h>
@@ -393,6 +393,7 @@ main(int argc, char **argv)
             if (len == 0) {
                 EditLine *edit;
                 History *hist;
+               HistEvent he;
                 const char *l, *env;
                 int size;
 
@@ -403,7 +404,7 @@ main(int argc, char **argv)
                       size = 20;
                 } else
                     size = 20;
-                history(hist, NULL, H_SETSIZE, size);
+                history(hist, &he, H_SETSIZE, size);
                 edit = el_init("pppctl", stdin, stdout, stderr);
                 el_source(edit, NULL);
                 el_set(edit, EL_PROMPT, GetPrompt);
@@ -417,7 +418,7 @@ main(int argc, char **argv)
                 el_set(edit, EL_HIST, history, (const char *)hist);
                 while ((l = smartgets(edit, &len, fd))) {
                     if (len > 1)
-                        history(hist, NULL, H_ENTER, l);
+                        history(hist, &he, H_ENTER, l);
                     write(fd, l, len);
                     if (Receive(fd, REC_SHOW) != 0)
                         break;