]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/StoreMetaUnpacker.cc
2 * Copyright (C) 1996-2019 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 20 Storage Manager Swapfile Unpacker */
12 #include "base/TextException.h"
15 #include "StoreMeta.h"
16 #include "StoreMetaUnpacker.h"
18 int const StoreMetaUnpacker::MinimumBufferLength
= sizeof(char) + sizeof(int);
20 /// useful for meta stored in pre-initialized (with zeros) db files
22 StoreMetaUnpacker::isBufferZero()
24 // We could memcmp the entire buffer, but it is probably safe enough
25 // to test a few bytes because if we do not detect a corrupted entry
26 // it is not a big deal. Empty entries are not isBufferSane anyway.
29 return false; // cannot be sure enough
31 for (int i
= 0; i
< depth
; ++i
) {
39 StoreMetaUnpacker::checkBuffer()
41 assert(buf
); // paranoid; already checked in the constructor
42 if (buf
[0] != static_cast<char>(STORE_META_OK
))
43 throw TexcHere("store entry metadata is corrupted");
45 * sanity check on 'buflen' value. It should be at least big
46 * enough to hold one type and one length.
49 if (*hdr_len
< MinimumBufferLength
)
50 throw TexcHere("store entry metadata is too small");
51 if (*hdr_len
> buflen
)
52 throw TexcHere("store entry metadata is too big");
56 StoreMetaUnpacker::getBufferLength()
58 memcpy(hdr_len
, &buf
[1], sizeof(int));
61 StoreMetaUnpacker::StoreMetaUnpacker(char const *aBuffer
, ssize_t aLen
, int *anInt
) :
65 position(1 + sizeof(int)),
70 assert(aBuffer
!= NULL
);
74 StoreMetaUnpacker::getType()
81 StoreMetaUnpacker::getLength()
83 memcpy(&length
, &buf
[position
], sizeof(int));
84 position
+= sizeof(int);
88 StoreMetaUnpacker::doOneEntry()
93 if (position
+ length
> *hdr_len
) {
94 debugs(20, DBG_CRITICAL
, "storeSwapMetaUnpack: overflow!");
95 debugs(20, DBG_CRITICAL
, "\ttype=" << type
<< ", length=" << length
<< ", *hdr_len=" << *hdr_len
<< ", offset=" << position
);
99 StoreMeta
*newNode
= StoreMeta::Factory(type
, length
, &buf
[position
]);
102 tail
= StoreMeta::Add (tail
, newNode
);
110 StoreMetaUnpacker::moreToProcess() const
112 return *hdr_len
- position
- MinimumBufferLength
>= 0;
116 StoreMetaUnpacker::createStoreMeta ()
120 assert(hdr_len
!= NULL
);
126 assert (position
== 1 + sizeof(int));
128 while (moreToProcess()) {
134 throw TexcHere("store entry metadata is empty");