From: Bruno Haible Date: Sat, 30 Sep 2023 13:08:26 +0000 (+0200) Subject: intl: Merge from glibc. X-Git-Tag: v0.23~360 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85dd7c1bab78062be836ddb901f599d298781f86;p=thirdparty%2Fgettext.git intl: Merge from glibc. Apply commits 2017-06-21 Florian Weimer DCIGETTEXT: Use getcwd, asprintf to construct absolute pathname and 2018-12-21 Florian Weimer intl: Do not return NULL on asprintf failure in gettext [BZ #24018] --- diff --git a/gettext-runtime/intl/dcigettext.c b/gettext-runtime/intl/dcigettext.c index c59c88a57..9a6ae7b16 100644 --- a/gettext-runtime/intl/dcigettext.c +++ b/gettext-runtime/intl/dcigettext.c @@ -59,6 +59,7 @@ extern int errno; #include #include +#include #include #if defined HAVE_UNISTD_H || defined _LIBC @@ -463,6 +464,7 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, const char *categoryname; const char *categoryvalue; const char *dirname; + char *xdirname = NULL; #if defined _WIN32 && !defined __CYGWIN__ const wchar_t *wdirname; #endif @@ -666,35 +668,17 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, if (IS_RELATIVE_FILE_NAME (dirname)) { /* We have a relative path. Make it absolute now. */ - size_t dirname_len = strlen (dirname) + 1; - size_t path_max; - char *resolved_dirname; - char *ret; - - path_max = (unsigned int) PATH_MAX; - path_max += 2; /* The getcwd docs say to do this. */ - - for (;;) - { - resolved_dirname = (char *) alloca (path_max + dirname_len); - ADD_BLOCK (block_list, resolved_dirname); - - __set_errno (0); - ret = getcwd (resolved_dirname, path_max); - if (ret != NULL || errno != ERANGE) - break; - - path_max += path_max / 2; - path_max += PATH_INCR; - } - - if (ret == NULL) - /* We cannot get the current working directory. Don't signal an - error but simply return the default string. */ + char *cwd = getcwd (NULL, 0); + if (cwd == NULL) + /* We cannot get the current working directory. Don't + signal an error but simply return the default + string. */ goto return_untranslated; - - stpcpy (stpcpy (strchr (resolved_dirname, '\0'), "/"), dirname); - dirname = resolved_dirname; + int ret = __asprintf (&xdirname, "%s/%s", cwd, dirname); + free (cwd); + if (ret < 0) + goto return_untranslated; + dirname = xdirname; } #endif #ifndef IN_LIBGLOCALE @@ -815,6 +799,7 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, { /* Found the translation of MSGID1 in domain DOMAIN: starting at RETVAL, RETLEN bytes. */ + free (xdirname); FREE_BLOCKS (block_list); if (foundp == NULL) { @@ -898,6 +883,7 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, return_untranslated: /* Return the untranslated MSGID. */ + free (xdirname); FREE_BLOCKS (block_list); gl_rwlock_unlock (_nl_state_lock); #ifdef _LIBC