mirror of
https://git.proxmox.com/git/efi-boot-shim
synced 2025-08-03 13:47:39 +00:00
Fix path generation for Dhcpv4 bootloader.
Right now we always look for e.g. "\grubx64.efi", which is completely wrong. This makes it look for the path shim was loaded from and modify that to end in a sanitized version of our default loader name. Resolves: rhbz#1032583 Signed-off-by: Peter Jones <pjones@redhat.com>
This commit is contained in:
parent
8b48ec5c70
commit
e62b69a5b0
45
include/str.h
Normal file
45
include/str.h
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef SHIM_STR_H
|
||||
#define SHIM_STR_H
|
||||
|
||||
static inline
|
||||
__attribute__((unused))
|
||||
unsigned long strnlena(const CHAR8 *s, unsigned long n)
|
||||
{
|
||||
unsigned long i;
|
||||
for (i = 0; i <= n; i++)
|
||||
if (s[i] == '\0')
|
||||
break;
|
||||
return i;
|
||||
}
|
||||
|
||||
static inline
|
||||
__attribute__((unused))
|
||||
CHAR8 *
|
||||
strncpya(CHAR8 *dest, const CHAR8 *src, unsigned long n)
|
||||
{
|
||||
unsigned long i;
|
||||
|
||||
for (i = 0; i < n && src[i] != '\0'; i++)
|
||||
dest[i] = src[i];
|
||||
for (; i < n; i++)
|
||||
dest[i] = '\0';
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
static inline
|
||||
__attribute__((unused))
|
||||
CHAR8 *
|
||||
strcata(CHAR8 *dest, const CHAR8 *src)
|
||||
{
|
||||
unsigned long dest_len = strlena(dest);
|
||||
unsigned long i;
|
||||
|
||||
for (i = 0; src[i] != '\0'; i++)
|
||||
dest[dest_len + i] = src[i];
|
||||
dest[dest_len + i] = '\0';
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
#endif /* SHIM_STR_H */
|
28
netboot.c
28
netboot.c
@ -38,6 +38,7 @@
|
||||
#include <string.h>
|
||||
#include "shim.h"
|
||||
#include "netboot.h"
|
||||
#include "str.h"
|
||||
|
||||
static inline unsigned short int __swap16(unsigned short int x)
|
||||
{
|
||||
@ -305,19 +306,32 @@ static EFI_STATUS parseDhcp6()
|
||||
|
||||
static EFI_STATUS parseDhcp4()
|
||||
{
|
||||
CHAR8 *template = (CHAR8 *)DEFAULT_LOADER_CHAR;
|
||||
full_path = AllocateZeroPool(strlen(template)+1);
|
||||
CHAR8 *template = (CHAR8 *)translate_slashes(DEFAULT_LOADER_CHAR);
|
||||
UINTN template_len = strlen(template) + 1;
|
||||
|
||||
UINTN dir_len = strnlena(pxe->Mode->DhcpAck.Dhcpv4.BootpBootFile, 127);
|
||||
UINTN i;
|
||||
UINT8 *dir = pxe->Mode->DhcpAck.Dhcpv4.BootpBootFile;
|
||||
|
||||
for (i = dir_len; i >= 0; i--) {
|
||||
if (dir[i] == '/')
|
||||
break;
|
||||
}
|
||||
dir_len = (i >= 0) ? i + 1 : 0;
|
||||
|
||||
full_path = AllocateZeroPool(dir_len + template_len);
|
||||
|
||||
if (!full_path)
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
|
||||
if (dir_len > 0) {
|
||||
strncpya(full_path, dir, dir_len);
|
||||
if (full_path[dir_len-1] == '/' && template[0] == '/')
|
||||
full_path[dir_len-1] = '\0';
|
||||
}
|
||||
strcata(full_path, template);
|
||||
memcpy(&tftp_addr.v4, pxe->Mode->DhcpAck.Dhcpv4.BootpSiAddr, 4);
|
||||
|
||||
memcpy(full_path, template, strlen(template));
|
||||
|
||||
/* Note we don't capture the filename option here because we know its shim.efi
|
||||
* We instead assume the filename at the end of the path is going to be grubx64.efi
|
||||
*/
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user