Skip to content

Commit

Permalink
Merge pull request #41 from zeux/sanitize
Browse files Browse the repository at this point in the history
Add config=sanitize to make it easier to test changes
  • Loading branch information
zeux authored Oct 27, 2024
2 parents 3dcd9a8 + bf86435 commit 8a7869e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.SUFFIXES:
MAKEFLAGS+=-r

BUILD=build/make-$(CXX)
config?=release

BUILD=build/make-$(CXX)-$(config)

CCFLAGS=-c -g -Wall -Werror -fPIC -O2 -Iextern/lz4/lib -Iextern/re2
CXXFLAGS=-std=c++11
Expand All @@ -23,6 +25,11 @@ else
LDFLAGS+=-pie -Wl,--dynamic-list=src/qgrep.dynlist
endif

ifeq ($(config),sanitize)
CCFLAGS+=-fsanitize=address,undefined
LDFLAGS+=-fsanitize=address,undefined
endif

SOURCES=

SOURCES+=extern/re2/re2/bitmap256.cc extern/re2/re2/bitstate.cc extern/re2/re2/compile.cc extern/re2/re2/dfa.cc extern/re2/re2/filtered_re2.cc extern/re2/re2/mimics_pcre.cc extern/re2/re2/nfa.cc extern/re2/re2/onepass.cc extern/re2/re2/parse.cc extern/re2/re2/perl_groups.cc extern/re2/re2/prefilter.cc extern/re2/re2/prefilter_tree.cc extern/re2/re2/prog.cc extern/re2/re2/re2.cc extern/re2/re2/regexp.cc extern/re2/re2/set.cc extern/re2/re2/simplify.cc extern/re2/re2/stringpiece.cc extern/re2/re2/tostring.cc extern/re2/re2/unicode_casefold.cc extern/re2/re2/unicode_groups.cc
Expand Down
3 changes: 2 additions & 1 deletion src/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ static ChunkData prepareChunkData(const Chunk& chunk)
const File& f = chunk.files[i];

memcpy(result.data.get() + nameOffset, f.name.c_str(), f.name.length());
memcpy(result.data.get() + dataOffset, f.contents.data(), f.contents.size());
if (f.contents.size())
memcpy(result.data.get() + dataOffset, f.contents.data(), f.contents.size());

DataChunkFileHeader& h = reinterpret_cast<DataChunkFileHeader*>(result.data.get())[i];

Expand Down
7 changes: 5 additions & 2 deletions src/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,18 @@ static bool processFile(Output* output, BuildContext* builder, UpdateFileIterato
{
std::unique_ptr<char[]> extra(new (std::nothrow) char[chunk.extraSize]);
std::unique_ptr<char[]> index(new (std::nothrow) char[chunk.indexSize]);
std::unique_ptr<char[]> data(new (std::nothrow) char[chunk.compressedSize + chunk.uncompressedSize]);

size_t uncompressedOffset = (chunk.compressedSize + 7) & ~7; // make sure uncompressed data is aligned

std::unique_ptr<char[]> data(new (std::nothrow) char[uncompressedOffset + chunk.uncompressedSize]);

if (!extra || !index || !data || !read(in, extra.get(), chunk.extraSize) || !read(in, index.get(), chunk.indexSize) || !read(in, data.get(), chunk.compressedSize))
{
output->error("Error reading data file %s: malformed chunk\n", path);
return false;
}

char* uncompressed = data.get() + chunk.compressedSize;
char* uncompressed = data.get() + uncompressedOffset;

processChunkData(output, builder, fileit, stats, chunk, uncompressed, data, index, extra);
}
Expand Down

0 comments on commit 8a7869e

Please sign in to comment.