From 1134e13c17973837f02a28a35dc8dea871b80121 Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Mon, 28 Jun 2004 12:13:29 +0000 Subject: [PATCH] interface of lizard_decompress_safe() has been simplified --- lib/buck2obj.c | 10 ++-------- lib/lizard-safe.c | 20 ++++++++++++-------- lib/lizard-test.c | 11 ++++------- lib/lizard.h | 2 +- 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/lib/buck2obj.c b/lib/buck2obj.c index ba7efd57..f268e11a 100644 --- a/lib/buck2obj.c +++ b/lib/buck2obj.c @@ -141,15 +141,9 @@ obj_read_bucket(struct buck2obj_buf *buf, uns buck_type, uns buck_len, struct fa { 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; } diff --git a/lib/lizard-safe.c b/lib/lizard-safe.c index 9c347bd2..88e9aebd 100644 --- a/lib/lizard-safe.c +++ b/lib/lizard-safe.c @@ -71,8 +71,8 @@ sigsegv_handler(int signal UNUSED) 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 @@ -84,18 +84,22 @@ lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length, 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; } diff --git a/lib/lizard-test.c b/lib/lizard-test.c index 6ab7d8d0..ba78e022 100644 --- a/lib/lizard-test.c +++ b/lib/lizard-test.c @@ -101,13 +101,10 @@ main(int argc, char **argv) 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"); diff --git a/lib/lizard.h b/lib/lizard.h index bbd2a838..f81ea5f4 100644 --- a/lib/lizard.h +++ b/lib/lizard.h @@ -32,4 +32,4 @@ struct lizard_buffer; 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); -- 2.39.2