linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix off-by-one in pass_env_to_socket()
@ 2008-09-08 13:17 Alan Jenkins
  2008-09-08 22:40 ` Kay Sievers
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Jenkins @ 2008-09-08 13:17 UTC (permalink / raw)
  To: linux-hotplug

This only manifests in exceptional circumstances when the variables exceed
the buffer size.  It can be reproduced as follows:

[kill existing udevd and udevadm]

valgrind -q ./udevd & sleep 1

LONG=`dd if=/dev/zero bs=1 countP0 | tr '\0' 'A'` # 500 character string
for VAR in a b c d; do
	./udevadm control --env $VAR=$LONG
done

./udevadm monitor -e > /dev/null &
./udevadm trigger

[wait a few seconds]

=17942= Syscall param socketcall.sendto(msg) points to uninitialised byte(s)
=17942=    at 0x511BBC3: __sendto_nocancel (in /usr/lib/debug/libc-2.7.so)
=17942=    by 0x407B72: pass_env_to_socket (udev_rules.c:500)
=17942=    by 0x407C7F: udev_rules_run (udev_rules.c:517)
=17942=    by 0x410DDB: udev_event_process (udevd.c:145)
=17942=    by 0x411217: udev_event_run (udevd.c:251)
=17942=    by 0x411E78: msg_queue_manager (udevd.c:581)
=17942=    by 0x413C10: main (udevd.c:1282)
=17942=  Address 0x7fefff0af is on thread 1's stack
...

kill %1 %2

[restart normal udevd]

diff --git a/udev/udev_rules.c b/udev/udev_rules.c
index f372a61..9ed4d62 100644
--- a/udev/udev_rules.c
+++ b/udev/udev_rules.c
@@ -490,8 +490,8 @@ static int pass_env_to_socket(const char *sockpath, const char *devpath, const c
 
 	bufpos = snprintf(buf, sizeof(buf)-1, "%s@%s", action, devpath);
 	bufpos++;
-	for (i = 0; environ[i] != NULL && bufpos < (sizeof(buf)-1); i++) {
-		bufpos += strlcpy(&buf[bufpos], environ[i], sizeof(buf) - bufpos-1);
+	for (i = 0; environ[i] != NULL && bufpos < sizeof(buf); i++) {
+		bufpos += strlcpy(&buf[bufpos], environ[i], sizeof(buf) - bufpos);
 		bufpos++;
 	}
 	if (bufpos > sizeof(buf))



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix off-by-one in pass_env_to_socket()
  2008-09-08 13:17 [PATCH] Fix off-by-one in pass_env_to_socket() Alan Jenkins
@ 2008-09-08 22:40 ` Kay Sievers
  0 siblings, 0 replies; 2+ messages in thread
From: Kay Sievers @ 2008-09-08 22:40 UTC (permalink / raw)
  To: linux-hotplug

On Mon, Sep 8, 2008 at 15:17, Alan Jenkins <alan-jenkins@tuffmail.co.uk> wrote:
> This only manifests in exceptional circumstances when the variables exceed
> the buffer size.

Applied.

Thanks,
Kay

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-09-08 22:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-08 13:17 [PATCH] Fix off-by-one in pass_env_to_socket() Alan Jenkins
2008-09-08 22:40 ` Kay Sievers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).