--- pgp/src/zunzip.c 2018/04/24 16:38:40 1.1.1.2 +++ pgp/src/zunzip.c 2018/04/24 16:39:22 1.1.1.3 @@ -15,7 +15,7 @@ /**********************/ 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() */ ULONG mask_bits[] = {0x00000000L, @@ -64,21 +64,19 @@ static byte *hold; 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 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 */ bits_left = 0; bitbuf = 0; @@ -93,10 +91,10 @@ 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) { + if ((incnt = read(zipfd, (char *) inbuf,INBUFSIZ)) <= 0) { fprintf(stderr, "error: unexpected end if input"); - return(-1); /* can still do next file */ - } + status = -1; /* can still do next file */ + } inptr = inbuf; /* Read in implode information */ @@ -104,10 +102,14 @@ int unzip( FILE *inFile, FILE *outFile ) /* Get compressed, uncompressed file sizes */ csize = ucsize = 1000000000L; /* Make sure we can read in anything */ - inflate(); /* Ftoomschk! */ + if (status == 0) + inflate(); /* Ftoomschk! */ /* Flush output buffer before returning */ - if (FlushOutput()) - return(-1); - return(0); + if (status == 0 && FlushOutput()) + status = -1; + free(inbuf); + free(outbuf); + inbuf = outbuf = outout = NULL; + return(status); }