mirror of
https://github.com/upx/upx
synced 2025-10-05 19:20:23 +08:00
MemBuffer.subref(errfmt, skip, take) checks that a subinterval is inside
modified: mem.cpp modified: mem.h
This commit is contained in:
parent
58771ecca6
commit
f014406b65
12
src/mem.cpp
12
src/mem.cpp
|
@ -73,6 +73,18 @@ MemBuffer::~MemBuffer()
|
||||||
this->dealloc();
|
this->dealloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// similar to BoundedPtr, except checks only at creation
|
||||||
|
unsigned char *MemBuffer::subref(char const *errfmt, unsigned skip, unsigned take)
|
||||||
|
{
|
||||||
|
if ((take + skip) < take // wrap-around
|
||||||
|
|| (take + skip) > b_size // overrun
|
||||||
|
) {
|
||||||
|
char buf[100]; snprintf(buf, sizeof(buf), errfmt, skip, take);
|
||||||
|
throwCantPack(buf);
|
||||||
|
}
|
||||||
|
return &b[skip];
|
||||||
|
}
|
||||||
|
|
||||||
void MemBuffer::dealloc()
|
void MemBuffer::dealloc()
|
||||||
{
|
{
|
||||||
if (b != NULL)
|
if (b != NULL)
|
||||||
|
|
|
@ -64,6 +64,11 @@ public:
|
||||||
void clear(unsigned off, unsigned len) { fill(off, len, 0); }
|
void clear(unsigned off, unsigned len) { fill(off, len, 0); }
|
||||||
void clear() { fill(0, b_size, 0); }
|
void clear() { fill(0, b_size, 0); }
|
||||||
|
|
||||||
|
// If the entire range [skip, take+skip) is inside the buffer,
|
||||||
|
// then return &b[skip]; else throwCantPack(sprintf(errfmt, skip, take)).
|
||||||
|
// This is similar to BoundedPtr, except only checks once.
|
||||||
|
unsigned char *subref(char const *errfmt, unsigned skip, unsigned take);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned char *b;
|
unsigned char *b;
|
||||||
unsigned b_size;
|
unsigned b_size;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user