cmd: efidebug: fix a failure of "boot rm" sub-command
PATCH 1/1 cmd: efidebug: fix a failure of "boot rm" sub-command
There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and then it will end up with a failure of this command due to a wrong value of an interim variable ("var_name16").
--- cmd/efidebug.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
cmd/efidebug.c +3 -2
@@ -641,7 +641,7 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag,int id, i;char *endp;char var_name[9 ]; -u16 var_name16[9 ]; +u16 var_name16[9 ], *p;efi_status_t ret;if (argc ==1 )
@@ -654,7 +654,8 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag,return CMD_RET_FAILURE ;sprintf (var_name,"Boot%04X" , id); -utf8_utf16_strncpy ((u16 **)&var_name16, var_name,9 ); + p = var_name16; +utf8_utf16_strncpy (&p, var_name,9 ); ret =EFI_CALL (RT ->set_variable (var_name16, &guid,0 ,0 ,NULL ));if (ret) {
Signature · 1 line
2.24.0
PATCH 1/1 cmd: efidebug: fix a failure of "boot rm" sub-command
Quoted 23 lines · AKASHI Takahiro
There is a wrong usage of
utf8_utf16_strncpy()in "boot rm" command, and then it will end up with a failure of this command due to a wrong value of an interim variable ("var_name16").Signed-off-by AKASHI Takahiro <[email protected]>--- cmd/efidebug.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)cmd/efidebug.c +1
-1@@ -641,7 +641,7 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag,int id, i;char *endp;char var_name[9 ]; -u16 var_name16[9 ]; +u16 var_name16[9 ], *p;efi_status_t ret;if (argc ==1 )
cmd/efidebug.c static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag, · line 658
Quoted 6 lines
cmd/efidebug.c +2
-1@@ -654,7 +654,8 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag,return CMD_RET_FAILURE ;sprintf (var_name,"Boot%04X" , id); -utf8_utf16_strncpy ((u16 **)&var_name16, var_name,9 ); + p = var_name16; +utf8_utf16_strncpy (&p, var_name,9 );
This is duplicating code in do_efi_boot_add(). Please, consider putting the following codeblock into separate function:
??????? id = (int)simple_strtoul(argv[1], &endp, 16); ????????if (*endp != '\0' || id > 0xffff) ????????????????return CMD_RET_USAGE;
????????sprintf(var_name, "Boot%04X", id);
????????p = var_name16;
????????utf8_utf16_strncpy(&p, var_name, 9);
try_load_entry() has another implementation.
Best regards
Heinrich
Quoted 4 lines
cmd/efidebug.c +0
-0ret =EFI_CALL (RT ->set_variable (var_name16, &guid,0 ,0 ,NULL ));if (ret) {
PATCH 1/1 cmd: efidebug: fix a failure of "boot rm" sub-command
Quoted 26 lines · Heinrich Schuchardt
Quoted 25 lines · AKASHI Takahiro
There is a wrong usage of
utf8_utf16_strncpy()in "boot rm" command, and then it will end up with a failure of this command due to a wrong value of an interim variable ("var_name16").Signed-off-by AKASHI Takahiro <[email protected]>--- cmd/efidebug.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)cmd/efidebug.c +1
-1@@ -641,7 +641,7 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag,int id, i;char *endp;char var_name[9 ]; -u16 var_name16[9 ]; +u16 var_name16[9 ], *p;efi_status_t ret;if (argc ==1 )@@ -654,7 +654,8 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag,return CMD_RET_FAILURE ;
Quoted 7 lines
cmd/efidebug.c static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag, · line 658
Quoted 4 lines
cmd/efidebug.c +2
-1sprintf (var_name,"Boot%04X" , id); -utf8_utf16_strncpy ((u16 **)&var_name16, var_name,9 ); + p = var_name16; +utf8_utf16_strncpy (&p, var_name,9 );This is duplicating code in
do_efi_boot_add(). Please, consider putting the following codeblock into separate function:
No.
Quoted 7 lines
??????? id = (int)simple_strtoul(argv[1], &endp, 16); ????????if (*endp != '\0' || id >
0xffff) ????????????????returnCMD_RET_USAGE;????????sprintf(var_name, "Boot%04X", id);
????????p =var_name16;
????????utf8_utf16_strncpy(&p,var_name, 9);
Frankly, I don't like this function's prototype because it is different from "normal" corresponding C libraries.
Moreover, as far as I notice, there is no use case where the first parameter which is modified after calling is used in any code.
Thanks,
-Takahiro Akashi
Quoted 11 lines
try_load_entry()has another implementation.Best regards
Heinrich
Quoted 4 lines
cmd/efidebug.c +0
-0ret =EFI_CALL (RT ->set_variable (var_name16, &guid,0 ,0 ,NULL ));if (ret) {
PATCH 1/1 cmd: efidebug: fix a failure of "boot rm" sub-command
Quoted 35 lines · AKASHI Takahiro
Quoted 26 lines · Heinrich Schuchardt
Quoted 25 lines · AKASHI Takahiro
There is a wrong usage of
utf8_utf16_strncpy()in "boot rm" command, and then it will end up with a failure of this command due to a wrong value of an interim variable ("var_name16").Signed-off-by AKASHI Takahiro <[email protected]>--- cmd/efidebug.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)cmd/efidebug.c +1
-1@@ -641,7 +641,7 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag,int id, i;char *endp;char var_name[9 ]; -u16 var_name16[9 ]; +u16 var_name16[9 ], *p;efi_status_t ret;if (argc ==1 )@@ -654,7 +654,8 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag,return CMD_RET_FAILURE ;Quoted 7 lines
cmd/efidebug.c static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag, · line 658
Quoted 4 lines
cmd/efidebug.c +2
-1sprintf (var_name,"Boot%04X" , id); -utf8_utf16_strncpy ((u16 **)&var_name16, var_name,9 ); + p = var_name16; +utf8_utf16_strncpy (&p, var_name,9 );This is duplicating code in
do_efi_boot_add(). Please, consider putting the following codeblock into separate function:
Quoted 1 line
No.
Factoring out a separate function does not reduce the code size.
Hence
Quoted 28 lines
Quoted 8 lines
??????? id = (int)simple_strtoul(argv[1], &endp, 16); ????????if (*endp != '\0' || id >
0xffff) ????????????????returnCMD_RET_USAGE;????????sprintf(var_name, "Boot%04X", id);
????????p =var_name16;
????????utf8_utf16_strncpy(&p,var_name, 9);Frankly, I don't like this function's prototype because it is different from "normal" corresponding C libraries.
Moreover, as far as I notice, there is no use case where the first parameter which is modified after calling is used in any code.Thanks,
-Takahiro AkashiQuoted 11 lines
try_load_entry()has another implementation.Best regards
Heinrich
Quoted 4 lines
cmd/efidebug.c +0
-0ret =EFI_CALL (RT ->set_variable (var_name16, &guid,0 ,0 ,NULL ));if (ret) {