View | Details | Raw Unified | Return to bug 24000 | Differences between
and this patch

Collapse All | Expand All

(-)a/libelf/elf_compress.c (-6 / +10 lines)
Lines 44-60 Link Here
44
/* Cleanup and return result.  Don't leak memory.  */
44
/* Cleanup and return result.  Don't leak memory.  */
45
static void *
45
static void *
46
do_deflate_cleanup (void *result, z_stream *z, void *out_buf,
46
do_deflate_cleanup (void *result, z_stream *z, void *out_buf,
47
                    int ei_data, Elf_Data *cdatap)
47
                    int ei_data, Elf_Data *data, Elf_Data *cdatap)
48
{
48
{
49
  deflateEnd (z);
49
  deflateEnd (z);
50
  free (out_buf);
50
  free (out_buf);
51
  if (ei_data != MY_ELFDATA)
51
  if (ei_data != MY_ELFDATA && data->d_size > 0)
52
    free (cdatap->d_buf);
52
    free (cdatap->d_buf);
53
  return result;
53
  return result;
54
}
54
}
55
55
56
#define deflate_cleanup(result) \
56
#define deflate_cleanup(result) \
57
    do_deflate_cleanup(result, &z, out_buf, ei_data, &cdata)
57
    do_deflate_cleanup(result, &z, out_buf, ei_data, data, &cdata)
58
58
59
/* Given a section, uses the (in-memory) Elf_Data to extract the
59
/* Given a section, uses the (in-memory) Elf_Data to extract the
60
   original data size (including the given header size) and data
60
   original data size (including the given header size) and data
Lines 127-133 __libelf_compress (Elf_Scn *scn, size_t hsize, int ei_data, Link Here
127
    {
127
    {
128
      /* Convert to raw if different endianess.  */
128
      /* Convert to raw if different endianess.  */
129
      cdata = *data;
129
      cdata = *data;
130
      if (ei_data != MY_ELFDATA)
130
      if (ei_data != MY_ELFDATA && data->d_size > 0)
131
	{
131
	{
132
	  /* Don't do this conversion in place, we might want to keep
132
	  /* Don't do this conversion in place, we might want to keep
133
	     the original data around, caller decides.  */
133
	     the original data around, caller decides.  */
Lines 188-194 __libelf_compress (Elf_Scn *scn, size_t hsize, int ei_data, Link Here
188
	}
188
	}
189
      while (z.avail_out == 0); /* Need more output buffer.  */
189
      while (z.avail_out == 0); /* Need more output buffer.  */
190
190
191
      if (ei_data != MY_ELFDATA)
191
      if (ei_data != MY_ELFDATA && data->d_size > 0)
192
	{
192
	{
193
	  free (cdata.d_buf);
193
	  free (cdata.d_buf);
194
	  cdata.d_buf = NULL;
194
	  cdata.d_buf = NULL;
Lines 220-226 __libelf_decompress (void *buf_in, size_t size_in, size_t size_out) Link Here
220
      return NULL;
220
      return NULL;
221
    }
221
    }
222
222
223
  void *buf_out = malloc (size_out);
223
  /* Malloc might return NULL when requestion zero size.  This is highly
224
     unlikely, it would only happen when the compression was forced.
225
     But we do need a non-NULL buffer to return and set as result.
226
     Just make sure to always allocate at least 1 byte.  */
227
  void *buf_out = malloc (size_out ?: 1);
224
  if (unlikely (buf_out == NULL))
228
  if (unlikely (buf_out == NULL))
225
    {
229
    {
226
      __libelf_seterrno (ELF_E_NOMEM);
230
      __libelf_seterrno (ELF_E_NOMEM);

Return to bug 24000