Without that fix command can be NULL when it reaches this assert:
    assert(command->options & OPTION_FILE);

The crash can be reproduced by running nv_data-imei with command
options but without the command itself, for example with
'nv_data-imei -i 1'.

Signed-off-by: Denis 'GNUtoo' Carikli <gnu...@cyberdimension.org>
---
 tools/nv_data-imei.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/nv_data-imei.c b/tools/nv_data-imei.c
index 766c7a8..64ce3f5 100644
--- a/tools/nv_data-imei.c
+++ b/tools/nv_data-imei.c
@@ -1021,11 +1021,12 @@ int main(int argc, char * const argv[])
        /* We use the - in optstring so all arguments go in the 'case 1:' */
        assert(optind == argc);
 
-       if (argc == 2) {
+       if (argc == 2 || command == NULL) {
                /* If none of the commands or options were reached, we are in
-                * the case where users ran 'nv_data-imei FILE'.
+                * the case where users ran 'nv_data-imei FILE' or used some
+                * options like -i <argument> without any command.
                 */
-               printf("Missing options, commands or invalid command '%s'\n",
+               printf("Missing options, command or invalid command '%s'\n",
                       argv[1]);
                printf("Try -h to print the help.\n");
                return EX_USAGE;
-- 
2.30.1

_______________________________________________
Replicant mailing list
Replicant@osuosl.org
https://lists.osuosl.org/mailman/listinfo/replicant

Reply via email to