From 43cea6d5652b6b9e61ac6ecc69419c909b504f47 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Mon, 13 Sep 2021 20:48:35 +0530 Subject: 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 Reported-by: Michael Hudson-Doyle Reviewed-by: Andreas Schwab --- iconv/iconvconfig.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'iconv/iconvconfig.c') 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; } -- cgit 1.4.1