diff options
author | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2021-09-13 20:48:35 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2021-09-13 20:48:35 +0530 |
commit | 43cea6d5652b6b9e61ac6ecc69419c909b504f47 (patch) | |
tree | 2c1b75d47a59bf6a789c6c83b0970b9fe439c136 /iconv/iconvconfig.c | |
parent | 526c3cf11ee9367344b6b15d669e4c3cb461a2be (diff) | |
download | glibc-43cea6d5652b6b9e61ac6ecc69419c909b504f47.tar.gz glibc-43cea6d5652b6b9e61ac6ecc69419c909b504f47.tar.xz glibc-43cea6d5652b6b9e61ac6ecc69419c909b504f47.zip |
iconvconfig: Fix behaviour with --prefix [BZ #28199]
The consolidation of configuration parsing broke behaviour with --prefix, where the prefix bled into the modules cache. Accept a prefix which, when non-NULL, is prepended to the path when looking for configuration files but only the original directory is added to the modules cache. This has no effect on the codegen of gconv_conf since it passes NULL. Reported-by: Patrick McCarty <patrick.mccarty@intel.com> Reported-by: Michael Hudson-Doyle <michael.hudson@canonical.com> Reviewed-by: Andreas Schwab <schwab@linux-m68k.org>
Diffstat (limited to 'iconv/iconvconfig.c')
-rw-r--r-- | iconv/iconvconfig.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c index fd61cf27fe..a89b62e784 100644 --- a/iconv/iconvconfig.c +++ b/iconv/iconvconfig.c @@ -652,13 +652,21 @@ add_module (char *rp, const char *directory, static int handle_dir (const char *dir) { + char *newp = NULL; size_t dirlen = strlen (dir); bool found = false; - char *fulldir = xasprintf ("%s%s%s", dir[0] == '/' ? prefix : "", - dir, dir[dirlen - 1] != '/' ? "/" : ""); + /* End directory path with a '/' if it doesn't already. */ + if (dir[dirlen - 1] != '/') + { + newp = xmalloc (dirlen + 2); + memcpy (newp, dir, dirlen); + newp[dirlen++] = '/'; + newp[dirlen] = '\0'; + dir = newp; + } - found = gconv_parseconfdir (fulldir, strlen (fulldir)); + found = gconv_parseconfdir (dir[0] == '/' ? prefix : NULL, dir, dirlen); if (!found) { @@ -670,7 +678,7 @@ handle_dir (const char *dir) "configuration files with names ending in .conf."); } - free (fulldir); + free (newp); return found ? 0 : 1; } |