Skip to content

Commit

Permalink
pstore: Avoid size casts for 842 compression
Browse files Browse the repository at this point in the history
Instead of casting, make sure we don't end up with giant values and just
perform regular assignments with unsigned int instead of re-cast size_t.

Signed-off-by: Kees Cook <keescook@chromium.org>
  • Loading branch information
Kees Cook committed Mar 6, 2018
1 parent 239b716 commit 5559740
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions fs/pstore/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,27 +452,37 @@ static const struct pstore_zbackend backend_lz4hc = {
static int compress_842(const void *in, void *out, size_t inlen, size_t outlen)
{
int ret;
unsigned int size;

ret = sw842_compress(in, inlen, out, (unsigned int *)&outlen, workspace);
if (outlen > UINT_MAX)
return -EIO;
size = outlen;

ret = sw842_compress(in, inlen, out, &size, workspace);
if (ret) {
pr_err("sw842_compress error; compression failed!\n");
return ret;
}

return outlen;
return size;
}

static int decompress_842(void *in, void *out, size_t inlen, size_t outlen)
{
int ret;
unsigned int size;

ret = sw842_decompress(in, inlen, out, (unsigned int *)&outlen);
if (outlen > UINT_MAX)
return -EIO;
size = outlen;

ret = sw842_decompress(in, inlen, out, &size);
if (ret) {
pr_err("sw842_decompress error, ret = %d!\n", ret);
return ret;
}

return outlen;
return size;
}

static void allocate_842(void)
Expand Down

0 comments on commit 5559740

Please sign in to comment.