From: Alex Rousskov Date: Sun, 5 Feb 2012 07:31:45 +0000 (-0700) Subject: Bug 3441: part 2: Prevent further cache size corruption of swap.state X-Git-Tag: SQUID_3_1_19~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5aed765e03caf36069764cb34b462715bd3963f7;p=thirdparty%2Fsquid.git Bug 3441: part 2: Prevent further cache size corruption of swap.state --- diff --git a/src/fs/ufs/store_dir_ufs.cc b/src/fs/ufs/store_dir_ufs.cc index 1f9f3f4c56..0344368cad 100644 --- a/src/fs/ufs/store_dir_ufs.cc +++ b/src/fs/ufs/store_dir_ufs.cc @@ -750,13 +750,6 @@ UFSSwapDir::closeTmpSwapLog() debugs(47, 3, "Cache Dir #" << index << " log opened on FD " << fd); } -static void -FreeHeader(void *address) -{ - StoreSwapLogHeader *anObject = static_cast (address); - delete anObject; -} - FILE * UFSSwapDir::openTmpSwapLog(int *clean_flag, int *zero_flag) { @@ -795,9 +788,16 @@ UFSSwapDir::openTmpSwapLog(int *clean_flag, int *zero_flag) swaplog_fd = fd; { - StoreSwapLogHeader *header = new StoreSwapLogHeader; - file_write(swaplog_fd, -1, header, sizeof(*header), - NULL, NULL, FreeHeader); + const StoreSwapLogHeader header; + MemBuf buf; + buf.init(header.record_size, header.record_size); + buf.append(reinterpret_cast(&header), sizeof(header)); + // Pad to keep in sync with UFSSwapDir::writeCleanStart(). + // TODO: When MemBuf::spaceSize() is fixed not to subtract one, + // memset() space() with zeroes and use spaceSize() below. + buf.appended(static_cast(header.record_size) - sizeof(header)); + file_write(swaplog_fd, -1, buf.content(), buf.contentSize(), + NULL, NULL, buf.freeFunc()); } /* open a read-only stream of the old log */ @@ -883,6 +883,7 @@ UFSSwapDir::writeCleanStart() state->outbuf_offset = 0; /*copy the header */ xmemcpy(state->outbuf, &header, sizeof(StoreSwapLogHeader)); + // Leave a gap to keep in sync with UFSSwapDir::openTmpSwapLog(). state->outbuf_offset += header.record_size; state->walker = repl->WalkInit(repl);