relocator: Fix integer underflow.

This commit is contained in:
Daniel Kiper 2016-02-12 15:58:22 +01:00 committed by Vladimir Serbinenko
parent 6e1ace590a
commit eba6db6323

View file

@ -736,26 +736,36 @@ malloc_in_range (struct grub_relocator *rel,
} }
isinsideafter = (!ncollisions && (nstarted || ((nlefto || nstartedfw) isinsideafter = (!ncollisions && (nstarted || ((nlefto || nstartedfw)
&& !nblockfw))); && !nblockfw)));
if (!isinsidebefore && isinsideafter) if (from_low_priv) {
starta = from_low_priv ? ALIGN_UP (events[j].pos, align) if (!isinsidebefore && isinsideafter)
: ALIGN_DOWN (events[j].pos - size, align) + size; starta = ALIGN_UP (events[j].pos, align);
if (isinsidebefore && !isinsideafter && from_low_priv)
{ if (isinsidebefore && !isinsideafter)
target = starta; {
if (target < start) target = starta;
target = start; if (target < start)
if (target + size <= end && target + size <= events[j].pos) target = start;
/* Found an usable address. */ if (target + size <= end && target + size <= events[j].pos)
goto found; /* Found an usable address. */
} goto found;
if (isinsidebefore && !isinsideafter && !from_low_priv) }
{ } else {
target = starta - size; if (!isinsidebefore && isinsideafter)
if (target > end - size) {
target = end - size; if (events[j].pos >= size)
if (target >= start && target >= events[j].pos) starta = ALIGN_DOWN (events[j].pos - size, align) + size;
goto found; else
} starta = 0;
}
if (isinsidebefore && !isinsideafter && starta >= size)
{
target = starta - size;
if (target > end - size)
target = end - size;
if (target >= start && target >= events[j].pos)
goto found;
}
}
} }
} }