From nobody@FreeBSD.org  Tue Aug 27 16:50:39 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id 83DD3C5A
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 27 Aug 2013 16:50:39 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 729B62465
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 27 Aug 2013 16:50:39 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r7RGoce7019013
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 27 Aug 2013 16:50:38 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r7RGocIu019008;
	Tue, 27 Aug 2013 16:50:38 GMT
	(envelope-from nobody)
Message-Id: <201308271650.r7RGocIu019008@oldred.freebsd.org>
Date: Tue, 27 Aug 2013 16:50:38 GMT
From: "Oleg A. Mamontov" <oleg@mamontov.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: nscd negative responses
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         181586
>Category:       bin
>Synopsis:       [patch] nscd(8): nscd negative responses
>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 Aug 27 17:00:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Tue Aug 27 23:55:30 UTC 2013
>Originator:     Oleg A. Mamontov
>Release:        9.1-RELEASE-p4
>Organization:
>Environment:
FreeBSD lonerr.jail.local 9.1-RELEASE-p4 FreeBSD 9.1-RELEASE-p4 #0: Mon Jun 17 11:42:37 UTC 2013     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
nscd (8) daemon caches negative responses for infinite time.
Parameter 'negative-time-to-live' in /etc/nscd.conf doesn't correct this behavior.
>How-To-Repeat:
Try set 'negative-time-to-live hosts 1' in /etc/nscd.conf and 'hosts: files cache dns' in /etc/nsswitch.conf.
Restart nscd: '/etc/rc.d/nscd onerestart'.
Now we can see output of 'tcpdump udp and port 53' and repeat many times: 'ping -c1 some.nonexistent'.
Only first time there will be actual dns search (with expected negative response).


>Fix:
Supplied below corrects nscd behaviour on 9.1-RELEASE-p4 and HEAD:

--- usr.sbin/nscd/query.c.orig  2013-08-22 11:59:03.921956888 +0400
+++ usr.sbin/nscd/query.c   2013-08-22 12:00:01.515957178 +0400
@@ -743,9 +743,14 @@
                &read_response->data_size);

            if (read_response->error_code == -2) {
-               read_response->error_code = 0;
-               read_response->data = NULL;
-               read_response->data_size = 0;
+               read_response->data = malloc(
+                   read_response->data_size);
+               assert(read_response != NULL);
+               read_response->error_code = cache_read(neg_c_entry,
+                   read_request->cache_key,
+                   read_request->cache_key_size,
+                   read_response->data,
+                   &read_response->data_size);
            }
        }
        configuration_unlock_entry(qstate->config_entry, CELT_NEGATIVE);

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