File tree 1 file changed +11
-3
lines changed
library/std/src/sys/pal/unix/process
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -330,14 +330,22 @@ impl Command {
330
330
if let Some ( u) = self . get_uid ( ) {
331
331
// When dropping privileges from root, the `setgroups` call
332
332
// will remove any extraneous groups. We only drop groups
333
- // if we weren't given an explicit set of groups.
334
- // If we don't call this, then even though our
333
+ // if we have CAP_SETGID and we weren't given an explicit
334
+ // set of groups. If we don't call this, then even though our
335
335
// uid has dropped, we may still have groups that enable us to
336
336
// do super-user things.
337
337
//FIXME: Redox kernel does not support setgroups yet
338
338
#[ cfg( not( target_os = "redox" ) ) ]
339
339
if self . get_groups ( ) . is_none ( ) {
340
- cvt ( libc:: setgroups ( 0 , crate :: ptr:: null ( ) ) ) ?;
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
+ }
341
349
}
342
350
cvt ( libc:: setuid ( u as uid_t ) ) ?;
343
351
}
You can’t perform that action at this time.
0 commit comments