]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
ext_password_file: Ensure full key match with password file entries
authorJoshua Manchester <joshuamanchester4@gmail.com>
Tue, 21 Jan 2025 19:38:47 +0000 (19:38 +0000)
committerJouni Malinen <j@w1.fi>
Sun, 26 Jan 2025 07:16:03 +0000 (09:16 +0200)
When searching for a matching key in the external password file, strings
were only compared up to the length of the key in the file. This meant
searching for key "foo" could retrieve the incorrect password if keys
"f" or "fo" were defined earlier in the file.

Signed-off-by: Joshua Manchester <joshuamanchester4@gmail.com>
src/utils/ext_password_file.c

index 312251263ad1ec2c281c2c9d16a9413624bdaea0..158500ced2050552e7b38f6ed5a49939eb0de600 100644 (file)
@@ -83,6 +83,7 @@ static struct wpabuf * ext_password_file_get(void *ctx, const char *name)
        struct ext_password_file_data *data = ctx;
        struct wpabuf *password = NULL;
        char buf[512], *pos;
+       size_t name_len;
        int line = 0;
        FILE *f;
 
@@ -94,6 +95,8 @@ static struct wpabuf * ext_password_file_get(void *ctx, const char *name)
                return NULL;
        }
 
+       name_len = os_strlen(name);
+
        wpa_printf(MSG_DEBUG, "EXT PW FILE: get(%s)", name);
 
        while ((pos = fgets(buf, sizeof(buf), f))) {
@@ -121,7 +124,8 @@ static struct wpabuf * ext_password_file_get(void *ctx, const char *name)
 
                }
 
-               if (os_strncmp(name, pos, sep - pos) != 0)
+               if (name_len != (size_t) (sep - pos) ||
+                   os_strncmp(name, pos, sep - pos) != 0)
                        continue;
 
                password = wpabuf_alloc_copy(sep + 1, os_strlen(sep + 1));