Skip to content

Commit b211225

Browse files
committed
Auto merge of rust-lang#122511 - matthiaskrgr:rollup-swzilin, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#117118 ([AIX] Remove AixLinker's debuginfo() implementation) - rust-lang#121650 (change std::process to drop supplementary groups based on CAP_SETGID) - rust-lang#121764 (Make incremental sessions identity no longer depend on the crate names provided by source code) - rust-lang#122212 (Copy byval argument to alloca if alignment is insufficient) - rust-lang#122322 (coverage: Initial support for branch coverage instrumentation) - rust-lang#122373 (Fix the conflict problem between the diagnostics fixes of lint `unnecessary_qualification` and `unused_imports`) - rust-lang#122479 (Implement `Duration::as_millis_{f64,f32}`) - rust-lang#122487 (Rename `StmtKind::Local` variant into `StmtKind::Let`) - rust-lang#122498 (Update version of cc crate) - rust-lang#122503 (Make `SubdiagMessageOp` well-formed) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8b66170 + ed30c01 commit b211225

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

core/src/time.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,48 @@ impl Duration {
856856
(self.secs as f32) + (self.nanos.0 as f32) / (NANOS_PER_SEC as f32)
857857
}
858858

859+
/// Returns the number of milliseconds contained by this `Duration` as `f64`.
860+
///
861+
/// The returned value does include the fractional (nanosecond) part of the duration.
862+
///
863+
/// # Examples
864+
/// ```
865+
/// #![feature(duration_millis_float)]
866+
/// use std::time::Duration;
867+
///
868+
/// let dur = Duration::new(2, 345_678_000);
869+
/// assert_eq!(dur.as_millis_f64(), 2345.678);
870+
/// ```
871+
#[unstable(feature = "duration_millis_float", issue = "122451")]
872+
#[must_use]
873+
#[inline]
874+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
875+
pub const fn as_millis_f64(&self) -> f64 {
876+
(self.secs as f64) * (MILLIS_PER_SEC as f64)
877+
+ (self.nanos.0 as f64) / (NANOS_PER_MILLI as f64)
878+
}
879+
880+
/// Returns the number of milliseconds contained by this `Duration` as `f32`.
881+
///
882+
/// The returned value does include the fractional (nanosecond) part of the duration.
883+
///
884+
/// # Examples
885+
/// ```
886+
/// #![feature(duration_millis_float)]
887+
/// use std::time::Duration;
888+
///
889+
/// let dur = Duration::new(2, 345_678_000);
890+
/// assert_eq!(dur.as_millis_f32(), 2345.678);
891+
/// ```
892+
#[unstable(feature = "duration_millis_float", issue = "122451")]
893+
#[must_use]
894+
#[inline]
895+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
896+
pub const fn as_millis_f32(&self) -> f32 {
897+
(self.secs as f32) * (MILLIS_PER_SEC as f32)
898+
+ (self.nanos.0 as f32) / (NANOS_PER_MILLI as f32)
899+
}
900+
859901
/// Creates a new `Duration` from the specified number of seconds represented
860902
/// as `f64`.
861903
///

profiler_builtins/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ core = { path = "../core" }
1313
compiler_builtins = { version = "0.1.0", features = ['rustc-dep-of-std'] }
1414

1515
[build-dependencies]
16-
cc = "1.0.69"
16+
cc = "1.0.90"

std/src/os/unix/process.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ pub trait CommandExt: Sealed {
3939
/// Sets the child process's user ID. This translates to a
4040
/// `setuid` call in the child process. Failure in the `setuid`
4141
/// call will cause the spawn to fail.
42+
///
43+
/// # Notes
44+
///
45+
/// This will also trigger a call to `setgroups(0, NULL)` in the child
46+
/// process if no groups have been specified.
47+
/// This removes supplementary groups that might have given the child
48+
/// unwanted permissions.
4249
#[stable(feature = "rust1", since = "1.0.0")]
4350
fn uid(&mut self, id: UserId) -> &mut process::Command;
4451

std/src/sys/pal/unix/process/process_unix.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,22 @@ impl Command {
330330
if let Some(u) = self.get_uid() {
331331
// When dropping privileges from root, the `setgroups` call
332332
// will remove any extraneous groups. We only drop groups
333-
// if the current uid is 0 and we weren't given an explicit
333+
// if we have CAP_SETGID and we weren't given an explicit
334334
// set of groups. If we don't call this, then even though our
335335
// uid has dropped, we may still have groups that enable us to
336336
// do super-user things.
337337
//FIXME: Redox kernel does not support setgroups yet
338338
#[cfg(not(target_os = "redox"))]
339-
if libc::getuid() == 0 && self.get_groups().is_none() {
340-
cvt(libc::setgroups(0, crate::ptr::null()))?;
339+
if self.get_groups().is_none() {
340+
let res = cvt(libc::setgroups(0, crate::ptr::null()));
341+
if let Err(e) = res {
342+
// Here we ignore the case of not having CAP_SETGID.
343+
// An alternative would be to require CAP_SETGID (in
344+
// addition to CAP_SETUID) for setting the UID.
345+
if e.raw_os_error() != Some(libc::EPERM) {
346+
return Err(e.into());
347+
}
348+
}
341349
}
342350
cvt(libc::setuid(u as uid_t))?;
343351
}

0 commit comments

Comments
 (0)