Skip to content

Commit 0cc456e

Browse files
committed
Clean up clippy warnings
1 parent bdb78f7 commit 0cc456e

6 files changed

Lines changed: 36 additions & 11 deletions

File tree

sample/bin/sudo_approve

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ pair() {
5050
# (which causes a SIGPIPE to get sent). So the `kill` ensures the
5151
# subshell is killed without the user having to type something
5252
# additional that would cause the command to exit.
53+
#
54+
# FIXME: Technically, `echo` puts a secret value into an process
55+
# argument list, which isn't great. However, the window for
56+
# exploitation here is microscopic.
5357
{ socat STDIO unix-connect:"${socket}"; kill $!; } < <(
5458
echo -n "${token}" ; cat -
5559
)

sudo_pair/src/errors.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(crate) enum ErrorKind {
2020
}
2121

2222
impl ErrorKind {
23-
fn as_str(&self) -> &str {
23+
fn as_str(self) -> &'static str {
2424
match self {
2525
ErrorKind::CommunicationError => "couldn't establish communications with the pair",
2626
ErrorKind::SessionDeclined => "pair declined the session",
@@ -51,14 +51,14 @@ impl Display for Error {
5151
impl Fail for Error {}
5252

5353
impl From<ErrorKind> for Error {
54-
fn from(kind: ErrorKind) -> Error {
55-
Error::from(Context::new(kind))
54+
fn from(kind: ErrorKind) -> Self {
55+
Self::from(Context::new(kind))
5656
}
5757
}
5858

5959
impl From<Context<ErrorKind>> for Error {
60-
fn from(inner: Context<ErrorKind>) -> Error {
61-
Error { inner: inner }
60+
fn from(inner: Context<ErrorKind>) -> Self {
61+
Self { inner }
6262
}
6363
}
6464

@@ -68,8 +68,8 @@ impl From<Context<ErrorKind>> for Error {
6868
/// converted to an Unauthorized error.
6969
///
7070
impl From<Error> for SudoPluginError {
71-
fn from(error: Error) -> SudoPluginError {
72-
SudoPluginError::with_chain(
71+
fn from(error: Error) -> Self {
72+
Self::with_chain(
7373
error.compat(),
7474
SudoPluginErrorKind::Unauthorized
7575
)
@@ -81,7 +81,7 @@ impl From<Error> for SudoPluginError {
8181
/// implicitly wrapped in a new `Error`.
8282
///
8383
impl From<ErrorKind> for SudoPluginError {
84-
fn from(kind: ErrorKind) -> SudoPluginError {
85-
SudoPluginError::from(Error::from(kind))
84+
fn from(kind: ErrorKind) -> Self {
85+
Self::from(Error::from(kind))
8686
}
8787
}

sudo_pair/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,13 @@ impl SudoPair {
283283
).context(ErrorKind::CommunicationError)?;
284284

285285
let mut response : [u8; 16] = [0; 16];
286-
let _ = socket.read_exact(&mut response)
286+
287+
// TODO: read_exact will cause this process to block
288+
// indefinitely (even on Ctrl-C) until the correct number of
289+
// bytes are read; this won't happen in normal circumstances,
290+
// but a bug in (or untimely exit of) the approval script can
291+
// cause this process to hang and require being killed
292+
socket.read_exact(&mut response)
287293
.context(ErrorKind::CommunicationError)?;
288294

289295
// non-constant comparison is fine here since a comparison

sudo_pair/src/socket.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
// implied. See the License for the specific language governing
1313
// permissions and limitations under the License.
1414

15+
// these warnings are unavoidable with names like `uid` and `gid`, and
16+
// such names are natural to use for this problem domain so should not
17+
// be avoided
18+
#![cfg_attr(feature="cargo-clippy", allow(similar_names))]
19+
1520
use std::ffi::CString;
1621
use std::fs;
1722
use std::io::{Read, Write, Result, Error, ErrorKind};
@@ -30,7 +35,6 @@ pub(crate) struct Socket {
3035
}
3136

3237
impl Socket {
33-
#[cfg_attr(feature="cargo-clippy", allow(similar_names))]
3438
pub(crate) fn open<P: AsRef<Path>>(
3539
path: P,
3640
uid: uid_t,

sudo_plugin/src/plugin/option_map.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ impl OptionMap {
6868
// separators might not exist (e.g., in the case of parsing
6969
// plugin options; for this case, we use the full entry as
7070
// both the name of the key and its value
71+
//
72+
// indexing into an array can panic, but there's no cleaner
73+
// way in rust to split a byte array on a delimiter, and
74+
// the code above selects `sep` such that it's guaranteed to
75+
// be within the slice
76+
#[cfg_attr(feature = "cargo-clippy", allow(indexing_slicing))]
7177
let (k, v) = match sep {
7278
Some(s) => { ( &bytes[..s], &bytes[s+1..] ) }
7379
None => { ( &bytes[..], &bytes[..] ) }

sudo_plugin/src/plugin/settings.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ pub struct NetAddr {
199199
impl FromSudoOption for NetAddr {
200200
type Err = AddrParseError;
201201

202+
// indexing into an array can panic, but there's no cleaner way in
203+
// rust to split a byte array on a delimiter, and the code below
204+
// selects the midpoint such that it's guaranteed to be within the
205+
// slice
206+
#[cfg_attr(feature = "cargo-clippy", allow(indexing_slicing))]
202207
fn from_sudo_option(s: &str) -> ::std::result::Result<Self, Self::Err> {
203208
let bytes = s.as_bytes();
204209
let mid = bytes.iter()

0 commit comments

Comments
 (0)