mirror of
https://github.com/libretro/RetroArch
synced 2025-04-18 14:42:30 +00:00
(trans_stream_zlib.c) Try to prevent null pointer dereferences
This commit is contained in:
parent
dc2664a4ef
commit
f5dedd673f
@ -29,15 +29,16 @@
|
|||||||
|
|
||||||
struct zlib_trans_stream
|
struct zlib_trans_stream
|
||||||
{
|
{
|
||||||
z_stream z;
|
|
||||||
int ex; /* window_bits or level */
|
|
||||||
bool inited;
|
bool inited;
|
||||||
|
int ex; /* window_bits or level */
|
||||||
|
z_stream z;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void *zlib_deflate_stream_new(void)
|
static void *zlib_deflate_stream_new(void)
|
||||||
{
|
{
|
||||||
struct zlib_trans_stream *ret = (struct zlib_trans_stream*)calloc(1, sizeof(struct zlib_trans_stream));
|
struct zlib_trans_stream *ret = (struct zlib_trans_stream*)calloc(1, sizeof(struct zlib_trans_stream));
|
||||||
if (ret)
|
if (!ret)
|
||||||
|
return NULL;
|
||||||
ret->ex = 9;
|
ret->ex = 9;
|
||||||
return (void *) ret;
|
return (void *) ret;
|
||||||
}
|
}
|
||||||
@ -45,7 +46,8 @@ static void *zlib_deflate_stream_new(void)
|
|||||||
static void *zlib_inflate_stream_new(void)
|
static void *zlib_inflate_stream_new(void)
|
||||||
{
|
{
|
||||||
struct zlib_trans_stream *ret = (struct zlib_trans_stream*)calloc(1, sizeof(struct zlib_trans_stream));
|
struct zlib_trans_stream *ret = (struct zlib_trans_stream*)calloc(1, sizeof(struct zlib_trans_stream));
|
||||||
if (ret)
|
if (!ret)
|
||||||
|
return NULL;
|
||||||
ret->ex = MAX_WBITS;
|
ret->ex = MAX_WBITS;
|
||||||
return (void *) ret;
|
return (void *) ret;
|
||||||
}
|
}
|
||||||
@ -53,6 +55,8 @@ static void *zlib_inflate_stream_new(void)
|
|||||||
static void zlib_deflate_stream_free(void *data)
|
static void zlib_deflate_stream_free(void *data)
|
||||||
{
|
{
|
||||||
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
|
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
|
||||||
|
if (!z)
|
||||||
|
return;
|
||||||
if (z->inited)
|
if (z->inited)
|
||||||
deflateEnd(&z->z);
|
deflateEnd(&z->z);
|
||||||
free(z);
|
free(z);
|
||||||
@ -73,6 +77,7 @@ static bool zlib_deflate_define(void *data, const char *prop, uint32_t val)
|
|||||||
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
|
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
|
||||||
if (string_is_equal_fast(prop, "level", 5))
|
if (string_is_equal_fast(prop, "level", 5))
|
||||||
{
|
{
|
||||||
|
if (z)
|
||||||
z->ex = (int) val;
|
z->ex = (int) val;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -84,6 +89,7 @@ static bool zlib_inflate_define(void *data, const char *prop, uint32_t val)
|
|||||||
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
|
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
|
||||||
if (string_is_equal_fast(prop, "window_bits", 11))
|
if (string_is_equal_fast(prop, "window_bits", 11))
|
||||||
{
|
{
|
||||||
|
if (z)
|
||||||
z->ex = (int) val;
|
z->ex = (int) val;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -139,9 +145,10 @@ static bool zlib_deflate_trans(
|
|||||||
uint32_t *rd, uint32_t *wn,
|
uint32_t *rd, uint32_t *wn,
|
||||||
enum trans_stream_error *error)
|
enum trans_stream_error *error)
|
||||||
{
|
{
|
||||||
int zret;
|
int zret = 0;
|
||||||
bool ret;
|
bool ret = false;
|
||||||
uint32_t pre_avail_in, pre_avail_out;
|
uint32_t pre_avail_in = 0;
|
||||||
|
uint32_t pre_avail_out = 0;
|
||||||
struct zlib_trans_stream *zt = (struct zlib_trans_stream *) data;
|
struct zlib_trans_stream *zt = (struct zlib_trans_stream *) data;
|
||||||
z_stream *z = &zt->z;
|
z_stream *z = &zt->z;
|
||||||
|
|
||||||
@ -202,8 +209,9 @@ static bool zlib_inflate_trans(
|
|||||||
enum trans_stream_error *error)
|
enum trans_stream_error *error)
|
||||||
{
|
{
|
||||||
int zret;
|
int zret;
|
||||||
bool ret;
|
bool ret = false;
|
||||||
uint32_t pre_avail_in, pre_avail_out;
|
uint32_t pre_avail_in = 0;
|
||||||
|
uint32_t pre_avail_out = 0;
|
||||||
struct zlib_trans_stream *zt = (struct zlib_trans_stream *) data;
|
struct zlib_trans_stream *zt = (struct zlib_trans_stream *) data;
|
||||||
z_stream *z = &zt->z;
|
z_stream *z = &zt->z;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user