diff options
| author | Rasmus Villemoes <[email protected]> | 2026-04-21 09:54:36 +0200 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-05-12 15:38:00 -0600 |
| commit | b87ff4878d081103c45f0ebea7528609a0b173f3 (patch) | |
| tree | 327e2b5df884d5aeda5f56da07b5716a2dd738da /lib | |
| parent | ee8be5d4a1035de232b3497563fe9f6773775f96 (diff) | |
lib/hashtable.c: use memdup_nul() in himport_r
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 <[email protected]>
Signed-off-by: Rasmus Villemoes <[email protected]>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/hashtable.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/hashtable.c b/lib/hashtable.c index 75c263b5053..f96a8e686f6 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -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 */ |
