From: Jan Kiszka <[email protected]>

strncmp(A, B, strlen(B) + 1) == strcmp(A, B)

Signed-off-by: Jan Kiszka <[email protected]>
---
 env/env_api_fat.c             | 13 ++++++-------
 env/uservars.c                |  2 +-
 tools/bg_setenv.c             |  2 +-
 tools/tests/test_ebgenv_api.c |  6 ++----
 4 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/env/env_api_fat.c b/env/env_api_fat.c
index 130c161..a4d8393 100644
--- a/env/env_api_fat.c
+++ b/env/env_api_fat.c
@@ -24,23 +24,22 @@ bool bgenv_verbosity = false;
 
 EBGENVKEY bgenv_str2enum(char *key)
 {
-       if (strncmp(key, "kernelfile", strlen("kernelfile") + 1) == 0) {
+       if (strcmp(key, "kernelfile") == 0) {
                return EBGENV_KERNELFILE;
        }
-       if (strncmp(key, "kernelparams", strlen("kernelparams") + 1) == 0) {
+       if (strcmp(key, "kernelparams") == 0) {
                return EBGENV_KERNELPARAMS;
        }
-       if (strncmp(key, "watchdog_timeout_sec",
-                   strlen("watchdog_timeout_sec") + 1) == 0) {
+       if (strcmp(key, "watchdog_timeout_sec") == 0) {
                return EBGENV_WATCHDOG_TIMEOUT_SEC;
        }
-       if (strncmp(key, "revision", strlen("revision") + 1) == 0) {
+       if (strcmp(key, "revision") == 0) {
                return EBGENV_REVISION;
        }
-       if (strncmp(key, "ustate", strlen("ustate") + 1) == 0) {
+       if (strcmp(key, "ustate") == 0) {
                return EBGENV_USTATE;
        }
-       if (strncmp(key, "in_progress", strlen("in_progress") + 1) == 0) {
+       if (strcmp(key, "in_progress") == 0) {
                return EBGENV_IN_PROGRESS;
        }
        return EBGENV_UNKNOWN;
diff --git a/env/uservars.c b/env/uservars.c
index daa757d..f251f24 100644
--- a/env/uservars.c
+++ b/env/uservars.c
@@ -167,7 +167,7 @@ uint8_t *bgenv_find_uservar(uint8_t *udata, char *key)
        while (*udata) {
                bgenv_map_uservar(udata, &varkey, NULL, NULL, NULL, NULL);
 
-               if (strncmp(varkey, key, strlen(key) + 1) == 0) {
+               if (strcmp(varkey, key) == 0) {
                        return udata;
                }
                udata = bgenv_next_uservar(udata);
diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
index c789fcc..ee0e587 100644
--- a/tools/bg_setenv.c
+++ b/tools/bg_setenv.c
@@ -122,7 +122,7 @@ static void journal_process_action(BGENV *env, struct 
env_action *action)
                VERBOSE(stdout, "Task = SET, key = %s, type = %llu, val = %s\n",
                        action->key, (long long unsigned int)action->type,
                        (char *)action->data);
-               if (strncmp(action->key, "ustate", strlen("ustate")+1) == 0) {
+               if (strcmp(action->key, "ustate") == 0) {
                        uint16_t ustate;
                        unsigned long t;
                        char *arg;
diff --git a/tools/tests/test_ebgenv_api.c b/tools/tests/test_ebgenv_api.c
index ea4523f..740211a 100644
--- a/tools/tests/test_ebgenv_api.c
+++ b/tools/tests/test_ebgenv_api.c
@@ -134,11 +134,9 @@ START_TEST(ebgenv_api_ebg_env_create_new)
        ck_assert_int_eq(((BGENV *)e.bgenv)->data->ustate, USTATE_OK);
        ck_assert_int_eq(((BGENV *)e.bgenv)->data->watchdog_timeout_sec, 44);
        (void)str16to8(buffer, ((BGENV *)e.bgenv)->data->kernelfile);
-       ck_assert_int_eq(
-               strncmp(buffer, kernelfile, strlen(kernelfile) + 1), 0);
+       ck_assert_int_eq(strcmp(buffer, kernelfile), 0);
        (void)str16to8(buffer, ((BGENV *)e.bgenv)->data->kernelparams);
-       ck_assert_int_eq(
-               strncmp(buffer, kernelparams, strlen(kernelparams) + 1), 0);
+       ck_assert_int_eq(strcmp(buffer, kernelparams), 0);
 
        (void)ebg_env_close(&e);
 
-- 
2.34.1

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/5545c572-29c7-7129-78c6-3dd73cd32ce3%40siemens.com.

Reply via email to