Commit Graph

2598 Commits

Author SHA1 Message Date
Alan Somers
098aba2c4a Fix SockaddrLike::from_raw with unaligned inputs
The major users of this function are functions like gethostname, which
will always properly align their buffers.  But out-of-crate consumers
could manually construct an unaligned buffer.  Handle that correctly.

Enable Clippy's cast_ptr_alignment lint.  It's disabled by default as it
reports many false positives, but it would've caught this problem.

Reported-by:	Miri
Fixes:		1769
2022-07-23 14:46:42 -06:00
bors[bot]
b1e1a604a7
Merge #1764
1764: Fix description of fchownat r=asomers a=valdaarhun

Based on the man page for `fchownat` and `lchown`, I have got the impression that with `FchownatFlags::NoFollowSymlink`, fchownat and lchown are identical. I couldn't find any documentation on `lchmod`.

Co-authored-by: valdaarhun <icegambit91@gmail.com>
2022-07-15 19:36:06 +00:00
valdaarhun
885b9430ae Fix description of fchownat 2022-07-16 00:18:34 +05:30
bors[bot]
b44daa1362
Merge #1741
1741: SigSet: A new unsafe helper method to create a SigSet from a sigset_t r=rtzoeller a=germag

Currently,  the only way to create a `SigSet` from a `sigset_t` object
is by using pointer casts, like:

```
unsafe {
    let sigset = *(&sigset as *const libc::sigset_t as *const SigSet)
};
```

This is un-ergonomic for library creators with interfaces to C.
So, let's add a new unsafe method that creates a `SigSet` from a 
`libc::sigset_t` object.

We can't implement `From` since converting from `libc::sigset_t` to
`SigSet` is unsafe, because objects of type `libc::sigset_t` must be
initialized by calling either `sigemptyset(3)` or `sigfillset(3)`
before being used. In other case, the results are undefined.
We can't implement `TryFrom` either, because there is no way to check
if an object of type `libc::sigset_t` is initialized.

Signed-off-by: German Maglione <gmaglione@redhat.com>

Co-authored-by: German Maglione <gmaglione@redhat.com>
2022-07-15 02:53:44 +00:00
bors[bot]
2556b78f34
Merge #1763
1763: Fix a buffer overflow in sys::socket::recvfrom r=posborne a=asomers

IPv4 and stream sockets are unaffected, but for datagram sockets of
other address types libc::recvfrom might overwrite part of the stack.

Fixes #1762

Co-authored-by: Alan Somers <asomers@gmail.com>
2022-07-14 19:25:51 +00:00
Alan Somers
e0e768e7b9 Fix a buffer overflow in sys::socket::recvfrom
IPv4 and stream sockets are unaffected, but for datagram sockets of
other address types libc::recvfrom might overwrite part of the stack.

Fixes #1762
2022-07-14 11:37:56 -06:00
bors[bot]
e5f354cf58
Merge #1758
1758: Add chflags r=rtzoeller a=asomers



Co-authored-by: musikid <musikid@outlook.com>
2022-07-14 04:15:39 +00:00
musikid
137a9abb66 Add chflags 2022-07-13 21:27:36 -06:00
bors[bot]
fb65331a55
Merge #1761
1761: Add non-standard Linux `SysconfVar` variants r=asomers a=stevenengler

Closes #1240.

You can find these options near the end of https://man7.org/linux/man-pages/man3/sysconf.3.html.

I can see that the libc crate defines these for Linux and Android, but I'm not sure if they're defined for any others as well.

Co-authored-by: Steven Engler <opara@cs.georgetown.edu>
2022-07-13 21:01:47 +00:00
Steven Engler
b7a2de0539 Added non-standard Linux SysconfVar variants 2022-07-13 16:43:45 -04:00
German Maglione
b207aaee4c SigSet: Add the repr(transparent) attribute
This commit adds the `repr(transparent)` attribute to the `SigSet`
struct, to make sure that its representation is exactly like the
`sigset_t` struct from C, in all cases.

