misc/60309: sys/socket.h: CMSG_NXTHDR requires definition of NULL

Jeff King peff-freebsd at peff.net
Tue Dec 16 13:10:22 PST 2003


>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 at 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:


More information about the freebsd-bugs mailing list