This patch fixes a memory corruption error in lar when compiled on a 64-bit

architecture.  The function prototypes had a size mismatch, which overwrote
other things on the stack.  Now the prototypes use int for lengths.

Signed-off-by: Myles Watson <myles@pel.cs.byu.edu>
Acked-by: Ronald G. Minnich <rminnich@gmail.com>


git-svn-id: svn://coreboot.org/repository/coreboot-v3@592 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
Myles Watson 2008-02-13 17:30:49 +00:00
parent 93a391301e
commit 6c88373502
6 changed files with 30 additions and 29 deletions

View file

@ -93,18 +93,18 @@ struct lar {
enum compalgo { none = 0, lzma = 1, nrv2b = 2 };
typedef void (*compress_func) (char *, u32, char *, u32 *);
typedef void (*uncompress_func) (char *, char *, u32);
typedef void (*compress_func) (char *, int, char *, int *);
typedef void (*uncompress_func) (char *, char *, int);
void compress_impossible(char *in, u32 in_len, char *out, u32 *out_len);
void do_no_compress(char *in, u32 in_len, char *out, u32 *out_len);
void do_lzma_compress(char *in, u32 in_len, char *out, u32 *out_len);
void do_nrv2b_compress(char *in, u32 in_len, char *out, u32 *out_len);
void compress_impossible(char *in, int in_len, char *out, int *out_len);
void do_no_compress(char *in, int in_len, char *out, int *out_len);
void do_lzma_compress(char *in, int in_len, char *out, int *out_len);
void do_nrv2b_compress(char *in, int in_len, char *out, int *out_len);
void uncompress_impossible(char *, char *, u32);
void do_no_uncompress(char *, char *, u32);
void do_lzma_uncompress(char *, char *, u32);
void do_nrv2b_uncompress(char *, char *, u32);
void uncompress_impossible(char *, char *, int);
void do_no_uncompress(char *, char *, int);
void do_lzma_uncompress(char *, char *, int);
void do_nrv2b_uncompress(char *, char *, int);
static compress_func compress_functions[] = {
do_no_compress,

View file

@ -40,7 +40,7 @@ static struct file *files = NULL;
* The default "compress impossible" hook to call when no other compression
* is used
*/
void compress_impossible(char *in, u32 in_len, char *out, u32 *out_len)
void compress_impossible(char *in, int in_len, char *out, int *out_len)
{
fprintf(stderr,
"The selected compression algorithm wasn't compiled in.\n");
@ -50,7 +50,7 @@ void compress_impossible(char *in, u32 in_len, char *out, u32 *out_len)
/**
* The default "compress" hook to call when no other compression is used
*/
void do_no_compress(char *in, u32 in_len, char *out, u32 *out_len)
void do_no_compress(char *in, int in_len, char *out, int *out_len)
{
memcpy(out, in, in_len);
out_len[0] = in_len;
@ -60,7 +60,7 @@ void do_no_compress(char *in, u32 in_len, char *out, u32 *out_len)
* The default "uncompress" hook to call when no other compression is used
*/
void do_no_uncompress(char *dst, char *src, u32 len)
void do_no_uncompress(char *dst, char *src, int len)
{
memcpy(dst, src, len);
}
@ -68,7 +68,7 @@ void do_no_uncompress(char *dst, char *src, u32 len)
/**
* The default "uncompress" hook to call when no other compression is used
*/
void uncompress_impossible(char *dst, char *src, u32 len)
void uncompress_impossible(char *dst, char *src, int len)
{
fprintf(stderr,
"Cannot uncompress data (algorithm not compiled in).\n");

View file

@ -58,7 +58,7 @@ int iself(char *filebuf);
/* Prototypes for in-memory LAR operations */
int lar_process_name(char *name, char **pfilename, char **ppathname,
enum compalgo *thisalgo);
u32 lar_compress(char *ptr, ssize_t size, char *temp, enum compalgo *thisalgo);
int lar_compress(char *ptr, int size, char *temp, enum compalgo *thisalgo);
int hlen(char *name);
int maxsize(struct lar *lar, char *name);
int lar_add_entry(struct lar *lar, char *pathname, void *data,

View file

@ -113,7 +113,7 @@ int output_elf_segments(struct lar *lar, char *name, char *filebuf,
ehdr->e_type,
ehdr->e_machine,
ehdr->e_version,
(void *)ehdr->e_entry,
(void *)(unsigned long)ehdr->e_entry,
ehdr->e_phoff,
ehdr->e_shoff,
ehdr->e_flags,
@ -155,7 +155,7 @@ int output_elf_segments(struct lar *lar, char *name, char *filebuf,
size = shdr[i].sh_size;
if (verbose()) {
fprintf(stderr, "(cleaned up) New section addr %p size 0x%#x\n",
(void *)shdr[i].sh_addr, (u32)shdr[i].sh_size);
(void *)(unsigned long)shdr[i].sh_addr, (u32)shdr[i].sh_size);
}
/* ok, copy it out */
sprintf(ename, "%s/segment%d", name, segment++);
@ -193,9 +193,9 @@ int output_elf_segments(struct lar *lar, char *name, char *filebuf,
}
if (verbose()) {
fprintf(stderr, "(cleaned up) New segment addr %p size 0x%#x offset 0x%x\n",
(void *)phdr[i].p_paddr, size, phdr[i].p_offset);
(void *)(unsigned long)phdr[i].p_paddr, size, phdr[i].p_offset);
fprintf(stderr, "Copy to %p from %p for %d bytes\n",
(unsigned char *)phdr[i].p_paddr,
(unsigned char *)(unsigned long)phdr[i].p_paddr,
&header[phdr[i].p_offset], size);
fprintf(stderr, "entry %ux loadaddr %ux\n",
entry, phdr[i].p_paddr);
@ -840,9 +840,9 @@ int maxsize(struct lar *lar, char *name)
* @param thisalgo pointer to algorithm -- this can be modified
* @return size of compressed data
*/
u32 lar_compress(char *ptr, ssize_t size, char *temp, enum compalgo *thisalgo)
int lar_compress(char *ptr, int size, char *temp, enum compalgo *thisalgo)
{
u32 complen;
int complen;
compress_functions[*thisalgo](ptr, size, temp, &complen);
if (complen >= size && (*thisalgo != none)) {

View file

@ -280,15 +280,15 @@ int main(int argc, char *argv[])
#else
extern "C" {
void do_lzma_compress(char *in, unsigned long in_len, char *out,
unsigned long *out_len) {
void do_lzma_compress(char *in, int in_len, char *out,
int *out_len) {
std::vector<unsigned char> result;
result = LZMACompress(std::vector<unsigned char>(in, in + in_len));
*out_len = result.size();
std::memcpy(out, &result[0], *out_len);
}
void do_lzma_uncompress(char *dst, char *src, unsigned long len) {
void do_lzma_uncompress(char *dst, char *src, int len) {
std::vector<unsigned char> result;
result = LZMADeCompress(std::vector<unsigned char>(src, src + len));
std::memcpy(dst, &result[0], result.size());

View file

@ -1304,10 +1304,11 @@ void Encode(void) /* compression */
#endif
#ifdef COMPACT
void do_nrv2b_compress(uint8_t *in, unsigned long in_len, uint8_t *out, unsigned long *out_len) {
*out_len = in_len + (in_len/8) + 256;
out = malloc(*out_len);
ucl_nrv2b_99_compress(in, in_len, out, out_len, 0 );
void do_nrv2b_compress(uint8_t *in, int in_len, uint8_t *out, int *out_len) {
unsigned long new_out_len = in_len + (in_len/8) + 256;
out = malloc(new_out_len);
ucl_nrv2b_99_compress(in, in_len, out, &new_out_len, 0 );
*out_len = (int) new_out_len;
}
#endif
@ -1346,7 +1347,7 @@ void do_nrv2b_compress(uint8_t *in, unsigned long in_len, uint8_t *out, unsigned
#endif
#ifdef COMPACT
void do_nrv2b_uncompress(uint8_t *dst, uint8_t *src, unsigned long len) {
void do_nrv2b_uncompress(uint8_t *dst, uint8_t *src, int len) {
unsigned long ilen = 0, olen = 0, last_m_off = 1;
uint32_t bb = 0;
unsigned bc = 0;