source: rtems/cpukit/libmisc/untar/untar_tgz.c @ f1355f22

5
Last change on this file since f1355f22 was f1355f22, checked in by Sebastian Huber <sebastian.huber@…>, on 07/28/17 at 11:31:51

untar: Fix use of uninitialized variable

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <info@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/untar.h>
20
21int Untar_GzChunkContext_Init(
22  Untar_GzChunkContext *ctx,
23  void *inflateBuffer,
24  size_t inflateBufferSize
25)
26{
27  int ret;
28  int status = UNTAR_SUCCESSFUL;
29
30  Untar_ChunkContext_Init(&ctx->base);
31  ctx->inflateBuffer = inflateBuffer;
32  ctx->inflateBufferSize = inflateBufferSize;
33  memset(&ctx->strm, 0, sizeof(ctx->strm));
34  ret = inflateInit2(&ctx->strm, 32 + MAX_WBITS);
35  if (ret != Z_OK){
36    status = UNTAR_FAIL;
37  }
38  return status;
39}
40
41int Untar_FromGzChunk_Print(
42  Untar_GzChunkContext *ctx,
43  void *chunk,
44  size_t chunk_size,
45  const rtems_printer *printer
46)
47{
48  int untar_succesful;
49  int status;
50
51  ctx->strm.next_in = (Bytef *)chunk;
52  ctx->strm.avail_in = (size_t)chunk_size;
53
54    /* Inflate until output buffer is not full */
55  do {
56    ctx->strm.next_out = (Bytef *) ctx->inflateBuffer;
57    ctx->strm.avail_out = ctx->inflateBufferSize;
58
59    status = inflate(&ctx->strm, Z_NO_FLUSH);
60    if (status == Z_OK || status == Z_STREAM_END) {
61      size_t inflated_size =
62        ctx->inflateBufferSize - ctx->strm.avail_out;
63      untar_succesful = Untar_FromChunk_Print(&ctx->base,
64        ctx->inflateBuffer, inflated_size, NULL);
65      if (untar_succesful != UNTAR_SUCCESSFUL){
66        return untar_succesful;
67      }
68    } else {
69      untar_succesful = UNTAR_GZ_INFLATE_FAILED
70    }
71  } while (ctx->strm.avail_out == 0 && ctx->strm.avail_in > 0
72      && status == Z_OK);
73
74  if (status != Z_OK) {
75    if (untar_succesful != UNTAR_SUCCESSFUL){
76      rtems_printf(printer, "Untar not successful\n");
77    }
78
79    if (status != Z_STREAM_END) {
80      rtems_printf(printer, "Zlib inflate failed\n");
81    }
82
83    status = inflateEnd(&ctx->strm);
84    if (status != Z_OK) {
85      rtems_printf(printer, "Zlib inflate end failed\n");
86    }
87  }
88  return untar_succesful;
89}
90
91
Note: See TracBrowser for help on using the repository browser.