]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
lib/hashtable.c: use memdup_nul() in himport_r
authorRasmus Villemoes <ravi@prevas.dk>
Tue, 21 Apr 2026 07:54:36 +0000 (09:54 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 12 May 2026 21:38:00 +0000 (15:38 -0600)
We have memdup_nul() for exactly this pattern of duplicating a block
of memory and ensuring there's a nul byte after the copy.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
lib/hashtable.c

index 75c263b5053f32947185846f7bcdc5181687736d..f96a8e686f65e839e1b090acfec342695d486d66 100644 (file)
@@ -821,13 +821,12 @@ int himport_r(struct hsearch_data *htab,
        }
 
        /* we allocate new space to make sure we can write to the array */
-       if ((data = malloc(size + 1)) == NULL) {
-               debug("himport_r: can't malloc %lu bytes\n", (ulong)size + 1);
+       data = memdup_nul(env, size);
+       if (data == NULL) {
+               debug("himport_r: can't duplicate env block\n");
                __set_errno(ENOMEM);
                return 0;
        }
-       memcpy(data, env, size);
-       data[size] = '\0';
        dp = data;
 
        /* make a local copy of the list of variables */