Signed-off-by: German Maglione <gmaglione@redhat.com>
2022-07-12 17:25:51 +02:00
German Maglione
3d44d276e7 SigSet: A new unsafe helper method to create a SigSet from a sigset_t
Currently,  the only way to create a `SigSet` from a `sigset_t` object
is by using pointer casts, like:

```
unsafe {
    let sigset = *(&sigset as *const libc::sigset_t as *const SigSet)
};
```

This is un-ergonomic for library creators with interfaces to C.
So, let's add a new unsafe method that creates a `SigSet` from a
`libc::sigset_t` object.

We can't implement `From` since converting from `libc::sigset_t` to
`SigSet` is unsafe, because objects of type `libc::sigset_t` must be
initialized by calling either `sigemptyset(3)` or `sigfillset(3)`
before being used. In other case, the results are undefined.
We can't implement `TryFrom` either, because there is no way to check
if an object of type `libc::sigset_t` is initialized.

Signed-off-by: German Maglione <gmaglione@redhat.com>
2022-07-12 17:25:51 +02:00
bors[bot]
5f859d10df
Merge #1759 #1760
1759: More docs for dir and mqueue r=rtzoeller a=asomers

Add doc comments for the `dir` and `mqueue` modules.  Also, delete dead code in `mqueue`

1760: Add const constructors for TimeSpec and TimeVal r=rtzoeller a=asomers

These are basically the same as From<libc::timespec> and
From<libc::timeval>, but they're const and require less typing.

Co-authored-by: Alan Somers <asomers@gmail.com>
2022-07-11 02:34:44 +00:00
bors[bot]
b1b43725df
Merge #1757
1757: Clippy cleanup in the tests. r=rtzoeller a=asomers

* Remove a redundant closure.

Co-authored-by: Alan Somers <asomers@gmail.com>
2022-07-11 02:19:59 +00:00
Alan Somers
b3e4d59bd7 Add const constructors for TimeSpec and TimeVal
These are basically the same as From<libc::timespec> and
From<libc::timeval>, but they're const and require less typing.
2022-07-10 18:43:00 -06:00
bors[bot]
d09c2972b7
Merge #1752
1752: Add missing DontRoute SockOpt r=asomers a=leoleoasd

I'm not sure, but according to [unix standard](https://pubs.opengroup.org/onlinepubs/7908799/xns/setsockopt.html), SO_DONTROUTE should appear in all unix systems.
Does this need a test?

Co-authored-by: Leo Lu <luyuxuanleo@gmail.com>
2022-07-10 22:52:28 +00:00
Leo Lu
790960cbb2
Added CHANGELOG 2022-07-11 06:45:35 +08:00
Leo Lu
ba376e8577
Add DontRoute SockOpt 2022-07-11 06:45:34 +08:00
Alan Somers
349f3acf42 More docs for the dir module 2022-07-10 10:28:38 -06:00
Alan Somers
d988c65d86 More docs for mqueue.
Also, delete some dead code.  It's always been dead.
2022-07-10 10:20:48 -06:00
bors[bot]
c8ffe26955
Merge #1745
1745: Change gethostname to use a buffer of MaybeUninit values r=asomers a=nathaniel-daniel

Changing `gethostname` to accept a buffer of `MaybeUninit` bytes allows the user to avoid needlessly initializing a buffer. This is a breaking API change.

Co-authored-by: Nathaniel Daniel <nathaniel.daniel12@gmail.com>
2022-07-10 16:00:11 +00:00
Alan Somers
dc1a34b864 Clippy cleanup in the tests.
* Remove a redundant closure.
* Comparison with null
* Manual implementation of find
* Suppress a false positive
2022-07-10 08:43:04 -06:00
bors[bot]
caebe66185
Merge #1756
1756: Fix clippy on nightly r=asomers a=rtzoeller



Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2022-07-07 20:50:16 +00:00
Ryan Zoeller
8cfc530b88 Fix clippy on nightly 2022-07-07 15:02:36 -05:00
Nathaniel Daniel
22c4ba8bc0 Change gethostname to return an OsString 2022-06-27 19:48:14 -07:00
Nathaniel Daniel
356ecce5cd Change gethostname to use a buffer of MaybeUninit values 2022-06-27 19:48:14 -07:00
bors[bot]
0922fd99e7
Merge #1693
1693: Document aliases for functions like getuid() r=asomers a=rtzoeller

