|
|
2bfb24 |
commit a23820f6052a740246fdc7dcd9c43ce8eed0c45a
|
|
|
2bfb24 |
Author: Javier Pello <devel@otheo.eu>
|
|
|
2bfb24 |
Date: Mon Sep 5 20:09:01 2022 +0200
|
|
|
2bfb24 |
|
|
|
2bfb24 |
elf: Fix hwcaps string size overestimation
|
|
|
2bfb24 |
|
|
|
2bfb24 |
Commit dad90d528259b669342757c37dedefa8577e2636 added glibc-hwcaps
|
|
|
2bfb24 |
support for LD_LIBRARY_PATH and, for this, it adjusted the total
|
|
|
2bfb24 |
string size required in _dl_important_hwcaps. However, in doing so
|
|
|
2bfb24 |
it inadvertently altered the calculation of the size required for
|
|
|
2bfb24 |
the power set strings, as the computation of the power set string
|
|
|
2bfb24 |
size depended on the first value assigned to the total variable,
|
|
|
2bfb24 |
which is later shifted, resulting in overallocation of string
|
|
|
2bfb24 |
space. Fix this now by using a different variable to hold the
|
|
|
2bfb24 |
string size required for glibc-hwcaps.
|
|
|
2bfb24 |
|
|
|
2bfb24 |
Signed-off-by: Javier Pello <devel@otheo.eu>
|
|
|
2bfb24 |
|
|
|
2bfb24 |
diff --git a/elf/dl-hwcaps.c b/elf/dl-hwcaps.c
|
|
|
2bfb24 |
index 2fc4ae67a0f5d051..7ac27fd689187edc 100644
|
|
|
2bfb24 |
--- a/elf/dl-hwcaps.c
|
|
|
2bfb24 |
+++ b/elf/dl-hwcaps.c
|
|
|
2bfb24 |
@@ -193,7 +193,7 @@ _dl_important_hwcaps (const char *glibc_hwcaps_prepend,
|
|
|
2bfb24 |
/* Each hwcaps subdirectory has a GLIBC_HWCAPS_PREFIX string prefix
|
|
|
2bfb24 |
and a "/" suffix once stored in the result. */
|
|
|
2bfb24 |
hwcaps_counts.maximum_length += strlen (GLIBC_HWCAPS_PREFIX) + 1;
|
|
|
2bfb24 |
- size_t total = (hwcaps_counts.count * (strlen (GLIBC_HWCAPS_PREFIX) + 1)
|
|
|
2bfb24 |
+ size_t hwcaps_sz = (hwcaps_counts.count * (strlen (GLIBC_HWCAPS_PREFIX) + 1)
|
|
|
2bfb24 |
+ hwcaps_counts.total_length);
|
|
|
2bfb24 |
|
|
|
2bfb24 |
/* Count the number of bits set in the masked value. */
|
|
|
2bfb24 |
@@ -229,11 +229,12 @@ _dl_important_hwcaps (const char *glibc_hwcaps_prepend,
|
|
|
2bfb24 |
assert (m == cnt);
|
|
|
2bfb24 |
|
|
|
2bfb24 |
/* Determine the total size of all strings together. */
|
|
|
2bfb24 |
+ size_t total;
|
|
|
2bfb24 |
if (cnt == 1)
|
|
|
2bfb24 |
- total += temp[0].len + 1;
|
|
|
2bfb24 |
+ total = temp[0].len + 1;
|
|
|
2bfb24 |
else
|
|
|
2bfb24 |
{
|
|
|
2bfb24 |
- total += temp[0].len + temp[cnt - 1].len + 2;
|
|
|
2bfb24 |
+ total = temp[0].len + temp[cnt - 1].len + 2;
|
|
|
2bfb24 |
if (cnt > 2)
|
|
|
2bfb24 |
{
|
|
|
2bfb24 |
total <<= 1;
|
|
|
2bfb24 |
@@ -255,6 +256,7 @@ _dl_important_hwcaps (const char *glibc_hwcaps_prepend,
|
|
|
2bfb24 |
/* This is the overall result, including both glibc-hwcaps
|
|
|
2bfb24 |
subdirectories and the legacy hwcaps subdirectories using the
|
|
|
2bfb24 |
power set construction. */
|
|
|
2bfb24 |
+ total += hwcaps_sz;
|
|
|
2bfb24 |
struct r_strlenpair *overall_result
|
|
|
2bfb24 |
= malloc (*sz * sizeof (*result) + total);
|
|
|
2bfb24 |
if (overall_result == NULL)
|