* dtable.cc (fh_oom): New static fhandler storage.

(fh_calloc): New static function.  Add a comment to explain why this
	is needed.
	(cnew): Call fh_calloc as placement argument.
	(build_fh_name): Check return code from cnew against address of
	fh_oom to test for out of memory condition.
	(fh_alloc): Ditto.
	(build_fh_pc): Avoid a crash due to useing a NULL fhandler.
	* pipe.cc (fhandler_pipe::create): Check if build_fh_dev returned a
	valid pointer before using it.
This commit is contained in:
Corinna Vinschen
2011-06-30 09:37:36 +00:00
parent 53ffbf09d5
commit 9e1fd6bcf7
3 changed files with 41 additions and 9 deletions

View File

@@ -303,19 +303,23 @@ fhandler_pipe::create (fhandler_pipe *fhs[2], unsigned psize, int mode)
{
HANDLE r, w;
SECURITY_ATTRIBUTES *sa = sec_none_cloexec (mode);
int res;
int res = -1;
int ret = create_selectable (sa, r, w, psize);
if (ret)
__seterrno_from_win_error (ret);
else if ((fhs[0] = (fhandler_pipe *) build_fh_dev (*piper_dev)) == NULL)
{
__seterrno_from_win_error (ret);
res = -1;
CloseHandle (r);
CloseHandle (w);
}
else if ((fhs[1] = (fhandler_pipe *) build_fh_dev (*pipew_dev)) == NULL)
{
delete fhs[0];
CloseHandle (w);
}
else
{
fhs[0] = (fhandler_pipe *) build_fh_dev (*piper_dev);
fhs[1] = (fhandler_pipe *) build_fh_dev (*pipew_dev);
mode |= mode & O_TEXT ?: O_BINARY;
fhs[0]->init (r, FILE_CREATE_PIPE_INSTANCE | GENERIC_READ, mode);
fhs[1]->init (w, FILE_CREATE_PIPE_INSTANCE | GENERIC_WRITE, mode);