commit: 19b45d085c9fe12820eaa5d89eb9469a8d8b3bb3 Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> AuthorDate: Mon Dec 5 05:35:34 2022 +0000 Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> CommitDate: Mon Dec 5 05:36:21 2022 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=19b45d08
sys-boot/mbr-gpt: add safety check If the compiler/linker/objdump options make the mbr too large, bail out, so nobody accidently wipes out the start of their drives with a large MBR. Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org> sys-boot/mbr-gpt/mbr-gpt-0.0.1-r1.ebuild | 5 +++++ sys-boot/mbr-gpt/mbr-gpt-0.0.1-r2.ebuild | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sys-boot/mbr-gpt/mbr-gpt-0.0.1-r1.ebuild b/sys-boot/mbr-gpt/mbr-gpt-0.0.1-r1.ebuild index 3073a1e1cfed..1b062d5e5648 100644 --- a/sys-boot/mbr-gpt/mbr-gpt-0.0.1-r1.ebuild +++ b/sys-boot/mbr-gpt/mbr-gpt-0.0.1-r1.ebuild @@ -44,6 +44,11 @@ src_prepare() { src_compile() { emake CC="$(tc-getCC)" + # validate the size, it MUST fit into an MBR (440 bytes!) + size=$(stat --printf='%s' mbr) + if test $size -gt 440; then + die "Compiled MBR is too large! Must be at most 440 bytes, was $size" + fi } src_install() { diff --git a/sys-boot/mbr-gpt/mbr-gpt-0.0.1-r2.ebuild b/sys-boot/mbr-gpt/mbr-gpt-0.0.1-r2.ebuild index df636e06b770..9359c8200a24 100644 --- a/sys-boot/mbr-gpt/mbr-gpt-0.0.1-r2.ebuild +++ b/sys-boot/mbr-gpt/mbr-gpt-0.0.1-r2.ebuild @@ -27,7 +27,7 @@ QA_PRESTRIPPED="${QA_WX_LOAD}" QA_FLAGS_IGNORED="${QA_WX_LOAD}" # Don't strip it either; this binary reboots your host! -RESTRICT="binchecks strip" +RESTRICT="strip" src_prepare() { default @@ -46,6 +46,11 @@ src_prepare() { src_compile() { emake CC="$(tc-getCC)" + # validate the size, it MUST fit into an MBR (440 bytes!) + size=$(stat --printf='%s' mbr) + if test $size -gt 440; then + die "Compiled MBR is too large! Must be at most 440 bytes, was $size" + fi } src_install() {