From patchwork Mon Jun 19 16:17:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 21097 Received: (qmail 74136 invoked by alias); 19 Jun 2017 16:17:46 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 74055 invoked by uid 89); 19 Jun 2017 16:17:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=8357 X-HELO: mx1.redhat.com DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 00B5180C2D Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fweimer@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 00B5180C2D Date: Mon, 19 Jun 2017 18:17:46 +0200 To: libc-alpha@sourceware.org Subject: [PATCH] DCIGETTEXT: Use getcwd, asprintf to construct absolute pathname User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20170619161746.3B667402AEC0E@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) 2017-06-19 Florian Weimer * intl/dcigettext.c (DCIGETTEXT): Use getcwd (NULL, 0) and asprintf to construct an absolute pathname. diff --git a/intl/dcigettext.c b/intl/dcigettext.c index 49127d0..0e79b1f 100644 --- a/intl/dcigettext.c +++ b/intl/dcigettext.c @@ -59,6 +59,7 @@ extern int errno; #include #include +#include #include #if defined HAVE_UNISTD_H || defined _LIBC @@ -495,6 +496,7 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, const char *categoryname; const char *categoryvalue; const char *dirname; + char *xdirname = NULL; char *xdomainname; char *single_locale; char *retval; @@ -624,35 +626,17 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, if (!IS_ABSOLUTE_PATH (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, tmp_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) + return NULL; + dirname = xdirname; } #ifndef IN_LIBGLOCALE } @@ -767,6 +751,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) { @@ -850,6 +835,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