[Replicant] [libsamsung-ipc][PATCH 09/10] tools: nv_data-imei: fix crash with commands options without command

Denis 'GNUtoo' Carikli GNUtoo at cyberdimension.org
Sat Feb 13 13:17:48 UTC 2021


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 <GNUtoo at 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



More information about the Replicant mailing list