diff mbox

uefibootpath: include the null-terminated space in device path length

Message ID 1421308747-27409-1-git-send-email-ivan.hu@canonical.com
State Accepted
Headers show

Commit Message

Ivan Hu Jan. 15, 2015, 7:59 a.m. UTC
The UEFI spec defined some Device Path, such as the Description String on BIOS
Boot Specification Device Path as a null-terminated ASCII string that describes
the boot device to a user. Those null-terminated spaces need to be included to the device path length.

Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 src/uefi/uefibootpath/uefibootpath.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Keng-Yu Lin Jan. 20, 2015, 7:41 a.m. UTC | #1
On Thu, Jan 15, 2015 at 3:59 PM, Ivan Hu <ivan.hu@canonical.com> wrote:
> The UEFI spec defined some Device Path, such as the Description String on BIOS
> Boot Specification Device Path as a null-terminated ASCII string that describes
> the boot device to a user. Those null-terminated spaces need to be included to the device path length.
>
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/uefi/uefibootpath/uefibootpath.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/uefi/uefibootpath/uefibootpath.c b/src/uefi/uefibootpath/uefibootpath.c
> index 1c11963..6c521e4 100644
> --- a/src/uefi/uefibootpath/uefibootpath.c
> +++ b/src/uefi/uefibootpath/uefibootpath.c
> @@ -606,7 +606,7 @@ static int uefibootpath_check_dev_path(fwts_framework *fw, fwts_uefi_dev_path *d
>                                         "The length of File Path Media Device Path is %" PRIu16 " bytes "
>                                         "is not matching with adding the length of Path String %" PRIu16 " bytes.",
>                                         len,
> -                                       (uint16_t)(sizeof(fwts_uefi_file_path_dev_path) + (fwts_uefi_str16len(f->path_name) * sizeof(uint16_t))));
> +                                       (uint16_t)(sizeof(fwts_uefi_file_path_dev_path) + ((fwts_uefi_str16len(f->path_name) + 1) * sizeof(uint16_t))));
>                                 errors++;
>                                 break;
>                         }
> @@ -660,12 +660,12 @@ static int uefibootpath_check_dev_path(fwts_framework *fw, fwts_uefi_dev_path *d
>                                 break;
>                         }
>                         fwts_uefi_bios_dev_path *b = (fwts_uefi_bios_dev_path *)dev_path;
> -                       if (len != (sizeof(fwts_uefi_bios_dev_path) + strlen(b->description))) {
> +                       if (len != (sizeof(fwts_uefi_bios_dev_path) + strlen(b->description) + 1)) {
>                                 fwts_failed(fw, LOG_LEVEL_MEDIUM, "UEFIBiosBootDevPathLength",
>                                         "The length of BIOS Boot Specification Device Path is %" PRIu16 " bytes "
>                                         "is not matching with adding the length of Description String %" PRIu16 " bytes.",
>                                         len,
> -                                       (uint16_t)(sizeof(fwts_uefi_bios_dev_path) + strlen(b->description)));
> +                                       (uint16_t)(sizeof(fwts_uefi_bios_dev_path) + strlen(b->description) + 1));
>                                 errors++;
>                         }
>                         break;
> --
> 1.7.9.5
>

for the first case, there is already one char plus in the comparison,
it is good to have that additional one printed too.

