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@gentoo.org>
This commit is contained in:
Robin H. Johnson
2022-12-04 21:35:34 -08:00
parent 2e5e492f54
commit 19b45d085c
2 changed files with 11 additions and 1 deletions

View File

@@ -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() {

View File

@@ -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() {