From 638ec01fb9b267e6ab65e33552c178677f6258e9 Mon Sep 17 00:00:00 2001 From: Luo Ji Date: Thu, 25 Jan 2018 14:48:23 +0800 Subject: [PATCH] MA-11241 [Android] Use strlen() to calculate the string length Calculate the string length with strlen() instead of hard code. Change-Id: I6028c249ca03f5d3d08225c528d3584e507c64b3 Signed-off-by: Luo Ji --- drivers/usb/gadget/f_fastboot.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 9eb7fb646a..fa3d9cb47d 100755 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -2787,28 +2787,33 @@ static void cb_flashing(struct usb_ep *ep, struct usb_request *req) FASTBOOT_BOOTLOADER_VBOOT_KEY, strlen(FASTBOOT_BOOTLOADER_VBOOT_KEY))) { strcpy(response, "OKAY"); - } else if (!strncmp(cmd + len - 15, "unlock_critical", 15)) { + } else if (!strncmp(cmd + len - strlen("unlock_critical"), + "unlock_critical", strlen("unlock_critical"))) { #else - if (!strncmp(cmd + len - 15, "unlock_critical", 15)) { + if (!strncmp(cmd + len - strlen("unlock_critical"), + "unlock_critical", strlen("unlock_critical"))) { #endif strcpy(response, "OKAY"); - } else if (!strncmp(cmd + len - 13, "lock_critical", 13)) { + } else if (!strncmp(cmd + len - strlen("lock_critical"), + "lock_critical", strlen("lock_critical"))) { strcpy(response, "OKAY"); - } else if (!strncmp(cmd + len - 6, "unlock", 6)) { + } else if (!strncmp(cmd + len - strlen("unlock"), + "unlock", strlen("unlock"))) { printf("flashing unlock.\n"); status = do_fastboot_unlock(false); if (status != FASTBOOT_LOCK_ERROR) strcpy(response, "OKAY"); else strcpy(response, "FAIL unlock device failed."); - } else if (!strncmp(cmd + len - 4, "lock", 4)) { + } else if (!strncmp(cmd + len - strlen("lock"), "lock", strlen("lock"))) { printf("flashing lock.\n"); status = do_fastboot_lock(); if (status != FASTBOOT_LOCK_ERROR) strcpy(response, "OKAY"); else strcpy(response, "FAIL lock device failed."); - } else if (!strncmp(cmd + len - 18, "get_unlock_ability", 18)) { + } else if (!strncmp(cmd + len - strlen("get_unlock_ability"), + "get_unlock_ability", strlen("get_unlock_ability"))) { result = fastboot_lock_enable(); if (result == FASTBOOT_UL_ENABLE) { fastboot_tx_write_more("INFO1"); -- 2.17.1