aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhpa <hpa>2003-11-18 19:20:20 +0000
committerhpa <hpa>2003-11-18 19:20:20 +0000
commit319cfdb6a04d0936385cf8876e373f42d6298be2 (patch)
tree631c570739dd8e744df5c8f4c9d8c5215698e54d
parent7aabe805b949c456fde27dee0c020e66c23d7777 (diff)
downloadsyslinux-elf-319cfdb6a04d0936385cf8876e373f42d6298be2.tar.gz
syslinux-elf-319cfdb6a04d0936385cf8876e373f42d6298be2.tar.xz
syslinux-elf-319cfdb6a04d0936385cf8876e373f42d6298be2.zip
Add debugging code for input buffer underrunsyslinux-2.07-pre6
-rw-r--r--memdisk/e820test.c20
-rw-r--r--memdisk/inflate.c12
-rw-r--r--memdisk/unzip.c46
3 files changed, 52 insertions, 26 deletions
diff --git a/memdisk/e820test.c b/memdisk/e820test.c
index eefdf517..cadd2a7f 100644
--- a/memdisk/e820test.c
+++ b/memdisk/e820test.c
@@ -17,6 +17,7 @@
* Test of INT 15:E820 canonicalization/manipulation routine
*/
+#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
@@ -47,17 +48,22 @@ int main(int argc, char *argv[])
{
uint64_t start, len;
uint32_t type;
+ char line[BUFSIZ], *p;
e820map_init();
printranges();
- while ( scanf("%llx %llx %d", &start, &len, &type) == 3 ) {
- putchar('\n');
- printf("%016llx %016llx %d <-\n", start, len, type);
- putchar('\n');
- insertrange(start, len, type);
- printranges();
- }
+ while ( fgets(line, BUFSIZ, stdin) ) {
+ p = strchr(line, ':');
+ p = p ? p+1 : line;
+ if ( sscanf(p, " %llx %llx %d", &start, &len, &type) == 3 ) {
+ putchar('\n');
+ printf("%016llx %016llx %d <-\n", start, len, type);
+ putchar('\n');
+ insertrange(start, len, type);
+ printranges();
+ }
+ }
parse_mem();
diff --git a/memdisk/inflate.c b/memdisk/inflate.c
index a07d6f54..6c25ee68 100644
--- a/memdisk/inflate.c
+++ b/memdisk/inflate.c
@@ -978,7 +978,7 @@ STATIC int inflate()
*/
while (bk >= 8) {
bk -= 8;
- inptr--;
+ inbuf--;
}
/* flush out slide */
@@ -1093,10 +1093,12 @@ int gunzip(void)
error("Input has invalid flags");
return -1;
}
- (ulg)get_byte(); /* Get timestamp */
- ((ulg)get_byte()) << 8;
- ((ulg)get_byte()) << 16;
- ((ulg)get_byte()) << 24;
+
+ /* Ignore timestamp */
+ (void)get_byte();
+ (void)get_byte();
+ (void)get_byte();
+ (void)get_byte();
(void)get_byte(); /* Ignore extra flags for the moment */
(void)get_byte(); /* Ignore OS type for the moment */
diff --git a/memdisk/unzip.c b/memdisk/unzip.c
index 94f56e43..a3a7f124 100644
--- a/memdisk/unzip.c
+++ b/memdisk/unzip.c
@@ -28,15 +28,18 @@ typedef uint8_t uch;
typedef uint16_t ush;
typedef uint32_t ulg;
-#define WSIZE 0x8000 /* Window size must be at least 32k, */
+#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */
-static uch *inbuf; /* input buffer */
-static uch window[WSIZE]; /* Sliding window buffer */
+static uch *inbuf; /* input pointer */
+static uch window[WSIZE]; /* sliding output window buffer */
-static unsigned insize; /* valid bytes in inbuf */
-static unsigned inptr; /* index of next byte to be processed in inbuf */
-static unsigned outcnt; /* bytes in output buffer */
+static unsigned insize; /* total input bytes read */
+static unsigned inbytes; /* valid bytes in inbuf */
+static unsigned outcnt; /* bytes in output buffer */
+
+/* This is here to try to debug strange errors seen on some machines. */
+static ulg in_crc; /* crc of input bytes as read */
/* gzip flag byte */
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
@@ -47,8 +50,6 @@ static unsigned outcnt; /* bytes in output buffer */
#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
#define RESERVED 0xC0 /* bit 6,7: reserved */
-#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
/* Diagnostic functions */
#ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);}
@@ -71,7 +72,23 @@ static void flush_window(void);
static void error(char *m);
static void gzip_mark(void **);
static void gzip_release(void **);
-
+
+extern ulg crc_32_tab[256];
+
+/* Get byte from input buffer */
+static inline uch get_byte(void)
+{
+ if ( inbytes ) {
+ uch b = *inbuf++;
+ inbytes--;
+ in_crc = crc_32_tab[(in_crc ^ b) & 0xff] ^ (in_crc >> 8);
+
+ return b;
+ } else {
+ return fill_inbuf(); /* Input buffer underrun */
+ }
+}
+
static ulg bytes_out = 0; /* Number of bytes output */
static uch *output_data; /* Output data pointer */
static ulg output_size; /* Number of output bytes expected */
@@ -123,8 +140,9 @@ static int fill_inbuf(void)
{
/* This should never happen. We have already pointed the algorithm
to all the data we have. */
- error("ran out of input data");
- return 0;
+ printf("failed\nDecompression error: ran out of input data, cksum = %lu %u\n",
+ in_crc^0xffffffffUL, insize);
+ die();
}
/* ===========================================================================
@@ -144,7 +162,7 @@ static void flush_window(void)
out = output_data;
for (n = 0; n < outcnt; n++) {
ch = *out++ = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
+ c = crc_32_tab[(c ^ ch) & 0xff] ^ (c >> 8);
}
crc = c;
output_data = out;
@@ -155,7 +173,6 @@ static void flush_window(void)
static void error(char *x)
{
printf("failed\nDecompression error: %s\n", x);
- puts(x);
die();
}
@@ -176,8 +193,9 @@ void *unzip(void *indata, unsigned long zbytes, void *target)
free_mem_end_ptr = free_mem_ptr + 0x10000;
/* Set up input buffer */
+ in_crc = 0xffffffffUL;
inbuf = indata;
- insize = zbytes;
+ insize = inbytes = zbytes;
/* Set up output buffer */
outcnt = 0;