From: Samuel Thibault Date: Thu, 10 May 2012 22:49:30 +0000 (-0700) Subject: Hurd: Fix __dup3 _hurd_dtable_lock usage. X-Git-Tag: glibc-2.16-tps~387 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f34d6f840eaba45a82fa8d20922fc2d678968fb7;p=platform%2Fupstream%2Fglibc.git Hurd: Fix __dup3 _hurd_dtable_lock usage. --- diff --git a/ChangeLog b/ChangeLog index 805aded..d2174fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-05-10 Samuel Thibault + + * sysdeps/mach/hurd/dup3.c: Lock _hurd_dtable_lock before + checking for _hurd_dtablesize. Unlock it right after having + finished _hurd_dtable allocation. + 2012-05-10 Thomas Schwinge * sysdeps/mach/hurd/configure.in: Remove warning for --prefix=[...]. diff --git a/sysdeps/mach/hurd/dup3.c b/sysdeps/mach/hurd/dup3.c index 8a38caf..523ca42 100644 --- a/sysdeps/mach/hurd/dup3.c +++ b/sysdeps/mach/hurd/dup3.c @@ -71,15 +71,14 @@ __dup3 (int fd, int fd2, int flags) /* Get a hold of the destination descriptor. */ struct hurd_fd *d2; + __mutex_lock (&_hurd_dtable_lock); + if (fd2 >= _hurd_dtablesize) { /* The table is not large enough to hold the destination descriptor. Enlarge it as necessary to allocate this descriptor. */ __mutex_unlock (&_hurd_dtable_lock); - /* We still hold FD1's lock, but this is safe because - _hurd_alloc_fd will only examine the cells starting - at FD2. */ d2 = _hurd_alloc_fd (NULL, fd2); if (d2) __spin_unlock (&d2->port.lock); @@ -99,6 +98,7 @@ __dup3 (int fd, int fd2, int flags) MACH_PORT_NULL); } } + __mutex_unlock (&_hurd_dtable_lock); if (d2 == NULL) { @@ -126,7 +126,6 @@ __dup3 (int fd, int fd2, int flags) _hurd_port_locked_set (&d2->port, port); /* Unlocks D2. */ } } - __mutex_unlock (&_hurd_dtable_lock); _hurd_port_free (&d->port, &ulink, port); if (ctty != MACH_PORT_NULL)