lib/string: Fix getenv name matching

Without confirming that the name length exactly matches too, then
the string comparison would return the same value for VAR* as for
VAR, when VAR came first in the environ array.

Signed-off-by: Andrew Jones <drjones@redhat.com>
Message-Id: <20201014191444.136782-2-drjones@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/lib/string.c b/lib/string.c
index 018dcc8..75257f5 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -171,10 +171,13 @@
 char *getenv(const char *name)
 {
     char **envp = environ, *delim;
+    int len;
 
     while (*envp) {
         delim = strchr(*envp, '=');
-        if (delim && strncmp(name, *envp, delim - *envp) == 0)
+        assert(delim);
+        len = delim - *envp;
+        if (memcmp(name, *envp, len) == 0 && !name[len])
             return delim + 1;
         ++envp;
     }