Skip to content
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

fix overflow in alloc.c #37

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
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
Next Next commit
fix overflow in alloc.c
this patch will add unsigned integer for an overflow check in alloc.c
Matthew Dempsky came up with a fix.
See this discussion at https://marc.info/?l=qmail&m=125184448101814&w=2
  • Loading branch information
mbhangui authored and DerDakon committed Aug 31, 2019
commit 6d1578c0f488b31d70cf3d4476a414066e446f3f
6 changes: 5 additions & 1 deletion alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */
unsigned int n;
{
char *x;
n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */
unsigned int m = n;
if ((n = ALIGNMENT + n - (n & (ALIGNMENT - 1))) < m) { /* XXX: handle overflow */
errno = error_nomem;
return 0;
}
if (n <= avail) { avail -= n; return space + avail; }
x = malloc(n);
if (!x) errno = error_nomem;
Expand Down