From edb63b14225c783c673dcac0cc3c60aae076e45c Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 11 Jan 2021 11:37:11 +0100 Subject: kernels: Fix std::out_of_range if no kernels to protect In case we did not find any kernels to protect, the regular expression will be empty, and trying to substr(1) it will fail. --- apt-pkg/algorithms.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 260a8ac41..4c267c91c 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -1606,7 +1606,12 @@ std::string GetProtectedKernelsRegex(pkgCache *cache, bool ReturnRemove) } } - auto re = ss.str().substr(1); + auto re_with_leading_or = ss.str(); + + if (re_with_leading_or.empty()) + return ""; + + auto re = re_with_leading_or.substr(1); if (Debug) std::clog << "Kernel protection regex: " << re << "\n"; -- cgit v1.2.3 From 229e73afa4d6e862262f898a7e58942c90939306 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 11 Jan 2021 11:39:38 +0100 Subject: Call ischroot with -t We interpreted "cannot detect chroot" as "not a chroot", but it's arguably the better idea to detect it as a chroot, to avoid new behavior from phased updations in situations where it's unclear (no /proc mounted or stuff). --- apt-pkg/aptconfiguration.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index e88029f58..671c3d553 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -529,6 +529,7 @@ bool Configuration::isChroot() auto binary = _config->FindFile("Dir::Bin::ischroot", "/usr/bin/ischroot"); const char *const Args[] = { binary.c_str(), + "-t", nullptr}; execvp(Args[0], const_cast(Args)); _exit(127); -- cgit v1.2.3