[prev in list] [next in list] [prev in thread] [next in thread] 

List:       netsaintplug-devel
Subject:    [Netsaintplug-devel] Exporting environment in spopen()
From:       Martin Mares <mj () ucw ! cz>
Date:       2001-08-24 16:44:44
[Download RAW message or body]

Hello, world!\n

I've wondered why check_hpjd displays localized printer messages (iso-8859-2
strings) as hexadecimal strings while snmpget run from shell shows them
as normal strings. I've traced the problem down to LC_CTYPE set correctly
in the shell, but stripped away by spopen().

A comment in popen.c suggests that this is done due to some security issues,
but myself I don't realize any such risks as the only things we are going
to execute are commands specified in the configuration file.

I've modified spopen() to export the whole environment (patch below), if you
think it's dangerous, I'll modify it to filter the environment list to include
only things which are known to be safe, but now I see no reasons for complicating
the code.

				Have a nice fortnight
-- 
Martin `MJ' Mares   <mj@ucw.cz>   http://atrey.karlin.mff.cuni.cz/~mj/
Faculty of Math and Physics, Charles University, Prague, Czech Rep., Earth
"I don't give a damn for a man that can only spell a word one way." -- M. Twain


diff -u -r1.13 popen.c
--- popen.c	2001/07/25 12:31:07	1.13
+++ popen.c	2001/08/24 16:40:34
@@ -12,9 +12,8 @@
  * Code taken with liitle modification from "Advanced Programming for the Unix
  * Environment" by W. Richard Stevens
  *
- * This is considered safe in that no shell is spawned, and the environment and
- * path passed to the exec'd program are esstially empty. (popen create a shell
- * and passes the environment to it).
+ * As opposed to popen(), we don't create a shell, but we still pass the
+ * full environment of the parent process.
  *
  ******************************************************************************/
 
@@ -67,10 +66,9 @@
 FILE *
 spopen (const char *cmdstring)
 {
-	char *environ[] = { NULL };
 	char *cmd = NULL;
 	char **argv = NULL;
-	char *str;
+	char *str, **envr, **envw;
 	int argc;
 
 	int i = 0, pfd[2], pfderr[2];
@@ -182,7 +180,7 @@
 			if (childpid[i] > 0)
 				close (i);
 
-		execve (argv[0], argv, environ);
+		execv (argv[0], argv);
 		_exit (0);
 	}
 

_______________________________________________
Netsaintplug-devel mailing list
Netsaintplug-devel@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/netsaintplug-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic