From peff@peff.net  Tue Dec 16 13:02:58 2003
Return-Path: <peff@peff.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id BC13316A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 16 Dec 2003 13:02:58 -0800 (PST)
Received: from peff.net (adsl-068-209-112-235.sip.asm.bellsouth.net [68.209.112.235])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 59D6343D45
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 16 Dec 2003 13:02:57 -0800 (PST)
	(envelope-from peff@peff.net)
Received: (qmail 23817 invoked by uid 1001); 16 Dec 2003 21:03:19 -0000
Message-Id: <20031216210319.23816.qmail@peff.net>
Date: 16 Dec 2003 21:03:19 -0000
From: Jeff King <peff-freebsd@peff.net>
Reply-To: Jeff King <peff-freebsd@peff.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: sys/socket.h: CMSG_NXTHDR requires definition of NULL
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         60309
>Category:       kern
>Synopsis:       sys/socket.h: CMSG_NXTHDR requires definition of NULL
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 16 13:10:17 PST 2003
>Closed-Date:    Fri Jul 16 17:45:16 GMT 2004
>Last-Modified:  Fri Jul 16 17:45:16 GMT 2004
>Originator:     Jeff King
>Release:        FreeBSD 5.1-RELEASE-p10 i386
>Organization:
>Environment:
System: FreeBSD segfault.peff.net 5.1-RELEASE-p10 FreeBSD 5.1-RELEASE-p10 #2: Fri Oct 10 04:15:30 EDT 2003 root@segfault.peff.net:/usr/obj/usr/src/sys/SEGFAULT i386
>Description:
The definition of CMSG_NXTHDR in /usr/include/sys/socket.h references 'NULL'
but does not take any steps to define it. This causes broken compilation for
programs (that used to work). I'm not sure when the breakage occurred...it
happens on my 5.1-RELEASE-p10, but also on 4.9. It was not a problem for me
about six months ago, on I think 4.7. Unfortunately, I'm having a hard time
tracking down the exact change, since it may well be from a recursive include.

>How-To-Repeat:
  Compiling the following C file triggers the problem:
#include <sys/types.h>
#include <sys/socket.h>

void foo(struct msghdr *msg) {
  struct cmsghdr* cmsg;
  for(cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) ;
}

>Fix:
The possibilities are thus:
 - one line patch to change NULL to 0 in sys/socket.h
 - define NULL either manually (wrapped in indef NULL) or by
   including unistd/stdlib (and getting a bunch of other cruft).
 - accepting that users must include unistd.h or similar before using the
   macro. In this case, I think that the relevant man page (recv(2)?) should
   mention this. However, I prefer not introducing this dependency.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: harti 
State-Changed-When: Fri Jul 16 17:43:26 GMT 2004 
State-Changed-Why:  
Replace the NULL with a 0. We cannot define NULL here, because 
socket.h isn't allowed to define NULL. We can also not require 
the user to include another file, because POSIX requires that 
CMSG_NXTHDR is useable with socket.h alone. 

Committed. Thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=60309 
>Unformatted:
