summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2021-01-11 11:37:11 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2021-01-11 11:37:11 +0100
commitedb63b14225c783c673dcac0cc3c60aae076e45c (patch)
tree2310e4d2eb2c695ac15275112b064718494db248
parent8ecd0d2c572b0c36142f39a8691ace91ed90c8ca (diff)
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.
-rw-r--r--apt-pkg/algorithms.cc7
1 files changed, 6 insertions, 1 deletions
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";