From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Thu, 20 Nov 2003 17:31:42 +0000 Subject: Re: [udev] support arguments in callout exec MIME-Version: 1 Content-Type: multipart/mixed; boundary="G4iJoqBmSsgzjUCe" Message-Id: List-Id: References: In-Reply-To: To: linux-hotplug@vger.kernel.org --G4iJoqBmSsgzjUCe Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 20, 2003 at 03:59:31AM +0100, Arnd Bergmann wrote: > On Thursday 20 November 2003 17:07, Kay Sievers wrote: > > On Thu, Nov 20, 2003 at 01:47:36AM +0100, Arnd Bergmann wrote: > > > This still doesn't look correct: args[i] will be out of bounds > > > when the loop has finished on CALLOUT_MAXARG, and the args > > > array is not zero terminated when calling execve. > > > > Good catch, but arg is not NULL if MAXARG is reached - so args is sti= ll > > not terminated :) >=20 > > +=A0=A0=A0=A0=A0=A0=A0char *args[CALLOUT_MAXARG]; > > +=A0=A0=A0=A0=A0=A0=A0int i; > ... > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= for (i=3D0; i < CALLOUT_MAXARG; i++) { > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0args[i] =3D strsep(&arg, " "); > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0if (args[i] =3D=3D NULL) > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0break; > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= } > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= if (args[i]) { > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0dbg("to many args"); > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0args[i] =3D NULL; > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= } >=20 > Ok, it's terminated now, but again out of bounds. It should be > char *args[CALLOUT_MAXARG+1]; > in the beginning or only loop to (CALLOUT_MAXARG - 1). Oh, oh, oh... I hope, I don't send more patches than the number of lines added to the c= ode. Here is #5 :) thanks, Kay --G4iJoqBmSsgzjUCe Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="09-namedev.c-callout-argument-support.diff" --- ../udev/namedev.c 2003-11-19 12:56:50.000000000 +0100 +++ namedev.c 2003-11-20 18:29:42.000000000 +0100 @@ -45,6 +45,7 @@ #define TYPE_TOPOLOGY "TOPOLOGY" #define TYPE_REPLACE "REPLACE" #define TYPE_CALLOUT "CALLOUT" +#define CALLOUT_MAXARG 8 static LIST_HEAD(config_device_list); @@ -480,6 +481,9 @@ pid_t pid; int value_set = 0; char buffer[256]; + char *arg; + char *args[CALLOUT_MAXARG]; + int i; dbg("callout to %s\n", dev->exec_program); retval = pipe(fds); @@ -499,7 +503,22 @@ */ close(STDOUT_FILENO); dup(fds[1]); /* dup write side of pipe to STDOUT */ - retval = execve(dev->exec_program, main_argv, main_envp); + if (strchr(dev->exec_program, ' ')) { + /* callout with arguments */ + arg = dev->exec_program; + for (i=0; i < CALLOUT_MAXARG-1; i++) { + args[i] = strsep(&arg, " "); + if (args[i] == NULL) + break; + } + if (args[i]) { + dbg("to many args - %d", i); + args[i] = NULL; + } + retval = execve(args[0], args, main_envp); + } else { + retval = execve(dev->exec_program, main_argv, main_envp); + } if (retval != 0) { dbg("child execve failed"); exit(1); @@ -528,6 +547,7 @@ strncpy(value, buffer, len); } } + dbg("callout returned '%s'", value); close(fds[0]); res = wait(&status); if (res < 0) { --G4iJoqBmSsgzjUCe-- ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel