Bug 6545 - struct ucred ifdefined behind __USE_GNU
Summary: struct ucred ifdefined behind __USE_GNU
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-22 08:40 UTC by Luca Scamoni
Modified: 2014-07-03 11:30 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luca Scamoni 2008-05-22 08:40:10 UTC
sysdeps/unix/sysv/linux/bits/socket.h defines struct ucred behind #ifdef
__USE_GNU but ucred is not a GNU-specific extension.
This breaks compiling a number of sources if -D_GNU_SOURCE is not specified in
CFLAGS.
This modification has been introduced in revision 1.61 of MAIN trunk (tagged as
glibc-2_8-branch)
Comment 1 Ulrich Drepper 2008-05-22 14:16:57 UTC
This is a POSIX header and ucred is not in the POSIX namespace.  Fix you app to
pass the correct flags.
Comment 2 Howard Chu 2008-06-03 18:56:43 UTC
The ifdef is clearly wrong:

/* Socket level message types.  This must match the definitions in
   <linux/socket.h>.  */
enum
  {
    SCM_RIGHTS = 0x01           /* Transfer file descriptors.  */
#define SCM_RIGHTS SCM_RIGHTS
#ifdef __USE_BSD
    , SCM_CREDENTIALS = 0x02    /* Credentials passing.  */
# define SCM_CREDENTIALS SCM_CREDENTIALS
#endif
  };

#ifdef __USE_GNU
/* User visible structure for SCM_CREDENTIALS message */
struct ucred
{
  pid_t pid;                    /* PID of sending process.  */
  uid_t uid;                    /* UID of sending process.  */
  gid_t gid;                    /* GID of sending process.  */
};
#endif

The comment says the struct is used for the SCM_CREDENTIALS message. Therefore
it should at least be #ifdef __USE_BSD or #ifdef SCM_CREDENTIALS, not #ifdef
__USE_GNU.

Since the structure is also used by getsockopt(...SO_PEERCRED) it should probably be

#if defined(SO_PEERCRED) || defined(SCM_CREDENTIALS)

The comment should probably also be extended to indicate that it's also used for
the Linux-specific SO_PEERCRED sockopt.
Comment 3 Ulrich Drepper 2008-12-09 23:25:34 UTC
I've changed the header to make SCM_CREDENTIALS only available wen __USE_GNU is
defined.  BSD doesn't use this symbol/