Skip to content

Commit

Permalink
Limit datasize to 4096 bytes
Browse files Browse the repository at this point in the history
This is allowed by spec, and avoids an integer overflow.

Closes: gh-135
  • Loading branch information
yoe committed Jul 28, 2023
1 parent 58b356b commit 569070d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion nbd-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ struct reply* read_reply(int sock) {
fprintf(stderr, "E: received invalid negotiation magic %" PRIu64 " (expected %" PRIu64 ")", retval->magic, rep_magic);
exit(EXIT_FAILURE);
}
if (retval->datasize > 0) {
if (retval->datasize > 0 && retval->datasize < 4096) {
retval = realloc(retval, sizeof(struct reply) + retval->datasize);
readit(sock, &(retval->data), retval->datasize);
}
Expand Down

0 comments on commit 569070d

Please sign in to comment.