[BusyBox] [PATCH] init.c include initial environment

Matt Kraai kraai at alumni.carnegiemellon.edu
Wed Feb 14 05:07:59 UTC 2001


On Tue, Feb 13, 2001 at 09:31:12PM +0100, Erik Gustavsson wrote:
> --- /tmp/busybox-0.49/init.c	Sat Jan 27 08:23:00 2001
> +++ init.c	Tue Feb 13 21:14:08 2001
> @@ -134,6 +134,8 @@
>  #define INIT_SCRIPT  "/etc/init.d/rcS"   /* Default sysinit script. */
>  #endif
>  
> +#define MAXENV       64              /* Number of env. vars */
> +
>  static const int LOG = 0x1;
>  static const int CONSOLE = 0x2;
>  
> @@ -396,7 +398,8 @@
>  
>  static pid_t run(char *command, char *terminal, int get_enter)
>  {
> -	int i, fd;
> +	int i=0, j=0;
> +	int fd;
>  	pid_t pid;
>  	char *tmpCmd;
>          char *cmd[255], *cmdpath;
> @@ -408,14 +411,18 @@
>  #endif
>  
>  		"\nPlease press Enter to activate this console. ";
> -	char *environment[] = {
> +	char *environment[MAXENV+1] = {
>  		"HOME=/",
>  		"PATH=/usr/bin:/bin:/usr/sbin:/sbin",
>  		"SHELL=/bin/sh",
> -		termType,
> -		"USER=root",
> -		0

Does the environment need to be NULL terminated?  If so, where did
it go?

> +		"USER=root"
>  	};
> +
> +	while(environment[i+1]) i++;
> +	while(environ[++j] && (i++ < MAXENV)) {
> +		environment[i]=malloc(strlen(environ[j])+1);
> +		strcpy(environment[i],environ[j]);

Use strncpy to ensure that you don't overflow the buffer.  Sure,
as others have noted you've already got root on the box anyway,
but it still is nice not to allow the user to trash memory.

> +	}
>  
>  	if ((pid = fork()) == 0) {
>  		/* Clean up */

Matt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20010213/2666b800/attachment.pgp 


More information about the busybox mailing list