diff --git a/ChangeLog b/ChangeLog index c59df38c2..0063cdf04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-12-15 Vladimir Serbinenko + + * grub-core/lib/reed_solomon.c (decode_block): Allocate on heap and not + stack. + (encode_block): Likewise. + 2011-12-15 Vladimir Serbinenko * grub-core/boot/i386/pc/startup_raw.S: Clear direction flag for diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index fc5443c28..3d8bb9e1f 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -390,12 +390,19 @@ decode_block (gf_single_t *ptr, grub_size_t s, { grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; grub_size_t rr = (rs + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; - gf_single_t m[ds + rr]; + gf_single_t *m; /* Nothing to do. */ if (!ds || !rr) continue; +#ifndef STANDALONE + m = xmalloc (ds + rr); +#else + m = (gf_single_t *) scratch; + scratch += ds + rr; +#endif + for (j = 0; j < (int) ds; j++) m[j] = ptr[SECTOR_SIZE * j + i]; for (j = 0; j < (int) rr; j++) @@ -405,6 +412,12 @@ decode_block (gf_single_t *ptr, grub_size_t s, for (j = 0; j < (int) ds; j++) ptr[SECTOR_SIZE * j + i] = m[j]; + +#ifndef STANDALONE + free (m); +#else + scratch -= ds + rr; +#endif } } @@ -418,12 +431,18 @@ encode_block (gf_single_t *ptr, grub_size_t s, { grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; grub_size_t rr = (rs + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; - gf_single_t m[ds + rr]; + gf_single_t *m; + + if (!ds || !rr) + continue; + + m = xmalloc (ds + rr); for (j = 0; j < ds; j++) m[j] = ptr[SECTOR_SIZE * j + i]; rs_encode (m, ds, rr); for (j = 0; j < rr; j++) rptr[SECTOR_SIZE * j + i] = m[j + ds]; + free (m); } } #endif