Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tools/core/flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ class Flow {
return IndexError_ReadData;
}

if (!data_ptr) {
LOG_ERROR("Invalid data pointer for tag list header");
return IndexError_ReadData;
}

memcpy(&taglist_header, data_ptr, sizeof(TagListHeader));

auto segment_taglist_key = storage->get(TAGLIST_KEY_SEGMENT_NAME);
Expand All @@ -209,6 +214,11 @@ class Flow {
return IndexError_ReadData;
}

if (!data_ptr) {
LOG_ERROR("Invalid data pointer for tag list key");
return IndexError_ReadData;
}

uint64_t key = *reinterpret_cast<const uint64_t *>(data_ptr);
tag_key_list_.push_back(key);

Expand All @@ -231,6 +241,11 @@ class Flow {
return IndexError_ReadData;
}

if (!data_ptr) {
LOG_ERROR("Invalid data pointer for tag list offset");
return IndexError_ReadData;
}

uint64_t tag_offset = *reinterpret_cast<const uint64_t *>(data_ptr);
taglist_offsets.push_back(tag_offset);

Expand All @@ -246,6 +261,11 @@ class Flow {
}
offset += sizeof(uint64_t);

if (!data_ptr) {
LOG_ERROR("Invalid data pointer for tag count");
return IndexError_ReadData;
}

uint64_t tag_count = *reinterpret_cast<const uint64_t *>(data_ptr);

if (segment_taglist_data->read(offset, (const void **)(&data_ptr),
Expand Down
20 changes: 20 additions & 0 deletions tools/core/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ int load_taglists(const std::string &path,
return IndexError_ReadData;
}

if (!data_ptr) {
LOG_ERROR("Invalid data pointer for tag list header");
return IndexError_ReadData;
}

memcpy(&taglist_header, data_ptr, sizeof(TagListHeader));

auto segment_taglist_key = storage->get(TAGLIST_KEY_SEGMENT_NAME);
Expand All @@ -238,6 +243,11 @@ int load_taglists(const std::string &path,
return IndexError_ReadData;
}

if (!data_ptr) {
LOG_ERROR("Invalid data pointer for tag list key");
return IndexError_ReadData;
}

uint64_t key = *reinterpret_cast<const uint64_t *>(data_ptr);
tag_key_list.push_back(key);

Expand All @@ -260,6 +270,11 @@ int load_taglists(const std::string &path,
return IndexError_ReadData;
}

if (!data_ptr) {
LOG_ERROR("Invalid data pointer for tag list offset");
return IndexError_ReadData;
}

uint64_t tag_offset = *reinterpret_cast<const uint64_t *>(data_ptr);
taglist_offsets.push_back(tag_offset);

Expand All @@ -275,6 +290,11 @@ int load_taglists(const std::string &path,
}
offset += sizeof(uint64_t);

if (!data_ptr) {
LOG_ERROR("Invalid data pointer for tag count");
return IndexError_ReadData;
}
Comment on lines 291 to +296
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 offset incremented before null check — inconsistent ordering

offset += sizeof(uint64_t) is executed on line 291 before the null check on line 293. The other three null checks added by this PR are all placed immediately after the read() return-value guard, before any subsequent state mutation. To be consistent and to guard against unintended state modification before early-return, move the null check above the offset increment. The same ordering issue exists in flow.h at the corresponding location (line 262).

Suggested change
offset += sizeof(uint64_t);
if (!data_ptr) {
LOG_ERROR("Invalid data pointer for tag count");
return IndexError_ReadData;
}
if (!data_ptr) {
LOG_ERROR("Invalid data pointer for tag count");
return IndexError_ReadData;
}
offset += sizeof(uint64_t);


uint64_t tag_count = *reinterpret_cast<const uint64_t *>(data_ptr);

if (segment_taglist_data->read(offset, (const void **)(&data_ptr),
Expand Down