rust-agent: Remove unused code that has undefined behavior

Some functions have undefined behavior and are not actually used.

This addresses the following warning:
    warning: the type `oci::User` does not permit zero-initialization
      --> rustjail/src/lib.rs:99:18
       |
    99 |         unsafe { MaybeUninit::zeroed().assume_init() }
       |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |                  |
       |                  this code causes undefined behavior when executed
       |                  help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
       |
       = note: `#[warn(invalid_value)]` on by default
    note: `std::ptr::Unique<u32>` must be non-null (in this struct field)

    warning: the type `protocols::oci::Process` does not permit zero-initialization
       --> rustjail/src/lib.rs:146:14
        |
    146 |     unsafe { MaybeUninit::zeroed().assume_init() }
        |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |              |
        |              this code causes undefined behavior when executed
        |              help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
        |
    note: `std::ptr::Unique<std::string::String>` must be non-null (in this struct field)

Fixes: #750

Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
This commit is contained in:
Christophe de Dinechin 2020-09-17 19:17:17 +02:00 committed by Peng Tao
parent 86bc151787
commit 19cb657299

View File

@ -69,7 +69,6 @@ use protocols::oci::{
Root as grpcRoot, Spec as grpcSpec, Root as grpcRoot, Spec as grpcSpec,
}; };
use std::collections::HashMap; use std::collections::HashMap;
use std::mem::MaybeUninit;
pub fn process_grpc_to_oci(p: &grpcProcess) -> ociProcess { pub fn process_grpc_to_oci(p: &grpcProcess) -> ociProcess {
let console_size = if p.ConsoleSize.is_some() { let console_size = if p.ConsoleSize.is_some() {
@ -91,7 +90,12 @@ pub fn process_grpc_to_oci(p: &grpcProcess) -> ociProcess {
username: u.Username.clone(), username: u.Username.clone(),
} }
} else { } else {
unsafe { MaybeUninit::zeroed().assume_init() } ociUser {
uid: 0,
gid: 0,
additional_gids: vec![],
username: String::from(""),
}
}; };
let capabilities = if p.Capabilities.is_some() { let capabilities = if p.Capabilities.is_some() {
@ -136,11 +140,6 @@ pub fn process_grpc_to_oci(p: &grpcProcess) -> ociProcess {
} }
} }
fn process_oci_to_grpc(_p: ociProcess) -> grpcProcess {
// dont implement it for now
unsafe { MaybeUninit::zeroed().assume_init() }
}
fn root_grpc_to_oci(root: &grpcRoot) -> ociRoot { fn root_grpc_to_oci(root: &grpcRoot) -> ociRoot {
ociRoot { ociRoot {
path: root.Path.clone(), path: root.Path.clone(),
@ -148,10 +147,6 @@ fn root_grpc_to_oci(root: &grpcRoot) -> ociRoot {
} }
} }
fn root_oci_to_grpc(_root: &ociRoot) -> grpcRoot {
unsafe { MaybeUninit::zeroed().assume_init() }
}
fn mount_grpc_to_oci(m: &grpcMount) -> ociMount { fn mount_grpc_to_oci(m: &grpcMount) -> ociMount {
ociMount { ociMount {
destination: m.destination.clone(), destination: m.destination.clone(),
@ -161,10 +156,6 @@ fn mount_grpc_to_oci(m: &grpcMount) -> ociMount {
} }
} }
fn mount_oci_to_grpc(_m: &ociMount) -> grpcMount {
unsafe { MaybeUninit::zeroed().assume_init() }
}
use oci::Hook as ociHook; use oci::Hook as ociHook;
use protocols::oci::Hook as grpcHook; use protocols::oci::Hook as grpcHook;
@ -195,10 +186,6 @@ fn hooks_grpc_to_oci(h: &grpcHooks) -> ociHooks {
} }
} }
fn hooks_oci_to_grpc(_h: &ociHooks) -> grpcHooks {
unsafe { MaybeUninit::zeroed().assume_init() }
}
use oci::{ use oci::{
LinuxDevice as ociLinuxDevice, LinuxIDMapping as ociLinuxIDMapping, LinuxDevice as ociLinuxDevice, LinuxIDMapping as ociLinuxIDMapping,
LinuxIntelRdt as ociLinuxIntelRdt, LinuxNamespace as ociLinuxNamespace, LinuxIntelRdt as ociLinuxIntelRdt, LinuxNamespace as ociLinuxNamespace,
@ -565,10 +552,6 @@ pub fn grpc_to_oci(grpc: &grpcSpec) -> ociSpec {
} }
} }
pub fn oci_to_grpc(_oci: &ociSpec) -> grpcSpec {
unsafe { MaybeUninit::zeroed().assume_init() }
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[test] #[test]