{
len = GET_U32(ptr);
ptr += 4;
- int res;
- byte *new_ptr;
- res = lizard_decompress_safe(ptr, buf->lizard, len, &new_ptr);
- if (res != (int) len)
- {
- if (res >= 0)
- errno = EINVAL;
+ byte *new_ptr = lizard_decompress_safe(ptr, buf->lizard, len);
+ if (!new_ptr)
return NULL;
- }
ptr = new_ptr;
end = ptr + len;
}
return 1;
}
-int
-lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length, byte **ptr)
+byte *
+lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length)
/* Decompresses in into buf, sets *ptr to the data, and returns the
* uncompressed length. If an error has occured, -1 is returned and errno is
* set. The buffer buf is automatically reallocated. SIGSEGV is caught in
lizard_realloc(buf, lock_offset);
volatile sh_sighandler_t old_handler = signal_handler[SIGSEGV];
signal_handler[SIGSEGV] = sigsegv_handler;
- int len;
+ byte *ptr;
if (!setjmp(safe_decompress_jump))
{
- *ptr = buf->ptr + buf->len - lock_offset;
- len = lizard_decompress(in, *ptr);
+ ptr = buf->ptr + buf->len - lock_offset;
+ int len = lizard_decompress(in, ptr);
+ if (len != (int) expected_length)
+ {
+ ptr = NULL;
+ errno = EINVAL;
+ }
}
else
{
- *ptr = NULL;
- len = -1;
+ ptr = NULL;
errno = EFAULT;
}
signal_handler[SIGSEGV] = old_handler;
- return len;
+ return ptr;
}
else
smaller_li = 0;
struct lizard_buffer *buf = lizard_alloc();
- byte *ptr;
- int lv = lizard_decompress_safe(mo, buf, crash ? smaller_li : li, &ptr);
- printf("-> %d ", lv);
- fflush(stdout);
- if (lv < 0)
- printf("err:%m ");
- else if (lv != li || memcmp(mi, ptr, li))
+ byte *ptr = lizard_decompress_safe(mo, buf, crash ? smaller_li : li);
+ if (!ptr)
+ printf("err: %m");
+ else if (memcmp(mi, ptr, li))
printf("WRONG");
else
printf("OK");
struct lizard_buffer *lizard_alloc(void);
void lizard_free(struct lizard_buffer *buf);
-int lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length, byte **ptr);
+byte *lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length);