Skip to content

Commit

Permalink
sign-digest: Fixing overflow check and output wording when start is n…
Browse files Browse the repository at this point in the history
…egative. (Feedback from Bu11etmagnet.)
  • Loading branch information
Neal Krawetz committed Nov 6, 2024
1 parent b3aadc5 commit 96231ac
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/sign-digest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ sealfield * RangeErrorCheck (sealfield *Rec, uint64_t sum[2], mmapfile *Mmap)
{
// Idiot-check the range
if (sum[0]==sum[1]) { return(Rec); } // sure, permit an empty range
if (sum[0] < 0)
if (sum[0] > Mmap->memsize) // sum went negative
{
Rec = SealSetText(Rec,"@error","Invalid range; start of range is negative");
}
if (sum[1] < 0)
{
Rec = SealSetText(Rec,"@error","Invalid range; end of range is negative");
Rec = SealSetText(Rec,"@error","Invalid range; start of range is beyond end of file");
}
if (sum[1] > Mmap->memsize)
{
Expand Down Expand Up @@ -207,12 +203,13 @@ sealfield * SealDigest (sealfield *Rec, mmapfile *Mmap)
else { sum[1] += acc*Addsym; }

// Check the range
if ((sum[1] < sum[0]) || (sum[0] < 0) || (sum[1] > Mmap->memsize))
// sum is size_t/unsigned. If it goes negative, it will be larger than memsize.
if ((sum[1] < sum[0]) || (sum[0] > Mmap->memsize) || (sum[1] > Mmap->memsize))
{
Rec = SealSetText(Rec,"@error","Invalid range in b='");
Rec = SealAddText(Rec,"@error",b);
Rec = SealAddText(Rec,"@error","'");
if (sum[0] < 0) { Rec = SealAddText(Rec,"@error","; underflow"); }
if (sum[0] > Mmap->memsize) { Rec = SealAddText(Rec,"@error","; underflow"); }
if (sum[1] > Mmap->memsize) { Rec = SealAddText(Rec,"@error","; overflow"); }
if (sum[1] < sum[0]) { Rec = SealAddText(Rec,"@error","; range begins after it ends"); }
goto Abort;
Expand Down

0 comments on commit 96231ac

Please sign in to comment.