[PATCH] Fix use of invalid file descriptor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Vegard Nossum <vegardno@xxxxxxxxxx>
Date: Sun, 25 May 2008 09:41:29 +0200
Subject: [PATCH] Fix use of invalid file descriptor

tokenize_buffer() calls setup_stream() with a file descriptor argument of -1.
This number makes it all the way into nextchar_slow(), where -1 is used as an
actual file descriptor when calling read().

Check for the -1 before calling read() if the buffer is empty.

(By the way, that read() there is probably missing some additional error
 handling. An EINTR at the right moment...)

Signed-off-by: Vegard Nossum <vegardno@xxxxxxxxxx>
---
 tokenize.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/tokenize.c b/tokenize.c
index e72c56e..d154882 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -213,6 +213,8 @@ restart:
 
 repeat:
 	if (offset >= size) {
+		if (stream->fd < 0)
+			goto got_eof;
 		size = read(stream->fd, stream->buffer, BUFSIZE);
 		if (size <= 0)
 			goto got_eof;
-- 
1.5.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux