------------------------------------------------------------ revno: 11754 revision-id: squid3@treenet.co.nz-20130128054311-h1mp3joh99vkxb8u parent: squid3@treenet.co.nz-20130128054006-pxm5jfqt3udui265 author: Tomas Hozza , Amos Jeffries committer: Amos Jeffries branch nick: 3.2 timestamp: Sun 2013-01-27 22:43:11 -0700 message: Fix various Disk I/O issues in all modules * Uninitialized class members. * Handle NULL potential after several dynamic_cast. * Better error result handling from several system functions lseek(), fcntl() can report errors which need handling. * diskd explicit NULL dereference on broken input. Extremely unlikely, but worth protecting against. Detected by Coverity Scan. Issues 740510, 740358, 740359, 740511, 740317, 740360, 740513, 740318, 740514 ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20130128054311-h1mp3joh99vkxb8u # target_branch: http://bzr.squid-cache.org/bzr/squid3/branches\ # /SQUID_3_2 # testament_sha1: 5458319fa1813445f8ddb3822f93b82d66ab2b3e # timestamp: 2013-01-28 05:45:17 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/branches\ # /SQUID_3_2 # base_revision_id: squid3@treenet.co.nz-20130128054006-\ # pxm5jfqt3udui265 # # Begin patch === modified file 'src/DiskIO/AIO/AIODiskIOStrategy.cc' --- src/DiskIO/AIO/AIODiskIOStrategy.cc 2012-07-28 05:38:50 +0000 +++ src/DiskIO/AIO/AIODiskIOStrategy.cc 2013-01-28 05:43:11 +0000 @@ -49,9 +49,12 @@ #include "DiskIO/ReadRequest.h" #include "DiskIO/WriteRequest.h" -AIODiskIOStrategy::AIODiskIOStrategy() +AIODiskIOStrategy::AIODiskIOStrategy() : + fd(-1) { + aq.aq_state = AQ_STATE_NONE; aq.aq_numpending = 0; + memset(&aq.aq_queue, 0, sizeof(aq.aq_queue)); } AIODiskIOStrategy::~AIODiskIOStrategy() === modified file 'src/DiskIO/DiskDaemon/DiskdFile.cc' --- src/DiskIO/DiskDaemon/DiskdFile.cc 2012-07-28 05:38:50 +0000 +++ src/DiskIO/DiskDaemon/DiskdFile.cc 2013-01-28 05:43:11 +0000 @@ -69,8 +69,11 @@ cbdataFree(t); } -DiskdFile::DiskdFile(char const *aPath, DiskdIOStrategy *anIO) : errorOccured (false), IO(anIO), - inProgressIOs (0) +DiskdFile::DiskdFile(char const *aPath, DiskdIOStrategy *anIO) : + errorOccured(false), + IO(anIO), + mode(0), + inProgressIOs(0) { assert (aPath); debugs(79, 3, "DiskdFile::DiskdFile: " << aPath); @@ -382,8 +385,10 @@ debugs(79, 3, "DiskdFile::readDone: status " << M->status); assert (M->requestor); ReadRequest::Pointer readRequest = dynamic_cast(M->requestor); + /* remove the free protection */ - readRequest->RefCountDereference(); + if (readRequest != NULL) + readRequest->RefCountDereference(); if (M->status < 0) { ++diskd_stats.read.fail; @@ -407,7 +412,8 @@ assert (M->requestor); WriteRequest::Pointer writeRequest = dynamic_cast(M->requestor); /* remove the free protection */ - writeRequest->RefCountDereference(); + if (writeRequest != NULL) + writeRequest->RefCountDereference(); if (M->status < 0) { errorOccured = true; === modified file 'src/DiskIO/DiskDaemon/diskd.cc' --- src/DiskIO/DiskDaemon/diskd.cc 2012-06-28 05:14:18 +0000 +++ src/DiskIO/DiskDaemon/diskd.cc 2013-01-28 05:43:11 +0000 @@ -266,6 +266,10 @@ if (s->shm_offset > -1) buf = shmbuf + s->shm_offset; + else { + fprintf(stderr, "%d UNLNK id(%u) Error: no filename in shm buffer\n", (int) mypid, s->id); + return; + } switch (r->mtype) { @@ -370,7 +374,10 @@ hash = hash_create(fsCmp, 1 << 4, fsHash); assert(hash); - fcntl(0, F_SETFL, SQUID_NONBLOCK); + if (fcntl(0, F_SETFL, SQUID_NONBLOCK) < 0) { + perror(xstrerror()); + return 1; + } memset(&sa, '\0', sizeof(sa)); sa.sa_handler = alarm_handler; sa.sa_flags = SA_RESTART; === modified file 'src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc' --- src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc 2012-07-28 05:38:50 +0000 +++ src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc 2013-01-28 05:43:11 +0000 @@ -190,7 +190,10 @@ debugs(32, 2, "aioSync: done"); } -DiskThreadsIOStrategy::DiskThreadsIOStrategy() : initialised (false) {} +DiskThreadsIOStrategy::DiskThreadsIOStrategy() : + initialised(false), + squidaio_ctrl_pool(NULL) +{} void DiskThreadsIOStrategy::aioStats(StoreEntry * sentry) === modified file 'src/DiskIO/DiskThreads/aiops.cc' --- src/DiskIO/DiskThreads/aiops.cc 2012-11-10 04:37:29 +0000 +++ src/DiskIO/DiskThreads/aiops.cc 2013-01-28 05:43:11 +0000 @@ -729,8 +729,10 @@ static void squidaio_do_read(squidaio_request_t * requestp) { - lseek(requestp->fd, requestp->offset, requestp->whence); - requestp->ret = read(requestp->fd, requestp->bufferp, requestp->buflen); + if (lseek(requestp->fd, requestp->offset, requestp->whence) >= 0) + requestp->ret = read(requestp->fd, requestp->bufferp, requestp->buflen); + else + requestp->ret = -1; requestp->err = errno; } === modified file 'src/DiskIO/IpcIo/IpcIoFile.cc' --- src/DiskIO/IpcIo/IpcIoFile.cc 2012-07-28 05:38:50 +0000 +++ src/DiskIO/IpcIo/IpcIoFile.cc 2013-01-28 05:43:11 +0000 @@ -584,9 +584,14 @@ /* IpcIoMsg */ IpcIoMsg::IpcIoMsg(): - requestId(0), offset(0), len(0), command(IpcIo::cmdNone), xerrno(0) + requestId(0), + offset(0), + len(0), + command(IpcIo::cmdNone), + xerrno(0) { start.tv_sec = 0; + start.tv_usec = 0; } /* IpcIoPendingRequest */