From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11754 Path: news.gmane.org!.POSTED!not-for-mail From: Alexander Monakov Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] __init_libc: add fallbacks for __progname setup Date: Fri, 28 Jul 2017 17:46:49 +0300 Message-ID: <20170728144649.3440-1-amonakov@ispras.ru> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1501253223 31721 195.159.176.226 (28 Jul 2017 14:47:03 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 28 Jul 2017 14:47:03 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-11767-gllmg-musl=m.gmane.org@lists.openwall.com Fri Jul 28 16:47:00 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1db6Xa-0007yL-N1 for gllmg-musl@m.gmane.org; Fri, 28 Jul 2017 16:46:58 +0200 Original-Received: (qmail 29853 invoked by uid 550); 28 Jul 2017 14:47:02 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 29809 invoked from network); 28 Jul 2017 14:47:01 -0000 X-Mailer: git-send-email 2.11.0 Xref: news.gmane.org gmane.linux.lib.musl.general:11754 Archived-At: It is possible for argv[0] to be a null pointer, but the __progname variable is used to implement functions in src/legacy/err.c that do not expect it to be null. It is also available to the user via the program_invocation_name alias as a GNU extension, and the implementation in Glibc initializes it to a pointer to empty string rather than NULL. Since argv[0] is usually non-null and it's preferable to keep those variables in BSS, implement the fallbacks in __init_libc, which also allows to have an intermediate fallback to AT_EXECFN. --- src/env/__libc_start_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c index 5c79be28..18afdc1d 100644 --- a/src/env/__libc_start_main.c +++ b/src/env/__libc_start_main.c @@ -30,10 +30,10 @@ void __init_libc(char **envp, char *pn) __sysinfo = aux[AT_SYSINFO]; libc.page_size = aux[AT_PAGESZ]; - if (pn) { - __progname = __progname_full = pn; - for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1; - } + if (!pn) pn = (void*)aux[AT_EXECFN]; + if (!pn) pn = ""; + __progname = __progname_full = pn; + for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1; __init_tls(aux); __init_ssp((void *)aux[AT_RANDOM]); -- 2.11.0