]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
efibootmgr: Simplify make_next_boot_var_name and fix cnt == 0 case
authorJessica Clarke <jrtc27@FreeBSD.org>
Fri, 23 Feb 2024 02:36:21 +0000 (02:36 +0000)
committerJessica Clarke <jrtc27@FreeBSD.org>
Fri, 23 Feb 2024 02:36:21 +0000 (02:36 +0000)
commit09cb8031b43c8e98abb5ff9b43ff649031d1e808
treedbdd7eeabbb0aff9974543d8cf00a290f8740861
parent04eca69323111986b262eef3135d804361b60d17
efibootmgr: Simplify make_next_boot_var_name and fix cnt == 0 case

If cnt == 0 we access element 0 unconditionally, which is out of bounds,
and then if that doesn't crash and happens to be 0 we will access
element - 1, also out of bounds, and then if that doesn't crash will add
1 to whatever junk is there and use that for the variable. On CHERI,
though, this does crash. This code is also overly complicated, with
unnecessary special cases and tracking more state than needed.

Rewrite it in a more general manner that doesn't need those special
cases and naturally works for cnt == 0.

Found by: CHERI
Reviewed by: imp
Fixes: 1285bcc833a3 ("Import Netflix's efibootmgr to help manage UEFI boot variables")
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D44029
usr.sbin/efibootmgr/efibootmgr.c