X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fjournal%2Fcompress.c;h=a4427be75a04fd97e8846bea9f9be7ae2640d624;hp=ff906581f0e4755c21d1c480e19e8002552d1f73;hb=236af516b866473c22f980b556a2d7535cef4d9b;hpb=e4e61fdbed832a2bd3f5dcd47623872d9081599c diff --git a/src/journal/compress.c b/src/journal/compress.c index ff906581f..a4427be75 100644 --- a/src/journal/compress.c +++ b/src/journal/compress.c @@ -6,16 +6,16 @@ Copyright 2011 Lennart Poettering systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. systemd is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . ***/ @@ -24,6 +24,7 @@ #include #include +#include "macro.h" #include "compress.h" bool compress_blob(const void *src, uint64_t src_size, void *dst, uint64_t *dst_size) { @@ -66,10 +67,11 @@ fail: } bool uncompress_blob(const void *src, uint64_t src_size, - void **dst, uint64_t *dst_alloc_size, uint64_t* dst_size) { + void **dst, uint64_t *dst_alloc_size, uint64_t* dst_size, uint64_t dst_max) { lzma_stream s = LZMA_STREAM_INIT; lzma_ret ret; + uint64_t space; bool b = false; assert(src); @@ -98,7 +100,8 @@ bool uncompress_blob(const void *src, uint64_t src_size, s.avail_in = src_size; s.next_out = *dst; - s.avail_out = *dst_alloc_size; + space = dst_max > 0 ? MIN(*dst_alloc_size, dst_max) : *dst_alloc_size; + s.avail_out = space; for (;;) { void *p; @@ -111,18 +114,23 @@ bool uncompress_blob(const void *src, uint64_t src_size, if (ret != LZMA_OK) goto fail; - p = realloc(*dst, *dst_alloc_size*2); + if (dst_max > 0 && (space - s.avail_out) >= dst_max) + break; + + p = realloc(*dst, space*2); if (!p) goto fail; s.next_out = (uint8_t*) p + ((uint8_t*) s.next_out - (uint8_t*) *dst); - s.avail_out += *dst_alloc_size; + s.avail_out += space; + + space *= 2; *dst = p; - *dst_alloc_size *= 2; + *dst_alloc_size = space; } - *dst_size = *dst_alloc_size - s.avail_out; + *dst_size = space - s.avail_out; b = true; fail: