dup2: fix off-by-one crash
* dtable.cc (dup3): Fix off-by-one. (find_unused_handle): Reduce time spent expanding during dup. * syscalls.cc (setdtablesize): Report error on invalid value.
This commit is contained in:
		| @@ -1,3 +1,10 @@ | |||||||
|  | 2013-11-23  Eric Blake  <eblake@redhat.com> | ||||||
|  |  | ||||||
|  | 	dup2: fix off-by-one crash | ||||||
|  | 	* dtable.cc (dup3): Fix off-by-one. | ||||||
|  | 	(find_unused_handle): Reduce time spent expanding during dup. | ||||||
|  | 	* syscalls.cc (setdtablesize): Report error on invalid value. | ||||||
|  |  | ||||||
| 2013-11-20  Corinna Vinschen  <corinna@vinschen.de> | 2013-11-20  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
| 	* include/cygwin/stdlib.h (realpath): Drop declaration.  It's declared | 	* include/cygwin/stdlib.h (realpath): Drop declaration.  It's declared | ||||||
|   | |||||||
| @@ -233,7 +233,7 @@ dtable::find_unused_handle (int start) | |||||||
| 	if (fds[i] == NULL) | 	if (fds[i] == NULL) | ||||||
| 	  return i; | 	  return i; | ||||||
|     } |     } | ||||||
|   while (extend (NOFILE_INCR)); |   while (extend (MAX (NOFILE_INCR, start - size))); | ||||||
|   return -1; |   return -1; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -754,7 +754,7 @@ dtable::dup3 (int oldfd, int newfd, int flags) | |||||||
|  |  | ||||||
|   if (!not_open (newfd)) |   if (!not_open (newfd)) | ||||||
|     close (newfd); |     close (newfd); | ||||||
|   else if ((size_t) newfd > size |   else if ((size_t) newfd >= size | ||||||
| 	   && find_unused_handle (newfd) < 0) | 	   && find_unused_handle (newfd) < 0) | ||||||
|     /* couldn't extend fdtab */ |     /* couldn't extend fdtab */ | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -2578,6 +2578,12 @@ system (const char *cmdstring) | |||||||
| extern "C" int | extern "C" int | ||||||
| setdtablesize (int size) | setdtablesize (int size) | ||||||
| { | { | ||||||
|  |   if (size < 0) | ||||||
|  |     { | ||||||
|  |       set_errno (EINVAL); | ||||||
|  |       return -1; | ||||||
|  |     } | ||||||
|  |  | ||||||
|   if (size <= (int)cygheap->fdtab.size || cygheap->fdtab.extend (size - cygheap->fdtab.size)) |   if (size <= (int)cygheap->fdtab.size || cygheap->fdtab.extend (size - cygheap->fdtab.size)) | ||||||
|     return 0; |     return 0; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user