--- pgp/src/zunzip.c 2018/04/24 16:37:53 1.1.1.1 +++ pgp/src/zunzip.c 2018/04/24 16:45:31 1.1.1.7 @@ -7,6 +7,7 @@ ---------------------------------------------------------------------------*/ #include "zunzip.h" /* includes, defines, and macros */ +#include "language.h" /* for LANG() */ #define VERSION "v4.20p BETA of 2-18-92" @@ -14,8 +15,11 @@ /* Global Variables */ /**********************/ +#if 0 longint csize; /* used by list_files(), ReadByte(): must be signed */ -longint ucsize; /* used by list_files(), unReduce(), unImplode() */ +static longint ucsize; /* used by list_files(), unReduce(), + unImplode() */ +#endif ULONG mask_bits[] = {0x00000000L, @@ -32,7 +36,8 @@ ULONG mask_bits[] = Input file variables: ---------------------------------------------------------------------------*/ -byte *inbuf = NULL, *inptr; /* input buffer (any size is legal) and pointer */ +byte *inbuf = NULL, *inptr; /* input buffer (any size is legal) + and pointer */ int incnt; ULONG bitbuf; @@ -62,23 +67,25 @@ static byte *hold; /* Main unzip code */ /*******************/ -int unzip( FILE *inFile, FILE *outFile ) /* return PK-type error code (except under VMS) */ +int unzip( FILE *inFile, FILE *outFile ) /* return PK-type error code + (except under VMS) */ { + int status = 0; outfd = fileno( outFile ); zipfd = fileno( inFile ); - if( inbuf == NULL ) - { - inbuf = (byte *) (malloc(INBUFSIZ + 4)); /* 4 extra for hold[] (below) */ - outbuf = (byte *) (malloc(OUTBUFSIZ + 1)); /* 1 extra for string termin. */ - outout = outbuf; /* else just point to outbuf */ - - if ((inbuf == NULL) || (outbuf == NULL) || (outout == NULL)) { - fprintf(stderr, "error: can't allocate unzip buffers\n"); - RETURN(4); /* 4-8: insufficient memory */ - } - hold = &inbuf[INBUFSIZ]; /* to check for boundary-spanning signatures */ - } + inbuf = (byte *) (malloc(INBUFSIZ + 4)); /* 4 extra for hold[] + (below) */ + outbuf = (byte *) (malloc(OUTBUFSIZ + 1)); /* 1 extra for string + termination */ + outout = outbuf; /* else just point to outbuf */ + + if ((inbuf == NULL) || (outbuf == NULL) || (outout == NULL)) { + fprintf(stderr, "error: can't allocate unzip buffers\n"); + RETURN(4); /* 4-8: insufficient memory */ + } + hold = &inbuf[INBUFSIZ]; /* to check for boundary-spanning + signatures */ bits_left = 0; bitbuf = 0; @@ -93,20 +100,27 @@ int unzip( FILE *inFile, FILE *outFile ) /* Go from high- to low-level I/O */ lseek( zipfd, ftell(inFile), SEEK_SET ); - if ((incnt = read(zipfd,inbuf,INBUFSIZ)) <= 0) { - fprintf(stderr, "error: unexpected end if input"); - return(-1); /* can still do next file */ - } + if ((incnt = read(zipfd, (char *) inbuf,INBUFSIZ)) <= 0) { + fprintf(stderr, LANG("\nERROR: unexpected end of compressed data input.\n")); + status = -1; /* can still do next file */ + } inptr = inbuf; +#if 0 /* Read in implode information */ csize = 1000L; /* Dummy size just to get input bits */ /* Get compressed, uncompressed file sizes */ csize = ucsize = 1000000000L; /* Make sure we can read in anything */ - inflate(); /* Ftoomschk! */ +#endif + if (status == 0) + status = inflate(); /* Ftoomschk! */ /* Flush output buffer before returning */ - FlushOutput(); - return(0); + if (status == 0 && FlushOutput()) + status = -1; + free(inbuf); + free(outbuf); + inbuf = outbuf = outout = NULL; + return(status); }