|
|
179894 |
commit e3217c7fd9e67aa2d53700bb1da9a966e73b9684
|
|
|
179894 |
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
|
|
|
179894 |
Date: Thu Jun 10 00:41:35 2021 +0530
|
|
|
179894 |
|
|
|
179894 |
iconv: Remove alloca use in gconv-modules configuration parsing
|
|
|
179894 |
|
|
|
179894 |
The alloca sizes ought to be constrained to PATH_MAX, but replace them
|
|
|
179894 |
with dynamic allocation to be safe. A static PATH_MAX array would
|
|
|
179894 |
have worked too but Hurd does not have PATH_MAX and the code path is
|
|
|
179894 |
not hot enough to micro-optimise this allocation. Revisit if any of
|
|
|
179894 |
those realities change.
|
|
|
179894 |
|
|
|
179894 |
Reviewed-by: DJ Delorie <dj@redhat.com>
|
|
|
179894 |
|
|
|
179894 |
diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c
|
|
|
179894 |
index 8eb981fca7cee36a..3099bf192adce711 100644
|
|
|
179894 |
--- a/iconv/gconv_conf.c
|
|
|
179894 |
+++ b/iconv/gconv_conf.c
|
|
|
179894 |
@@ -557,15 +557,15 @@ __gconv_read_conf (void)
|
|
|
179894 |
|
|
|
179894 |
for (cnt = 0; __gconv_path_elem[cnt].name != NULL; ++cnt)
|
|
|
179894 |
{
|
|
|
179894 |
-#define BUF_LEN elem_len + sizeof (gconv_conf_dirname)
|
|
|
179894 |
-
|
|
|
179894 |
const char *elem = __gconv_path_elem[cnt].name;
|
|
|
179894 |
size_t elem_len = __gconv_path_elem[cnt].len;
|
|
|
179894 |
- char *buf;
|
|
|
179894 |
|
|
|
179894 |
/* No slash needs to be inserted between elem and gconv_conf_filename;
|
|
|
179894 |
elem already ends in a slash. */
|
|
|
179894 |
- buf = alloca (BUF_LEN);
|
|
|
179894 |
+ char *buf = malloc (elem_len + sizeof (gconv_conf_dirname));
|
|
|
179894 |
+ if (buf == NULL)
|
|
|
179894 |
+ continue;
|
|
|
179894 |
+
|
|
|
179894 |
char *cp = __mempcpy (__mempcpy (buf, elem, elem_len),
|
|
|
179894 |
gconv_conf_filename, sizeof (gconv_conf_filename));
|
|
|
179894 |
|
|
|
179894 |
@@ -594,15 +594,16 @@ __gconv_read_conf (void)
|
|
|
179894 |
if (len > strlen (suffix)
|
|
|
179894 |
&& strcmp (ent->d_name + len - strlen (suffix), suffix) == 0)
|
|
|
179894 |
{
|
|
|
179894 |
- /* LEN <= PATH_MAX so this alloca is not unbounded. */
|
|
|
179894 |
- char *conf = alloca (BUF_LEN + len + 1);
|
|
|
179894 |
- cp = stpcpy (conf, buf);
|
|
|
179894 |
- sprintf (cp, "/%s", ent->d_name);
|
|
|
179894 |
+ char *conf;
|
|
|
179894 |
+ if (__asprintf (&conf, "%s/%s", buf, ent->d_name) < 0)
|
|
|
179894 |
+ continue;
|
|
|
179894 |
read_conf_file (conf, elem, elem_len, &modules, &nmodules);
|
|
|
179894 |
+ free (conf);
|
|
|
179894 |
}
|
|
|
179894 |
}
|
|
|
179894 |
__closedir (confdir);
|
|
|
179894 |
}
|
|
|
179894 |
+ free (buf);
|
|
|
179894 |
}
|
|
|
179894 |
#endif
|
|
|
179894 |
|
|
|
179894 |
diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c
|
|
|
179894 |
index fafc686ae25fb5c1..2f9d5f45ad3a8159 100644
|
|
|
179894 |
--- a/iconv/iconvconfig.c
|
|
|
179894 |
+++ b/iconv/iconvconfig.c
|
|
|
179894 |
@@ -712,7 +712,6 @@ handle_file (const char *dir, const char *infile)
|
|
|
179894 |
static int
|
|
|
179894 |
handle_dir (const char *dir)
|
|
|
179894 |
{
|
|
|
179894 |
-#define BUF_LEN prefix_len + dirlen + sizeof "gconv-modules.d"
|
|
|
179894 |
char *cp;
|
|
|
179894 |
size_t dirlen = strlen (dir);
|
|
|
179894 |
bool found = false;
|
|
|
179894 |
@@ -726,7 +725,10 @@ handle_dir (const char *dir)
|
|
|
179894 |
}
|
|
|
179894 |
|
|
|
179894 |
/* First, look for a gconv-modules file. */
|
|
|
179894 |
- char buf[BUF_LEN];
|
|
|
179894 |
+ char *buf = malloc (prefix_len + dirlen + sizeof "gconv-modules.d");
|
|
|
179894 |
+ if (buf == NULL)
|
|
|
179894 |
+ goto out;
|
|
|
179894 |
+
|
|
|
179894 |
cp = buf;
|
|
|
179894 |
if (dir[0] == '/')
|
|
|
179894 |
cp = mempcpy (cp, prefix, prefix_len);
|
|
|
179894 |
@@ -756,16 +758,19 @@ handle_dir (const char *dir)
|
|
|
179894 |
if (len > strlen (suffix)
|
|
|
179894 |
&& strcmp (ent->d_name + len - strlen (suffix), suffix) == 0)
|
|
|
179894 |
{
|
|
|
179894 |
- /* LEN <= PATH_MAX so this alloca is not unbounded. */
|
|
|
179894 |
- char *conf = alloca (BUF_LEN + len + 1);
|
|
|
179894 |
- cp = stpcpy (conf, buf);
|
|
|
179894 |
- sprintf (cp, "/%s", ent->d_name);
|
|
|
179894 |
+ char *conf;
|
|
|
179894 |
+ if (asprintf (&conf, "%s/%s", buf, ent->d_name) < 0)
|
|
|
179894 |
+ continue;
|
|
|
179894 |
found |= handle_file (dir, conf);
|
|
|
179894 |
+ free (conf);
|
|
|
179894 |
}
|
|
|
179894 |
}
|
|
|
179894 |
closedir (confdir);
|
|
|
179894 |
}
|
|
|
179894 |
|
|
|
179894 |
+ free (buf);
|
|
|
179894 |
+
|
|
|
179894 |
+out:
|
|
|
179894 |
if (!found)
|
|
|
179894 |
{
|
|
|
179894 |
error (0, errno, "failed to open gconv configuration files in `%s'",
|