Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect CMSG functions on BSD #1210

Closed
asomers opened this issue Jan 14, 2019 · 0 comments
Closed

Incorrect CMSG functions on BSD #1210

asomers opened this issue Jan 14, 2019 · 0 comments
Labels
C-bug Category: bug

Comments

@asomers
Copy link
Contributor

asomers commented Jan 14, 2019

PR #1098 introduced Rust functions that duplicate the CMSG_FIRSTHDR, CMSG_NXTHDR, CMSG_DATA, CMSG_SPACE, and CMSG_LEN C macros. However, several of these are incorrect on BSD. It looks like the author wrote the Linux versions first, and then simply copied them into src/unix/bsd/mod.rs. For example, on both FreeBSD and OpenBSD CMSG_DATA is defined as

    pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut ::c_uchar {
        cmsg.offset(1) as *mut ::c_uchar
    }

even though the actual C macro is

#define CMSG_DATA(cmsg) \
        ((unsigned char *)(cmsg) + _ALIGN(sizeof(struct cmsghdr)))
@gnzlbg gnzlbg added the C-bug Category: bug label Jan 15, 2019
asomers added a commit to asomers/libc that referenced this issue Jan 15, 2019
PR rust-lang#1098 added the CMSG_DATA(3) family of functions into libc.  Because
they're defined as macros in C, they had to be rewritten as Rust
functions for libc.  Also, they can't be tested in CI for the same
reason.  But that PR erroneously used the same definitions in BSD as in
Linux.

This commit corrects the definitions for OSX, FreeBSD, DragonflyBSD,
OpenBSD, and NetBSD.  I renamed a few variables and collapsed a few
macros in order to combine the definitions where possible.

Fixes rust-lang#1210
asomers added a commit to asomers/libc that referenced this issue Jan 16, 2019
PR rust-lang#1098 added the CMSG_DATA(3) family of functions into libc.  Because
they're defined as macros in C, they had to be rewritten as Rust
functions for libc.  Also, they can't be tested in CI for the same
reason.  But that PR erroneously used the same definitions in BSD as in
Linux.

This commit corrects the definitions for OSX, FreeBSD, DragonflyBSD,
OpenBSD, and NetBSD.  I renamed a few variables and collapsed a few
macros in order to combine the definitions where possible.

Fixes rust-lang#1210
bors added a commit that referenced this issue Jan 17, 2019
Fix CMSG_DATA(3) and friends on BSD

PR #1098 added the CMSG_DATA(3) family of functions into libc.  Because
they're defined as macros in C, they had to be rewritten as Rust
functions for libc.  Also, they can't be tested in CI for the same
reason.  But that PR erroneously used the same definitions in BSD as in
Linux.

This commit corrects the definitions for OSX, FreeBSD, DragonflyBSD,
OpenBSD, and NetBSD.  I renamed a few variables and collapsed a few
macros in order to combine the definitions where possible.

Fixes #1210
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants