[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: XTerm verschluckt die Env.-Variable TMPDIR



Michelle Konzack <linux4michelle@freenet.de> writes:

>Am 2006-03-23 16:31:29, schrieb Friedhelm Usenet Waitzmann:
>
>> Bekannt. Xterm in sarge verschluckt die Environmentvariable
>
>Bekannt?  -  Also ich bin gerade noch mal das BTS von xfree86
>durchgegangen und habe in den tausenden messages nichts gefunden...
>
>Wo haste das gelesen?

Der Fehler ist alt und bestand schon in Woody:  Fehlerbericht Nr. 276417
im Debian Bug Tracking System.  Erinnerst Du Dich?

Ich habe damals nach Branden Robinsons Aussage »xterm contains no logic
for scrubbing the environment.« aus Zeitgründen klein beigegeben.

Der Testfall, der den Fehler beschreibt -- 

   $ env TMPDIR=/tmp xterm -hold -e printenv TMPDIR

einerseits und

   $ env DUMMY=/tmp xterm -hold -e printenv DUMMY

andererseits -- lässt keinen Zweifel daran, dass xterm hier TMPDIR
verschluckt.

Vielleicht kann man jetzt einen neuen Anlauf nehmen?

Also, los geht's:

»execargs«

/*
  execargs.c - execute arguments via execvp() resp. execv()
  2006-04-06T00:56:42+0200
*/

#define _POSIX_SOURCE 1
#define _POSIX_C_SOURCE 199506L
#define _XOPEN_VERSION 4

#include <errno.h> /* errno, EINVAL, ENOENT, NOEXEC, EACCES */
#include <stddef.h> /* NULL, size_t */
#include <stdio.h> /* fprintf(), stderr */
#include <stdlib.h> /* EXIT_... */
#include <string.h> /* strerror() */
#include <unistd.h> /* exec...() */

static const char * invocation_name="execargs";

int
main(int argc, char **argv)
{
	if(argc > 0 && argv[0] != NULL)
		{
			/* an invocation name is supplied by the OS resp. run time
			 * environment
			 */
	 
			/* strip all leading path components from argv[0], if there are any:
			 */
			invocation_name = strrchr(argv[0], '/');
			/* invocation_name points to last ocurrence of '/' in
			 * argv[0] if there is one, otherwise invocation_name is
			 * NULL
			 */
			if(invocation_name == NULL)
				/* there aren't any '/' characters in argv[0]: nothing to
				 * do, just use argv[0] as invocation_name.
				 */
				invocation_name = argv[0];
			else
				/* we have found a last '/' character: invocation_name now
				 * points to it.
				 *
				 * let invocation_name begin after last '/' character:
				 */
				invocation_name += 1;
		}

	/* process option arguments:
	 */
		
	if (argc >= 2 && argv[1] != NULL)
		/* At least the name of the program to be executed is given.
		 */
		{
			/* argv[1] is the name of the program to be executed,
				argv+2 is its argument vector:
			*/
			execvp(argv[1], argv+2);
			/* if returning from exec...(), an error has occurred:
			 */
			{
				int saved_errno=errno;
				{
					const char * error_text=strerror(errno);

					fprintf(stderr,
						"%s:\ncannot execute %s%s%s\n",
						invocation_name,
						argv[1],
						(error_text != NULL) ? ":\n" : ".",
						(error_text != NULL) ? error_text : ""
					);
				}
				switch(saved_errno)
					{
#ifdef ENOENT
					case ENOENT:
#endif
						return 127;
						break;
#ifdef EACCES
					case EACCES:
#endif
#ifdef EPERM
					case EPERM:
#endif
#ifdef ENOEXEC
					case ENOEXEC:
#endif
#ifdef ENOTDIR
					case ENOTDIR:
#endif
#ifdef EINVAL
					case EINVAL:
#endif
#ifdef EISDIR
					case EISDIR:
#endif
#ifdef ELIBBAD
					case ELIBBAD:
#endif
						return 126;
						break;
					default:
						break;
					}
			}
		}
	else
		{
			fprintf(stderr,
				"%s: At least one argument (command) is required.\n"
				"Syntax:\n"
				"%s command [argv0 [argv1 [ ... [argvn]]]]\n",
				invocation_name, invocation_name
			);
		}
	return 125;
} /* main() */
ist ein Programm, das mit seinen Parametern argv[1] argv[2] ... die
Funktion execvp(argv[1], { argv[2], argv[3], ...}) aufruft.

$ TMPDIR=/tmp execargs printenv printenv TMPDIR; printf 'Exit Code: %s\n' "$?"
/tmp
Exit Code: 0

Setze ich jetzt bei »execargs« das Setuid- oder Setgid-Flag auf eine
Benutzer- oder Gruppenkennung, die sich von meiner unterscheidet, erhalte
ich folgende Ausgabe:

$ TMPDIR=/tmp execargs printenv printenv TMPDIR; printf 'Exit Code: %s\n' "$?"
Exit Code: 1

Das scheint also eine Eigenschaft der Laufzeitumgebung zu sein.  »xterm«
tut es also nicht explizit.
-- 
Wenn Sie mir E-Mail schreiben, stellen |  When writing me e-mail, please
Sie bitte vor meine E-Mail-Adresse     |  precede my e-mail address with
meinen Vor- und Nachnamen, etwa so:    |  my full name, like
Helmut Waitzmann <xxx@example.net>, (Helmut Waitzmann) xxx@example.net

Reply to: