From a0159f370da21f7dd264e7b4185f15907cca19ef Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 4 Jan 2011 15:39:59 +0100 Subject: [PATCH] * grub-core/lib/reed_solomon.c (grub_reed_solomon_add_redundancy): Prevent overflow. (grub_reed_solomon_recover): Likewise. --- ChangeLog | 6 ++++++ grub-core/lib/reed_solomon.c | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 505923fa9..3e20a118b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-04 Vladimir Serbinenko + + * grub-core/lib/reed_solomon.c (grub_reed_solomon_add_redundancy): + Prevent overflow. + (grub_reed_solomon_recover): Likewise. + 2011-01-04 Vladimir Serbinenko * grub-core/lib/reed_solomon.c (main) [TEST]: Reactivate normal test. diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index 62aad3111..e500ba32d 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -433,8 +433,8 @@ grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size, tt = cs + crs; if (tt > MAX_BLOCK_SIZE) { - cs = (cs * MAX_BLOCK_SIZE) / tt; - crs = (crs * MAX_BLOCK_SIZE) / tt; + cs = ((cs * (MAX_BLOCK_SIZE / 512)) / tt) * 512; + crs = ((crs * (MAX_BLOCK_SIZE / 512)) / tt) * 512; } encode_block (ptr, cs, rptr, crs); ptr += cs; @@ -468,8 +468,8 @@ grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs) tt = cs + crs; if (tt > MAX_BLOCK_SIZE) { - cs = (cs * MAX_BLOCK_SIZE) / tt; - crs = (crs * MAX_BLOCK_SIZE) / tt; + cs = ((cs * (MAX_BLOCK_SIZE / 512)) / tt) * 512; + crs = ((crs * (MAX_BLOCK_SIZE / 512)) / tt) * 512; } decode_block (ptr, cs, rptr, crs); ptr += cs;