Skip to content

bugfix: data size calculation and data range check #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions ipdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ int ipdb_resolve(ipdb_reader *reader, int node, const char **bytes) {
return ErrDatabaseError;
}

int size = (reader->data[resolved] << 8) | reader->data[resolved + 2];
int size = (reader->data[resolved] << 8) | reader->data[resolved + 1];
if ((resolved + 2 + size) > reader->data_size) {
return ErrDatabaseError;
}
Expand All @@ -162,15 +162,15 @@ int ipdb_search(ipdb_reader *reader, const u_char *ip, int bit_count, int *node)
}

for (int i = 0; i < bit_count; ++i) {
if (*node > reader->meta->node_count) {
if (*node >= reader->meta->node_count) {
break;
}

*node = ipdb_read_node(reader, *node,
((0xFF & ((int) ip[i >> 3])) >> (unsigned int) (7 - (i % 8))) & 1);
}

if (*node > reader->meta->node_count) {
if (*node >= reader->meta->node_count) {
return ErrNoErr;
}
return ErrDataNotExists;
Expand Down