Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: Register pointers in gcc?

From: Warner Losh <imp(at)village.org>
Date: Sun Feb 16 1997 - 13:38:48 EST

In message <Pine.BSF.3.95.970216130504.25797F-100000@alpha.risc.org> Brian Tao writes:

:     I was looking at the disklabel(8) source today and found this in
: editit():
:                 if ((ed = getenv("EDITOR")) == (char *)0)
:                         ed = DEFEDITOR;
:     How come I can stuff anything into EDITOR and not cause disklabel
: to segfault?  I've setenv EDITOR to 16K strings and it just complains
: that the argument list is too long, or that the editor does not exist.
: Where is it storing the contents of getenv("EDITOR")?

getenv is stored in the environment space of the process, so it grows and shrinks dynamically. Since there are no strcpy's here, it works. I'm a little surprised that the kernel doesn't barf on the string being >> MAXPATHLEN, but that's a whole other set of bugs that I don't think have been well looked for, even in OpenBSD: Passing args to the kernel that are too big. I think that this turns into a NDINIT call in the kernel, but haven't traced it past that point yet.

BTW, OpenBSD integrated some changes, appended below with change info, to disklabel that are likely desirable. There were some problems with signals that you might want to look into.

Warner

revision 1.27
date: 1997/02/16 07:42:52; author: deraadt; state: Exp; lines: +12 -14 when spawning editor child, use signal() instead of sigprocmask(SIG_BLOCK... this appears to prevent the intermediate shell from playing with the signals such that it gets a tty signal inside an editor such as emacs. this was very annoying

Index: disklabel.c



RCS file: /home/imp/OpenBSD/CVS/src/sbin/disklabel/disklabel.c,v retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- disklabel.c	1996/12/13 16:58:25	1.26
+++ disklabel.c	1997/02/16 07:42:52	1.27

@@ -1,4 +1,4 @@
-/* $OpenBSD: disklabel.c,v 1.25 1996/12/07 10:09:24 deraadt Exp $ */ +/* $OpenBSD: disklabel.c,v 1.26 1996/12/13 16:58:25 millert Exp $ */ /* $NetBSD: disklabel.c,v 1.30 1996/03/14 19:49:24 ghudson Exp $ */

 /*
@@ -44,7 +44,7 @@

 #endif /* not lint */  

Do you need help?X

 #ifndef lint
-static char rcsid[] = "$OpenBSD: disklabel.c,v 1.25 1996/12/07 10:09:24 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: disklabel.c,v 1.26 1996/12/13 16:58:25 millert Exp $";  #endif /* not lint */  

 #include <sys/param.h>
@@ -960,7 +960,6 @@

 	int pid, xpid;
 	int stat;
 	extern char *getenv();
-	sigset_t sigset, osigset;
 	char *argp[] = {"sh", "-c", NULL, NULL};
 	char *ed, *p;
 

@@ -974,24 +973,20 @@
sprintf(p, "%s %s", ed, tmpfil); argp[2] = p; - sigemptyset(&sigset); - sigaddset(&sigset, SIGINT); - sigaddset(&sigset, SIGQUIT); - sigaddset(&sigset, SIGHUP); - sigprocmask(SIG_BLOCK, &sigset, &osigset); + /* Turn off signals. */ + (void)signal(SIGHUP, SIG_IGN); + (void)signal(SIGINT, SIG_IGN); + (void)signal(SIGQUIT, SIG_IGN); while ((pid = fork()) < 0) { if (errno != EAGAIN) { - sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); warn("fork"); free(p); - return (0); + stat = 1; + goto bail; } sleep(1); } if (pid == 0) { - sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); - setgid(getgid()); - setuid(getuid()); execv(_PATH_BSHELL, argp); _exit(127); }
@@ -1003,7 +998,10 @@
else if (WIFEXITED(stat)) break; } - sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); +bail: + (void)signal(SIGHUP, SIG_DFL);
Do you need more help?X
+ (void)signal(SIGINT, SIG_DFL); + (void)signal(SIGQUIT, SIG_DFL); return (!stat);

 }   Received on Sun Feb 16 10:38:59 1997

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 12:41:02 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library