[coreboot] r592 - in coreboot-v3/util: lar lzma nrv2b

svn at coreboot.org svn at coreboot.org
Wed Feb 13 18:30:49 CET 2008


Author: myles
Date: 2008-02-13 18:30:49 +0100 (Wed, 13 Feb 2008)
New Revision: 592

Modified:
   coreboot-v3/util/lar/lar.h
   coreboot-v3/util/lar/lib.c
   coreboot-v3/util/lar/lib.h
   coreboot-v3/util/lar/stream.c
   coreboot-v3/util/lzma/minilzma.cc
   coreboot-v3/util/nrv2b/nrv2b.c
Log:
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 at pel.cs.byu.edu>
Acked-by: Ronald G. Minnich <rminnich at gmail.com>


Modified: coreboot-v3/util/lar/lar.h
===================================================================
--- coreboot-v3/util/lar/lar.h	2008-02-13 16:43:32 UTC (rev 591)
+++ coreboot-v3/util/lar/lar.h	2008-02-13 17:30:49 UTC (rev 592)
@@ -93,18 +93,18 @@
 
 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,

Modified: coreboot-v3/util/lar/lib.c
===================================================================
--- coreboot-v3/util/lar/lib.c	2008-02-13 16:43:32 UTC (rev 591)
+++ coreboot-v3/util/lar/lib.c	2008-02-13 17:30:49 UTC (rev 592)
@@ -40,7 +40,7 @@
  * 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 @@
 /**
  * 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 @@
  * 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 @@
 /**
  * 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");

Modified: coreboot-v3/util/lar/lib.h
===================================================================
--- coreboot-v3/util/lar/lib.h	2008-02-13 16:43:32 UTC (rev 591)
+++ coreboot-v3/util/lar/lib.h	2008-02-13 17:30:49 UTC (rev 592)
@@ -58,7 +58,7 @@
 /* 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, 

Modified: coreboot-v3/util/lar/stream.c
===================================================================
--- coreboot-v3/util/lar/stream.c	2008-02-13 16:43:32 UTC (rev 591)
+++ coreboot-v3/util/lar/stream.c	2008-02-13 17:30:49 UTC (rev 592)
@@ -113,7 +113,7 @@
 		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 @@
 		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 @@
 		}
 		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 @@
  * @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)) {

Modified: coreboot-v3/util/lzma/minilzma.cc
===================================================================
--- coreboot-v3/util/lzma/minilzma.cc	2008-02-13 16:43:32 UTC (rev 591)
+++ coreboot-v3/util/lzma/minilzma.cc	2008-02-13 17:30:49 UTC (rev 592)
@@ -280,15 +280,15 @@
 #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());

Modified: coreboot-v3/util/nrv2b/nrv2b.c
===================================================================
--- coreboot-v3/util/nrv2b/nrv2b.c	2008-02-13 16:43:32 UTC (rev 591)
+++ coreboot-v3/util/nrv2b/nrv2b.c	2008-02-13 17:30:49 UTC (rev 592)
@@ -1304,10 +1304,11 @@
 #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 @@
 #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;





More information about the coreboot mailing list