for the second, strlen() does steal the final null char, so

Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Alex Hung Jan. 20, 2015, 9:18 a.m. UTC | #2
On 01/15/2015 03:59 PM, Ivan Hu wrote:
> The UEFI spec defined some Device Path, such as the Description String on BIOS
> Boot Specification Device Path as a null-terminated ASCII string that describes
> the boot device to a user. Those null-terminated spaces need to be included to the device path length.
> 
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/uefi/uefibootpath/uefibootpath.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/uefi/uefibootpath/uefibootpath.c b/src/uefi/uefibootpath/uefibootpath.c
> index 1c11963..6c521e4 100644
> --- a/src/uefi/uefibootpath/uefibootpath.c
> +++ b/src/uefi/uefibootpath/uefibootpath.c
> @@ -606,7 +606,7 @@ static int uefibootpath_check_dev_path(fwts_framework *fw, fwts_uefi_dev_path *d
>  					"The length of File Path Media Device Path is %" PRIu16 " bytes "
>  					"is not matching with adding the length of Path String %" PRIu16 " bytes.",
>  					len,
> -					(uint16_t)(sizeof(fwts_uefi_file_path_dev_path) + (fwts_uefi_str16len(f->path_name) * sizeof(uint16_t))));
> +					(uint16_t)(sizeof(fwts_uefi_file_path_dev_path) + ((fwts_uefi_str16len(f->path_name) + 1) * sizeof(uint16_t))));
>  				errors++;
>  				break;
>  			}
> @@ -660,12 +660,12 @@ static int uefibootpath_check_dev_path(fwts_framework *fw, fwts_uefi_dev_path *d
>  				break;
>  			}
>  			fwts_uefi_bios_dev_path *b = (fwts_uefi_bios_dev_path *)dev_path;
> -			if (len != (sizeof(fwts_uefi_bios_dev_path) + strlen(b->description))) {
> +			if (len != (sizeof(fwts_uefi_bios_dev_path) + strlen(b->description) + 1)) {
>  				fwts_failed(fw, LOG_LEVEL_MEDIUM, "UEFIBiosBootDevPathLength",
>  					"The length of BIOS Boot Specification Device Path is %" PRIu16 " bytes "
>  					"is not matching with adding the length of Description String %" PRIu16 " bytes.",
>  					len,
> -					(uint16_t)(sizeof(fwts_uefi_bios_dev_path) + strlen(b->description)));
> +					(uint16_t)(sizeof(fwts_uefi_bios_dev_path) + strlen(b->description) + 1));
>  				errors++;
>  			}
>  			break;
> 

Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox

Patch

diff --git a/src/uefi/uefibootpath/uefibootpath.c b/src/uefi/uefibootpath/uefibootpath.c
index 1c11963..6c521e4 100644
--- a/src/uefi/uefibootpath/uefibootpath.c
+++ b/src/uefi/uefibootpath/uefibootpath.c
@@ -606,7 +606,7 @@  static int uefibootpath_check_dev_path(fwts_framework *fw, fwts_uefi_dev_path *d
 					"The length of File Path Media Device Path is %" PRIu16 " bytes "
 					"is not matching with adding the length of Path String %" PRIu16 " bytes.",
 					len,
-					(uint16_t)(sizeof(fwts_uefi_file_path_dev_path) + (fwts_uefi_str16len(f->path_name) * sizeof(uint16_t))));
+					(uint16_t)(sizeof(fwts_uefi_file_path_dev_path) + ((fwts_uefi_str16len(f->path_name) + 1) * sizeof(uint16_t))));
 				errors++;
 				break;
 			}
@@ -660,12 +660,12 @@  static int uefibootpath_check_dev_path(fwts_framework *fw, fwts_uefi_dev_path *d
 				break;
 			}
 			fwts_uefi_bios_dev_path *b = (fwts_uefi_bios_dev_path *)dev_path;
-			if (len != (sizeof(fwts_uefi_bios_dev_path) + strlen(b->description))) {
+			if (len != (sizeof(fwts_uefi_bios_dev_path) + strlen(b->description) + 1)) {
 				fwts_failed(fw, LOG_LEVEL_MEDIUM, "UEFIBiosBootDevPathLength",
 					"The length of BIOS Boot Specification Device Path is %" PRIu16 " bytes "
 					"is not matching with adding the length of Description String %" PRIu16 " bytes.",
 					len,
-					(uint16_t)(sizeof(fwts_uefi_bios_dev_path) + strlen(b->description)));
+					(uint16_t)(sizeof(fwts_uefi_bios_dev_path) + strlen(b->description) + 1));
 				errors++;
 			}
 			break;