------------------------------------------------------------ revno: 12444 revision-id: squid3@treenet.co.nz-20130102100954-kswk6y6qolnto9zf parent: squid3@treenet.co.nz-20130102100432-kunyl07x0klskupm author: Tomas Hozza , Amos Jeffries committer: Amos Jeffries branch nick: 3.3 timestamp: Wed 2013-01-02 03:09:54 -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-20130102100954-kswk6y6qolnto9zf # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3 # testament_sha1: c97a431b1f3f594a355ef3aa83edb6e9c9a87498 # timestamp: 2013-01-02 10:14:51 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3 # base_revision_id: squid3@treenet.co.nz-20130102100432-\ # kunyl07x0klskupm # # Begin patch === modified file 'src/DiskIO/AIO/AIODiskIOStrategy.cc' --- src/DiskIO/AIO/AIODiskIOStrategy.cc 2012-09-01 14:38:36 +0000 +++ src/DiskIO/AIO/AIODiskIOStrategy.cc 2013-01-02 10:09:54 +0000 @@ -47,9 +47,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-09-01 14:38:36 +0000 +++ src/DiskIO/DiskDaemon/DiskdFile.cc 2013-01-02 10:09:54 +0000 @@ -66,8 +66,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); @@ -379,8 +382,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; @@ -404,7 +409,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-09-01 14:38:36 +0000 +++ src/DiskIO/DiskDaemon/diskd.cc 2013-01-02 10:09:54 +0000 @@ -264,6 +264,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) { @@ -368,7 +372,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-09-04 09:10:20 +0000 +++ src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc 2013-01-02 10:09:54 +0000 @@ -187,7 +187,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:02:52 +0000 +++ src/DiskIO/DiskThreads/aiops.cc 2013-01-02 10:09:54 +0000 @@ -722,8 +722,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-09-04 09:10:20 +0000 +++ src/DiskIO/IpcIo/IpcIoFile.cc 2013-01-02 10:09:54 +0000 @@ -588,9 +588,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 */