From 51a360a0051323837c2885d29c92bd7cd2072341 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Nov 2006 11:41:52 +0100 Subject: [PATCH] Bug#23010 _my_b_read() passing illegal file handles to my_seek() - The io cache flag seek_not_done was not set properly in the reinit_io_cache function call and this led my_seek to be called desipite an invalid file handle. - Added a test in reinit_io_cache to ensure we have a valid file handle before setting seek_not_done flag. mysys/mf_iocache.c: Added a test to only trigger my_seek function calls if we have a valid file descriptor. mysys/my_seek.c: Refactored incomplete condition into an assertion. This also ensures that variable newpos is initialized properly. --- mysys/mf_iocache.c | 6 +++++- mysys/my_seek.c | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c index a7937da0cc2..5f0069d9bed 100644 --- a/mysys/mf_iocache.c +++ b/mysys/mf_iocache.c @@ -313,7 +313,11 @@ my_bool reinit_io_cache(IO_CACHE *info, enum cache_type type, if (info->type == READ_CACHE) { info->write_end=info->write_buffer+info->buffer_length; - info->seek_not_done=1; + /* + Trigger a new seek only if we have a valid + file handle. + */ + info->seek_not_done= (info->file >= 0); } info->end_of_file = ~(my_off_t) 0; } diff --git a/mysys/my_seek.c b/mysys/my_seek.c index ec24a26b3d9..f47383b7ace 100644 --- a/mysys/my_seek.c +++ b/mysys/my_seek.c @@ -30,6 +30,11 @@ my_off_t my_seek(File fd, my_off_t pos, int whence, whence, MyFlags)); DBUG_ASSERT(pos != MY_FILEPOS_ERROR); /* safety check */ + /* + Make sure we are using a valid file descriptor + */ + DBUG_ASSERT(fd >= 0); + newpos=lseek(fd, pos, whence); if (newpos == (os_off_t) -1) {