Add the autocfg crate as a build dependency, and introduce `has_doc_alias` as a conditional compilation symbol.

Closes #1673.

Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2022-06-27 00:52:16 +00:00
Ryan Zoeller
1fa1bb19b0 Document aliases for functions like getuid()
Add the autocfg crate as a build dependency, and introduce
has_doc_alias as a conditional compilation symbol.
2022-06-26 19:36:45 -05:00
bors[bot]
84b02b98a9
Merge #1751
1751: Pin cross to 0.2.1, as 0.2.2 requires Rust 1.58.1 r=asomers a=rtzoeller



Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2022-06-26 03:58:33 +00:00
Ryan Zoeller
d0d48f214b Pin cross to 0.2.1, as 0.2.2 requires Rust 1.58.1 2022-06-25 21:27:15 -05:00
bors[bot]
a45e9f8fe8
Merge #1748
1748: Add format test to CI r=rtzoeller a=costinsin

To enforce uniformity for all PRs, the CI checks if the code
is formatted right using `cargo fmt` tool.

Results after implementing the format test in CicleCI, but before fixing the format errors: https://cirrus-ci.com/build/4684991404703744
Results after fixing the format errors: https://cirrus-ci.com/build/5423803479097344

Solves #770 

Co-authored-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
2022-06-24 01:37:55 +00:00
Costin-Robert Sin
3e6cb639f0 Fix all formating problems to pass CI formating test
Signed-off-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
2022-06-24 00:35:52 +03:00
Costin-Robert Sin
8f08a69c28 Add format test to CI
To enforce uniformity for all PRs, the CI checks if the code
is formatted rigth using `cargo fmt` tool.

Signed-off-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
2022-06-24 00:35:31 +03:00
bors[bot]
2c7bb2ab85
Merge #1747
1747: Add getrusage wrapper r=rtzoeller a=kov

Includes an enum to specify what to get resource usage for, and a new
struct that provides a more readable view into libc::rusage, including
using TimeVal for user and system CPU time.

Signed-off-by: Gustavo Noronha Silva <gustavo@noronha.dev.br>

Co-authored-by: Gustavo Noronha Silva <gustavo@noronha.dev.br>
2022-06-21 03:04:36 +00:00
Gustavo Noronha Silva
9313a189d8 Add getrusage wrapper
Includes an enum to specify what to get resource usage for, and a new
struct that provides a more readable view into libc::rusage, including
using TimeVal for user and system CPU time.
2022-06-20 22:10:01 -03:00
bors[bot]
b6df05d63e
Merge #1746
1746: Fix typo and minimise the use of `unsafe` blocks inside the `pipe` function r=rtzoeller a=costinsin

Some of the operations inside the pipe function are safe and should not be included inside an unsafe block.

Co-authored-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
2022-06-19 01:28:28 +00:00
Costin-Robert Sin
a240d82880 Minimise the use of the unsafe block inside pipe function
Some of the operations inside the pipe function are safe and should
not be included inside an unsafe block.

Signed-off-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
2022-06-19 02:52:08 +03:00
Costin-Robert Sin
6755205782 Fix typo by adding a semicolon
Signed-off-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
2022-06-19 02:49:07 +03:00
bors[bot]
01a5927e2c
Merge #1739
1739: ppoll: make sigmask parameter optional r=rtzoeller a=stefano-garzarella

ppoll(2) supports 'sigmask' as NULL. In that case no signal mask
manipulation is performed.

Let's make `sigmask` parameter of `nix::poll::ppoll` optional
to allow that behaviour.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>

