bin/181783: [PATCH] nslookup segfaults after reading "^D"

Fabian Keil fk at fabiankeil.de
Tue Sep 3 17:30:01 UTC 2013


>Number:         181783
>Category:       bin
>Synopsis:       [PATCH] nslookup segfaults after reading "^D"
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 03 17:30:00 UTC 2013
>Closed-Date:
>Last-Modified:
>Originator:     Fabian Keil
>Release:        HEAD
>Organization:
>Environment:
FreeBSD r500.local 10.0-CURRENT FreeBSD 10.0-CURRENT #596 r255153+2bda83d: Mon Sep  2 22:07:13 CEST 2013     fk at r500.local:/usr/obj/usr/src/sys/ZOEY  amd64

>Description:
The attached patch prevents nslookup from segfaulting after reading a single "^D" when running in interactive mode and built with readline support.
>How-To-Repeat:
fk at r500 ~ $gdb76 --args nslookup
GNU gdb (GDB) 7.6 [GDB v7.6 for FreeBSD]
[...]
Reading symbols from /usr/bin/nslookup...done.
(gdb) r
Starting program: /usr/bin/nslookup 
[New LWP 101002]
> ^D[New Thread 802006800 (LWP 101058)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 802006800 (LWP 101058)]
strlen (str=0x0) at /usr/src/lib/libc/string/strlen.c:100
100		va = (*lp - mask01);
(gdb) where
#0  strlen (str=0x0) at /usr/src/lib/libc/string/strlen.c:100
#1  0x000000080149ef82 in strdup (str=0x0) at /usr/src/lib/libc/string/strdup.c:46
#2  0x00000008009eb529 in history_def_insert (ev=<optimized out>, str=0x0, h=<optimized out>) at /usr/src/lib/libedit/history.c:465
#3  history_def_enter (p=0x8024e7040, ev=0x7fffffbfdee0, str=0x0) at /usr/src/lib/libedit/history.c:497
#4  0x00000008009ebd71 in history (h=0x8024e5080, ev=0x7fffffbfdee0, fun=<optimized out>) at /usr/src/lib/libedit/history.c:953
#5  0x00000008009d7b18 in add_history (line=<optimized out>, line=<optimized out>) at /usr/src/lib/libedit/readline.c:1371
#6  0x000000000040efb5 in get_next_command () at /usr/src/usr.bin/nslookup/../../contrib/bind9/bin/dig/nslookup.c:770
#7  getinput (task=<optimized out>, event=<optimized out>) at /usr/src/usr.bin/nslookup/../../contrib/bind9/bin/dig/nslookup.c:869
#8  0x000000000054acaf in dispatch (manager=<optimized out>) at /usr/src/lib/bind/isc/../../../contrib/bind9/lib/isc/task.c:1116
#9  run (uap=0x802033000) at /usr/src/lib/bind/isc/../../../contrib/bind9/lib/isc/task.c:1286
#10 0x0000000800fee534 in thread_start (curthread=0x802006800) at /usr/src/lib/libthr/thread/thr_create.c:284
#11 0x0000000000000000 in ?? ()
>Fix:


Patch attached with submission follows:

>From 9f966878a610092dafade8950a32f789ca361f7f Mon Sep 17 00:00:00 2001
From: Fabian Keil <fk at fabiankeil.de>
Date: Tue, 3 Sep 2013 10:55:07 +0200
Subject: [PATCH] Prevent nslookup from segfaulting upon receiving ^D

---
 contrib/bind9/bin/dig/nslookup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/bind9/bin/dig/nslookup.c b/contrib/bind9/bin/dig/nslookup.c
index 3f5b82f..49aabed 100644
--- a/contrib/bind9/bin/dig/nslookup.c
+++ b/contrib/bind9/bin/dig/nslookup.c
@@ -767,7 +767,8 @@ get_next_command(void) {
 	if (interactive) {
 #ifdef HAVE_READLINE
 		ptr = readline("> ");
-		add_history(ptr);
+		if (ptr != NULL)
+			add_history(ptr);
 #else
 		fputs("> ", stderr);
 		fflush(stderr);
-- 
1.8.2.2



>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list