Skip to content

Commit

Permalink
Work around malformed path delimiters in file paths from DHCP
Browse files Browse the repository at this point in the history
shim uses path delimiters to determine the file path for the second
stage.  Currently only / (slash) is detected, but some DHCP
implementations supply \ (backslash) as the path specifier.

This patch changes it to accept either delimiter.

Fixes issue #524.

Signed-off-by: Alberto Perez <[email protected]>
  • Loading branch information
Alberto-Perez-Guevara authored and vathpela committed Jun 21, 2023
1 parent 0640e13 commit 0bfc397
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion netboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ static EFI_STATUS parseDhcp4()
UINT8 *dir = pkt_v4->BootpBootFile;

for (i = dir_len; i >= 0; i--) {
if (dir[i] == '/')
if ((dir[i] == '/') || (dir[i] == '\\'))
break;
}
dir_len = (i >= 0) ? i + 1 : 0;
Expand All @@ -277,6 +277,15 @@ static EFI_STATUS parseDhcp4()
strncpy(full_path, (CHAR8 *)dir, dir_len);
if (full_path[dir_len-1] == '/' && template[0] == '/')
full_path[dir_len-1] = '\0';
/*
* If the path from DHCP is using backslash instead of slash,
* accept that and use it in the template in the same position
* as well.
*/
if (full_path[dir_len-1] == '\\' && template[0] == '/') {
full_path[dir_len-1] = '\0';
template[0] = '\\';
}
}
if (dir_len == 0 && dir[0] != '/' && template[0] == '/')
template_ofs++;
Expand Down

0 comments on commit 0bfc397

Please sign in to comment.