Co-authored-by: Stefano Garzarella <sgarzare@redhat.com>
2022-06-09 11:31:52 +00:00
Stefano Garzarella
c3081e4896 ppoll: make sigmask parameter optional
ppoll(2) supports 'sigmask' as NULL. In that case no signal mask
manipulation is performed.

Let's make `sigmask` parameter of `nix::poll::ppoll` optional
to allow that behaviour.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-06-09 09:09:23 +02:00
bors[bot]
b3ba2b5f63
Merge #1736
1736: Fix socket address family checks r=rtzoeller a=qwandor

The `SockaddrLike::from_raw` implementations for `VsockAddr` and `SysControlAddr` were checking against the wrong address family constant. This PR makes them consistent with the values matched against in `SockaddrStorage::from_raw`.

Co-authored-by: Andrew Walbran <qwandor@google.com>
2022-06-09 04:26:59 +00:00
bors[bot]
32d597bbd6
Merge #1735
1735: Cleanup cfg blocks r=asomers a=rtzoeller

Remove obsolete references to target_env = wasi, target_os = nacl, target_os = osx, and a typo'd target_os = fushsia that didn't compile when fixed.

 - target_env = wasi is dead: https://github.com/rust-lang/rust/pull/60117
 - target_os = nacl is dead: https://github.com/rust-lang/rust/pull/45041
 - target_os = osx is dead, but I can't find a link.

Found while exploring `--check-cfg`, as mentioned in #1734.

Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2022-06-09 03:52:06 +00:00
bors[bot]
649430f990
Merge #1737
1737: Fix the test_acct test r=rtzoeller a=asomers

It has never actually executed its command, so the only reason that it
ever worked is that on most systems there are usually processes starting
and exiting all the time.

Co-authored-by: Alan Somers <asomers@gmail.com>
2022-06-09 03:29:21 +00:00
Alan Somers
c8a9cf3351 Fix the test_acct test
It has never actually executed its command, so the only reason that it
ever worked is that on most systems there are usually processes starting
and exiting all the time.
2022-06-07 20:10:46 -06:00
Andrew Walbran
ccf1b80455 Mention fix in changelog. 2022-06-07 16:22:03 +01:00
Andrew Walbran
d3cc30c3da Fix socket address family check for SysControlAddr::from_raw. 2022-06-07 15:52:49 +01:00
Andrew Walbran
5a122f83a0 Fix socket address family check for VsockAddr::from_raw. 2022-06-07 15:52:03 +01:00
Ryan Zoeller
80f8320ffd Cleanup cfg blocks
Remove obsolete references to target_env = wasi, target_os = nacl,
target_os = osx, and a typo'd target_os = fushsia that didn't compile
when fixed.

 - target_env = wasi is dead: https://github.com/rust-lang/rust/pull/60117
 - target_os = nacl is dead: https://github.com/rust-lang/rust/pull/45041
 - target_os = osx is dead, but I can't find a link.
2022-06-06 18:50:19 -05:00
bors[bot]
5dedbc7850
Merge #1729
1729: Enable SockaddrStorage::{as_link_addr, as_link_addr_mut} on Linux. r=rtzoeller a=asomers

This was an oversight from #1684.

Fixes #1728

Co-authored-by: Alan Somers <asomers@gmail.com>
2022-05-31 23:57:45 +00:00
bors[bot]
b53dfa87c3
Merge #1730
1730: Ignore doctests for unexported macros r=asomers a=zombiepigdragon

Due to rust-lang/rust#97030, cargo test will fail to doctest macros unless they are exported, breaking the examples for `libc_bitflags!` and `libc_enum!`.

Adds `ignore` to the examples for these macros to stop tests from failing.

`cargo test` already fails on cargo 1.62.0-beta.2, and the above issue makes it seem unlikely that this will be changed on the Rust side. If rust-lang/rust#96630 *does* get reverted, this PR can be closed/unmerged, although the test wasn't running beforehand, and it might be worth making this explicit regardless.

Co-authored-by: Alex Rawson <ajzecrom@gmail.com>
2022-05-31 23:36:31 +00:00