Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rpm-ostree -h usroverlay segfault #4550

Merged
merged 2 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions rpmostree-cxxrs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,9 @@ extern "C"
rpmostreecxx$cxxbridge1$Bubblewrap$run (::rpmostreecxx::Bubblewrap &self,
const ::rpmostreecxx::GCancellable &cancellable) noexcept;

::rust::repr::PtrLen
rpmostreecxx$cxxbridge1$usroverlay_entrypoint (const ::rust::Vec< ::rust::String> &args) noexcept;

::rust::repr::PtrLen
rpmostreecxx$cxxbridge1$applylive_entrypoint (const ::rust::Vec< ::rust::String> &args) noexcept;

Expand Down Expand Up @@ -3534,6 +3537,16 @@ Bubblewrap::run (const ::rpmostreecxx::GCancellable &cancellable)
}
}

void
usroverlay_entrypoint (const ::rust::Vec< ::rust::String> &args)
{
::rust::repr::PtrLen error$ = rpmostreecxx$cxxbridge1$usroverlay_entrypoint (args);
if (error$.ptr)
{
throw ::rust::impl< ::rust::Error>::error (error$);
}
}

void
applylive_entrypoint (const ::rust::Vec< ::rust::String> &args)
{
Expand Down
2 changes: 2 additions & 0 deletions rpmostree-cxxrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,8 @@ ::rust::Box< ::rpmostreecxx::Bubblewrap>
bubblewrap_new_with_mutability (::std::int32_t rootfs_fd,
::rpmostreecxx::BubblewrapMutability mutability);

void usroverlay_entrypoint (const ::rust::Vec< ::rust::String> &args);

void applylive_entrypoint (const ::rust::Vec< ::rust::String> &args);

void applylive_finish (const ::rpmostreecxx::OstreeSysroot &sysroot);
Expand Down
26 changes: 2 additions & 24 deletions rust/src/builtins/usroverlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,15 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use anyhow::{Context, Result};
use clap::Command;
use std::os::unix::prelude::CommandExt;

/// Directly exec(ostree admin unlock) - does not return on success.
pub fn entrypoint(args: &[&str]) -> Result<()> {
let cmd = cli_cmd();
cmd.get_matches_from(args.iter().skip(1));

pub fn usroverlay_entrypoint(args: &Vec<String>) -> Result<()> {
let exec_err = std::process::Command::new("ostree")
.args(&["admin", "unlock"])
.args(args.into_iter().skip(1))
.exec();

// This is only reached if the `exec()` above failed; otherwise
// execution got transferred to `ostree` at that point.
Err(exec_err).context("Failed to execute 'ostree admin unlock'")
}

/// CLI parser, handle --help and error on extra arguments.
fn cli_cmd() -> Command {
Command::new("rpm-ostree usroverlay")
.bin_name("rpm-ostree usroverlay")
.long_version("")
.long_about("Apply a transient overlayfs to /usr")
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_clap_cmd() {
cli_cmd().debug_assert()
}
}
2 changes: 2 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub mod ffi {

// builtins/apply_live.rs
extern "Rust" {
fn usroverlay_entrypoint(args: &Vec<String>) -> Result<()>;
fn applylive_entrypoint(args: &Vec<String>) -> Result<()>;
fn applylive_finish(sysroot: &OstreeSysroot) -> Result<()>;
}
Expand Down Expand Up @@ -901,6 +902,7 @@ pub mod builtins;
pub(crate) use crate::builtins::apply_live::*;
pub(crate) use crate::builtins::compose::commit::*;
pub(crate) use crate::builtins::compose::*;
pub(crate) use crate::builtins::usroverlay::usroverlay_entrypoint;
mod bwrap;
pub(crate) use bwrap::*;
pub mod client;
Expand Down
2 changes: 0 additions & 2 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ async fn inner_async_main(args: Vec<String>) -> Result<i32> {
// Add custom Rust commands here, and also in `libmain.cxx` if user-visible.
"countme" => rpmostree_rust::countme::entrypoint(args).map(|_| 0),
"cliwrap" => rpmostree_rust::cliwrap::entrypoint(args).map(|_| 0),
// The `unlock` is a hidden alias for "ostree CLI compatibility"
"usroverlay" | "unlock" => builtins::usroverlay::entrypoint(args).map(|_| 0),
// A hidden wrapper to intercept some binaries in RPM scriptlets.
"scriptlet-intercept" => builtins::scriptlet_intercept::entrypoint(args).map(|_| 0),
// This is a deprecated entrypoint
Expand Down
18 changes: 17 additions & 1 deletion src/app/libmain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@

#include "libglnx.h"

static gboolean
dispatch_usroverlay (int argc, char **argv, RpmOstreeCommandInvocation *invocation,
GCancellable *cancellable, GError **error)
{
rust::Vec<rust::String> rustargv;
for (int i = 0; i < argc; i++)
rustargv.push_back (std::string (argv[i]));
CXX_TRY (rpmostreecxx::usroverlay_entrypoint (rustargv), error);
return TRUE;
}

static RpmOstreeCommand commands[] = {
{ "compose",
static_cast<RpmOstreeBuiltinFlags> (RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD
Expand Down Expand Up @@ -91,7 +102,12 @@ static RpmOstreeCommand commands[] = {
{ "scriptlet-intercept", static_cast<RpmOstreeBuiltinFlags> (RPM_OSTREE_BUILTIN_FLAG_HIDDEN),
"Intercept some commands used by RPM scriptlets", NULL },
{ "usroverlay", static_cast<RpmOstreeBuiltinFlags> (RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT),
"Apply a transient overlayfs to /usr", NULL },
"Apply a transient overlayfs to /usr", dispatch_usroverlay },
// Alias for ostree compatibility
{ "unlock",
static_cast<RpmOstreeBuiltinFlags> (RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT
| RPM_OSTREE_BUILTIN_FLAG_HIDDEN),
"Apply a transient overlayfs to /usr", dispatch_usroverlay },
/* Legacy aliases */
{ "pkg-add", static_cast<RpmOstreeBuiltinFlags> (RPM_OSTREE_BUILTIN_FLAG_HIDDEN), NULL,
rpmostree_builtin_install },
Expand Down
7 changes: 7 additions & 0 deletions tests/kolainst/nondestructive/misc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ for verb in container ima-sign; do
done
echo "ok multicall corectly set up and working"

# Verify that we process arguments correctly
rpm-ostree usroverlay --help >out.txt
assert_file_has_content out.txt "ostree admin unlock"
rm -f out.txt
rpm-ostree -h usroverlay >out.txt
assert_file_has_content out.txt "ostree admin unlock"

# make sure that package-related entries are always present,
# even when they're empty.
# Validate there's no live state by default.
Expand Down