Skip site navigation (1)Skip section navigation (2)
Date:      16 Dec 2003 21:03:19 -0000
From:      Jeff King <peff-freebsd@peff.net>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   misc/60309: sys/socket.h: CMSG_NXTHDR requires definition of NULL
Message-ID:  <20031216210319.23816.qmail@peff.net>
Resent-Message-ID: <200312162110.hBGLAHuV073172@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         60309
>Category:       misc
>Synopsis:       sys/socket.h: CMSG_NXTHDR requires definition of NULL
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 16 13:10:17 PST 2003
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031216210319.23816.qmail>