Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Dec 1998 19:48:06 +0100 (CET)
From:      cejkar@dcse.fee.vutbr.cz
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/9035: Bad __progname content in ELF programs
Message-ID:  <199812091848.TAA18006@kazi.dcse.fee.vutbr.cz>

next in thread | raw e-mail | index | archive | help

>Number:         9035
>Category:       bin
>Synopsis:       Bad __progname content in ELF programs
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec  9 10:50:00 PST 1998
>Last-Modified:
>Originator:     Rudolf Cejka
>Organization:
FEE TU Brno, Czech Republic
>Release:        FreeBSD 3.0-CURRENT i386
>Environment:

	ELFoized current -current :-) [YY-MM-DD: 98-12-09]

>Description:

	For aout programs, __progname variable contains only program name.
	For ELF programs, __progname variable contains program name
	with full path (i386 & alpha).

	(
	There must be something wrong. If this difference is right you must
	fix at least manpage for err*()/warn*() or err*()/warn*() itself:

	... In all cases, the last component of the program name,
	a colon character, and a space are output ...

	... Which for ELF programs at this time doen't apply.
	)

>How-To-Repeat:

	Simple program test.c:

		#include <stdio.h>
		extern char *__progname;
		int main(void)
		{
			printf("%s\n", __progname);
			return 0;
		}

	gives there results:

	# gcc -aout -o test test.c
	# ./././test
	test
	# gcc -elf -o test test.c
	# ./././test
	./././test
	
>Fix:
	
	Patch is taken from /usr/src/lib/csu/i386/crt0.c. It isn't tested
	so you must review my patch!

	patch /usr/src/lib/csu/i386-elf/crt1.c:
	(You need similar patch for /usr/src/lib/csu/alpha/crt1.c!)

--- crt1.c	Wed Sep  9 10:11:21 1998
+++ /tmp/crt1.c.new	Wed Dec  9 19:43:17 1998
@@ -72,8 +72,13 @@
     argc = * (int *) (argv - 1);
     env = argv + argc + 1;
     environ = env;
-    if(argc > 0)
+    if(argc > 0 && argv[0]) {
+	register char *s;
 	__progname = argv[0];
+	for (s = __progname; *s != '\0'; s++)
+		if (*s == '/')
+			__progname = s + 1;
+    }
 
     if(&_DYNAMIC != 0)
 	atexit(rtld_cleanup);

--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--
Rudolf Cejka  (cejkar@dcse.fee.vutbr.cz;  http://www.fee.vutbr.cz/~cejkar)
Technical University of Brno, Faculty of El. Engineering and Comp. Science
Bozetechova 2, 612 66  Brno, Czech Republic
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199812091848.TAA18006>