File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
crates/lib/src/bootc_composefs Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -162,8 +162,20 @@ fn get_bootloader() -> Result<Bootloader> {
162162
163163 const EFI_LOADER_INFO : & str = "LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f" ;
164164
165- match efivarfs. read_to_string ( EFI_LOADER_INFO ) {
166- Ok ( loader) => {
165+ match efivarfs. read ( EFI_LOADER_INFO ) {
166+ Ok ( loader_bytes) => {
167+ if loader_bytes. len ( ) % 2 != 0 {
168+ anyhow:: bail!( "EFI var length is not valid UTF-16 LE" ) ;
169+ }
170+
171+ // EFI vars are UTF-16 LE
172+ let loader_u16_bytes: Vec < u16 > = loader_bytes
173+ . chunks_exact ( 2 )
174+ . map ( |x| u16:: from_le_bytes ( [ x[ 0 ] , x[ 1 ] ] ) )
175+ . collect ( ) ;
176+
177+ let loader = String :: from_utf16 ( & loader_u16_bytes) . context ( "EFI var is not UTF-16" ) ?;
178+
167179 if loader. to_lowercase ( ) . contains ( "systemd-boot" ) {
168180 return Ok ( Bootloader :: Systemd ) ;
169181 }
You can’t perform that action at this time.
0 commit comments