Skip to content

Commit 43f6ab8

Browse files
Jan WieckJan Wieck
authored andcommitted
Please find attached a patch for the pg_dump directory which addresses:
- The problems Jan reported - incompatibility with configure (now uses HAVE_LIBZ instead of HAVE_ZLIB) - a problem in auto-detecting archive file format on piped archives Philip Warner
1 parent 2a225eb commit 43f6ab8

File tree

6 files changed

+69
-68
lines changed

6 files changed

+69
-68
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
118118
_printTocEntry(AH, te, ropt);
119119

120120
if (AH->PrintTocDataPtr != NULL && (reqs & 2) != 0) {
121-
#ifndef HAVE_ZLIB
121+
#ifndef HAVE_LIBZ
122122
if (AH->compression != 0)
123123
die_horribly("%s: Unable to restore data from a compressed archive\n", progname);
124124
#endif
@@ -415,11 +415,14 @@ int archprintf(Archive* AH, const char *fmt, ...)
415415
{
416416
char *p = NULL;
417417
va_list ap;
418-
int bSize = strlen(fmt) + 1024;
418+
int bSize = strlen(fmt) + 256;
419419
int cnt = -1;
420420

421421
va_start(ap, fmt);
422-
while (cnt < 0) {
422+
423+
/* This is paranoid: deal with the possibility that vsnprintf is willing to ignore trailing null */
424+
/* or returns > 0 even if string does not fit. It may be the case that it returns cnt = bufsize */
425+
while (cnt < 0 || cnt >= (bSize-1) ) {
423426
if (p != NULL) free(p);
424427
bSize *= 2;
425428
if ((p = malloc(bSize)) == NULL)
@@ -443,7 +446,7 @@ int archprintf(Archive* AH, const char *fmt, ...)
443446
OutputContext SetOutput(ArchiveHandle* AH, char *filename, int compression)
444447
{
445448
OutputContext sav;
446-
#ifdef HAVE_ZLIB
449+
#ifdef HAVE_LIBZ
447450
char fmode[10];
448451
#endif
449452
int fn = 0;
@@ -464,7 +467,7 @@ OutputContext SetOutput(ArchiveHandle* AH, char *filename, int compression)
464467
}
465468

466469
/* If compression explicitly requested, use gzopen */
467-
#ifdef HAVE_ZLIB
470+
#ifdef HAVE_LIBZ
468471
if (compression != 0)
469472
{
470473
sprintf(fmode, "wb%d", compression);
@@ -482,7 +485,7 @@ OutputContext SetOutput(ArchiveHandle* AH, char *filename, int compression)
482485
AH->OF = fopen(filename, PG_BINARY_W);
483486
}
484487
AH->gzOut = 0;
485-
#ifdef HAVE_ZLIB
488+
#ifdef HAVE_LIBZ
486489
}
487490
#endif
488491

@@ -509,11 +512,13 @@ int ahprintf(ArchiveHandle* AH, const char *fmt, ...)
509512
{
510513
char *p = NULL;
511514
va_list ap;
512-
int bSize = strlen(fmt) + 1024; /* Should be enough */
515+
int bSize = strlen(fmt) + 256; /* Should be enough */
513516
int cnt = -1;
514517

515518
va_start(ap, fmt);
516-
while (cnt < 0) {
519+
/* This is paranoid: deal with the possibility that vsnprintf is willing to ignore trailing null */
520+
/* or returns > 0 even if string does not fit. It may be the case that it returns cnt = bufsize */
521+
while (cnt < 0 || cnt >= (bSize - 1) ) {
517522
if (p != NULL) free(p);
518523
bSize *= 2;
519524
p = (char*)malloc(bSize);
@@ -681,6 +686,7 @@ int _discoverArchiveFormat(ArchiveHandle* AH)
681686
int cnt;
682687
int wantClose = 0;
683688

689+
684690
if (AH->fSpec) {
685691
wantClose = 1;
686692
fh = fopen(AH->fSpec, PG_BINARY_R);
@@ -693,16 +699,11 @@ int _discoverArchiveFormat(ArchiveHandle* AH)
693699

694700
cnt = fread(sig, 1, 5, fh);
695701

696-
if (cnt != 5) {
697-
fprintf(stderr, "Archiver: input file is too short, or is unreadable\n");
698-
exit(1);
699-
}
702+
if (cnt != 5)
703+
die_horribly("%s: input file is too short, or is unreadable\n", progname);
700704

701705
if (strncmp(sig, "PGDMP", 5) != 0)
702-
{
703-
fprintf(stderr, "Archiver: input file does not appear to be a valid archive\n");
704-
exit(1);
705-
}
706+
die_horribly("%s: input file does not appear to be a valid archive\n", progname);
706707

707708
AH->vmaj = fgetc(fh);
708709
AH->vmin = fgetc(fh);
@@ -739,7 +740,7 @@ static ArchiveHandle* _allocAH(const char* FileSpec, ArchiveFormat fmt,
739740
int compression, ArchiveMode mode) {
740741
ArchiveHandle* AH;
741742

742-
AH = (ArchiveHandle*)malloc(sizeof(ArchiveHandle));
743+
AH = (ArchiveHandle*)calloc(1, sizeof(ArchiveHandle));
743744
if (!AH)
744745
die_horribly("Archiver: Could not allocate archive handle\n");
745746

@@ -759,7 +760,7 @@ static ArchiveHandle* _allocAH(const char* FileSpec, ArchiveFormat fmt,
759760
AH->currToc = NULL;
760761
AH->currUser = "";
761762

762-
AH->toc = (TocEntry*)malloc(sizeof(TocEntry));
763+
AH->toc = (TocEntry*)calloc(1, sizeof(TocEntry));
763764
if (!AH->toc)
764765
die_horribly("Archiver: Could not allocate TOC header\n");
765766

@@ -996,7 +997,7 @@ void WriteHead(ArchiveHandle* AH)
996997
(*AH->WriteBytePtr)(AH, AH->intSize);
997998
(*AH->WriteBytePtr)(AH, AH->format);
998999

999-
#ifndef HAVE_ZLIB
1000+
#ifndef HAVE_LIBZ
10001001
if (AH->compression != 0)
10011002
fprintf(stderr, "%s: WARNING - requested compression not available in this installation - "
10021003
"archive will be uncompressed \n", progname);
@@ -1016,43 +1017,43 @@ void ReadHead(ArchiveHandle* AH)
10161017
char tmpMag[7];
10171018
int fmt;
10181019

1019-
if (AH->readHeader)
1020-
return;
1020+
if (!AH->readHeader) {
10211021

1022-
(*AH->ReadBufPtr)(AH, tmpMag, 5);
1022+
(*AH->ReadBufPtr)(AH, tmpMag, 5);
10231023

1024-
if (strncmp(tmpMag,"PGDMP", 5) != 0)
1025-
die_horribly("Archiver: Did not fing magic PGDMP in file header\n");
1024+
if (strncmp(tmpMag,"PGDMP", 5) != 0)
1025+
die_horribly("Archiver: Did not fing magic PGDMP in file header\n");
10261026

1027-
AH->vmaj = (*AH->ReadBytePtr)(AH);
1028-
AH->vmin = (*AH->ReadBytePtr)(AH);
1027+
AH->vmaj = (*AH->ReadBytePtr)(AH);
1028+
AH->vmin = (*AH->ReadBytePtr)(AH);
10291029

1030-
if (AH->vmaj > 1 || ( (AH->vmaj == 1) && (AH->vmin > 0) ) ) /* Version > 1.0 */
1031-
{
1032-
AH->vrev = (*AH->ReadBytePtr)(AH);
1033-
} else {
1034-
AH->vrev = 0;
1035-
}
1030+
if (AH->vmaj > 1 || ( (AH->vmaj == 1) && (AH->vmin > 0) ) ) /* Version > 1.0 */
1031+
{
1032+
AH->vrev = (*AH->ReadBytePtr)(AH);
1033+
} else {
1034+
AH->vrev = 0;
1035+
}
10361036

1037-
AH->version = ( (AH->vmaj * 256 + AH->vmin) * 256 + AH->vrev ) * 256 + 0;
1037+
AH->version = ( (AH->vmaj * 256 + AH->vmin) * 256 + AH->vrev ) * 256 + 0;
10381038

10391039

1040-
if (AH->version < K_VERS_1_0 || AH->version > K_VERS_MAX)
1041-
die_horribly("Archiver: unsupported version (%d.%d) in file header\n", AH->vmaj, AH->vmin);
1040+
if (AH->version < K_VERS_1_0 || AH->version > K_VERS_MAX)
1041+
die_horribly("Archiver: unsupported version (%d.%d) in file header\n", AH->vmaj, AH->vmin);
10421042

1043-
AH->intSize = (*AH->ReadBytePtr)(AH);
1044-
if (AH->intSize > 32)
1045-
die_horribly("Archiver: sanity check on integer size (%d) failes\n", AH->intSize);
1043+
AH->intSize = (*AH->ReadBytePtr)(AH);
1044+
if (AH->intSize > 32)
1045+
die_horribly("Archiver: sanity check on integer size (%d) failes\n", AH->intSize);
10461046

1047-
if (AH->intSize > sizeof(int))
1048-
fprintf(stderr, "\nWARNING: Backup file was made on a machine with larger integers, "
1049-
"some operations may fail\n");
1047+
if (AH->intSize > sizeof(int))
1048+
fprintf(stderr, "\nWARNING: Backup file was made on a machine with larger integers, "
1049+
"some operations may fail\n");
10501050

1051-
fmt = (*AH->ReadBytePtr)(AH);
1051+
fmt = (*AH->ReadBytePtr)(AH);
10521052

1053-
if (AH->format != fmt)
1054-
die_horribly("Archiver: expected format (%d) differs from format found in file (%d)\n",
1055-
AH->format, fmt);
1053+
if (AH->format != fmt)
1054+
die_horribly("Archiver: expected format (%d) differs from format found in file (%d)\n",
1055+
AH->format, fmt);
1056+
}
10561057

10571058
if (AH->version >= K_VERS_1_2)
10581059
{
@@ -1061,8 +1062,9 @@ void ReadHead(ArchiveHandle* AH)
10611062
AH->compression = Z_DEFAULT_COMPRESSION;
10621063
}
10631064

1064-
#ifndef HAVE_ZLIB
1065-
fprintf(stderr, "%s: WARNING - archive is compressed - any data will not be available\n", progname);
1065+
#ifndef HAVE_LIBZ
1066+
if (AH->compression != 0)
1067+
fprintf(stderr, "%s: WARNING - archive is compressed - any data will not be available\n", progname);
10661068
#endif
10671069

10681070
}

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#include <stdio.h>
3232

33-
#ifdef HAVE_ZLIB
33+
#ifdef HAVE_LIBZ
3434
#include <zlib.h>
3535
#define GZCLOSE(fh) gzclose(fh)
3636
#define GZWRITE(p, s, n, fh) gzwrite(fh, p, n * s)
@@ -54,7 +54,7 @@ typedef z_stream *z_streamp;
5454

5555
#define K_VERS_MAJOR 1
5656
#define K_VERS_MINOR 2
57-
#define K_VERS_REV 0
57+
#define K_VERS_REV 1
5858

5959
/* Some important version numbers (checked in code) */
6060
#define K_VERS_1_0 (( (1 * 256 + 0) * 256 + 0) * 256 + 0)

src/bin/pg_dump/pg_backup_custom.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static void _StartData(ArchiveHandle* AH, TocEntry* te)
200200

201201
WriteInt(AH, te->id); /* For sanity check */
202202

203-
#ifdef HAVE_ZLIB
203+
#ifdef HAVE_LIBZ
204204

205205
if (AH->compression < 0 || AH->compression > 9) {
206206
AH->compression = Z_DEFAULT_COMPRESSION;
@@ -230,7 +230,7 @@ static int _DoDeflate(ArchiveHandle* AH, lclContext* ctx, int flush)
230230
{
231231
z_streamp zp = ctx->zp;
232232

233-
#ifdef HAVE_ZLIB
233+
#ifdef HAVE_LIBZ
234234
char* out = ctx->zlibOut;
235235
int res = Z_OK;
236236

@@ -268,14 +268,14 @@ static int _DoDeflate(ArchiveHandle* AH, lclContext* ctx, int flush)
268268
ctx->filePos += zp->avail_in;
269269
zp->avail_in = 0;
270270
} else {
271-
#ifdef HAVE_ZLIB
271+
#ifdef HAVE_LIBZ
272272
if (flush == Z_FINISH)
273273
res = Z_STREAM_END;
274274
#endif
275275
}
276276

277277

278-
#ifdef HAVE_ZLIB
278+
#ifdef HAVE_LIBZ
279279
}
280280

281281
return res;
@@ -305,7 +305,7 @@ static void _EndData(ArchiveHandle* AH, TocEntry* te)
305305
lclContext* ctx = (lclContext*)AH->formatData;
306306
lclTocEntry* tctx = (lclTocEntry*) te->formatData;
307307

308-
#ifdef HAVE_ZLIB
308+
#ifdef HAVE_LIBZ
309309
z_streamp zp = ctx->zp;
310310
int res;
311311

@@ -385,7 +385,7 @@ static void _PrintData(ArchiveHandle* AH)
385385
char* in = ctx->zlibIn;
386386
int cnt;
387387

388-
#ifdef HAVE_ZLIB
388+
#ifdef HAVE_LIBZ
389389

390390
int res;
391391
char* out = ctx->zlibOut;
@@ -424,7 +424,7 @@ static void _PrintData(ArchiveHandle* AH)
424424
zp->next_in = in;
425425
zp->avail_in = blkLen;
426426

427-
#ifdef HAVE_ZLIB
427+
#ifdef HAVE_LIBZ
428428

429429
if (AH->compression != 0) {
430430

@@ -443,14 +443,14 @@ static void _PrintData(ArchiveHandle* AH)
443443
ahwrite(in, 1, zp->avail_in, AH);
444444
zp->avail_in = 0;
445445

446-
#ifdef HAVE_ZLIB
446+
#ifdef HAVE_LIBZ
447447
}
448448
#endif
449449

450450
blkLen = ReadInt(AH);
451451
}
452452

453-
#ifdef HAVE_ZLIB
453+
#ifdef HAVE_LIBZ
454454
if (AH->compression != 0)
455455
{
456456
zp->next_in = NULL;

src/bin/pg_dump/pg_backup_files.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef struct {
5454
} lclContext;
5555

5656
typedef struct {
57-
#ifdef HAVE_ZLIB
57+
#ifdef HAVE_LIBZ
5858
gzFile *FH;
5959
#else
6060
FILE *FH;
@@ -133,7 +133,7 @@ static void _ArchiveEntry(ArchiveHandle* AH, TocEntry* te)
133133

134134
ctx = (lclTocEntry*)malloc(sizeof(lclTocEntry));
135135
if (te->dataDumper) {
136-
#ifdef HAVE_ZLIB
136+
#ifdef HAVE_LIBZ
137137
if (AH->compression == 0) {
138138
sprintf(fn, "%d.dat", te->id);
139139
} else {
@@ -192,7 +192,7 @@ static void _StartData(ArchiveHandle* AH, TocEntry* te)
192192

193193
sprintf(fmode, "wb%d", AH->compression);
194194

195-
#ifdef HAVE_ZLIB
195+
#ifdef HAVE_LIBZ
196196
tctx->FH = gzopen(tctx->filename, fmode);
197197
#else
198198
tctx->FH = fopen(tctx->filename, PG_BINARY_W);
@@ -229,7 +229,7 @@ static void _PrintTocData(ArchiveHandle* AH, TocEntry* te, RestoreOptions *ropt)
229229
if (!tctx->filename)
230230
return;
231231

232-
#ifdef HAVE_ZLIB
232+
#ifdef HAVE_LIBZ
233233
AH->FH = gzopen(tctx->filename,"rb");
234234
#else
235235
AH->FH = fopen(tctx->filename,PG_BINARY_R);

src/bin/pg_dump/pg_dump.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.156 2000/07/04 16:57:49 momjian Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.157 2000/07/06 18:39:39 wieck Exp $
2626
*
2727
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828
*
@@ -3202,10 +3202,9 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
32023202
{
32033203

32043204
/* Skip VIEW relations */
3205-
3206-
/*
3207-
* if (isViewRule(tblinfo[i].relname)) continue;
3208-
*/
3205+
3206+
/* if (isViewRule(tblinfo[i].relname)) continue; */
3207+
32093208

32103209
parentRels = tblinfo[i].parentRels;
32113210
numParents = tblinfo[i].numParents;

src/bin/pg_dump/pg_restore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int main(int argc, char **argv)
108108
char *progname;
109109
int c;
110110
Archive* AH;
111-
char *fileSpec;
111+
char *fileSpec = NULL;
112112

113113
opts = NewRestoreOptions();
114114

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy