Clean up pg_dump coredumps caused by change of output formatting for

oidvector/int2vector.  pg_dump code was assuming that it would see
exactly FUNC_MAX_ARGS integers in the string returned by the backend.
That's no longer true.  (Perhaps that change wasn't such a good idea
after all --- will it break any other applications??)
This commit is contained in:
Tom Lane 2000-01-16 03:54:58 +00:00
parent 255e07e829
commit 97e82dc72c
3 changed files with 53 additions and 43 deletions

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.36 1999/12/27 15:42:43 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.37 2000/01/16 03:54:58 tgl Exp $
* *
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2 * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
* *
@ -156,13 +156,12 @@ findParentsByOid(TableInfo *tblinfo, int numTables,
} }
/* /*
* parseArgTypes * parseNumericArray
* parse a string of eight numbers delimited by spaces * parse a string of numbers delimited by spaces into a character array
* into a character array
*/ */
void void
parseArgTypes(char **argtypes, const char *str) parseNumericArray(const char *str, char **array, int arraysize)
{ {
int j, int j,
argNum; argNum;
@ -171,28 +170,37 @@ parseArgTypes(char **argtypes, const char *str)
argNum = 0; argNum = 0;
j = 0; j = 0;
while ((s = *str) != '\0') for (;;)
{ {
if (s == ' ') s = *str++;
if (s == ' ' || s == '\0')
{ {
temp[j] = '\0'; if (j > 0)
argtypes[argNum] = strdup(temp); {
argNum++; if (argNum >= arraysize)
j = 0; {
fprintf(stderr, "parseNumericArray: too many numbers\n");
exit(2);
}
temp[j] = '\0';
array[argNum++] = strdup(temp);
j = 0;
}
if (s == '\0')
break;
} }
else else
{ {
temp[j] = s; if (!isdigit(s) || j >= sizeof(temp)-1)
j++; {
fprintf(stderr, "parseNumericArray: bogus number\n");
exit(2);
}
temp[j++] = s;
} }
str++;
} }
if (j != 0) while (argNum < arraysize)
{ array[argNum++] = strdup("0");
temp[j] = '\0';
argtypes[argNum] = strdup(temp);
}
} }

View File

@ -21,7 +21,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.131 2000/01/10 17:14:40 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.132 2000/01/16 03:54:58 tgl Exp $
* *
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
* *
@ -1387,6 +1387,8 @@ getFuncs(int *numFuncs)
finfo = (FuncInfo *) malloc(ntups * sizeof(FuncInfo)); finfo = (FuncInfo *) malloc(ntups * sizeof(FuncInfo));
memset((char *) finfo, 0, ntups * sizeof(FuncInfo));
i_oid = PQfnumber(res, "oid"); i_oid = PQfnumber(res, "oid");
i_proname = PQfnumber(res, "proname"); i_proname = PQfnumber(res, "proname");
i_prolang = PQfnumber(res, "prolang"); i_prolang = PQfnumber(res, "prolang");
@ -1410,11 +1412,16 @@ getFuncs(int *numFuncs)
finfo[i].retset = (strcmp(PQgetvalue(res, i, i_proretset), "t") == 0); finfo[i].retset = (strcmp(PQgetvalue(res, i, i_proretset), "t") == 0);
finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs)); finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
finfo[i].lang = atoi(PQgetvalue(res, i, i_prolang)); finfo[i].lang = atoi(PQgetvalue(res, i, i_prolang));
finfo[i].usename = strdup(PQgetvalue(res, i, i_usename)); finfo[i].usename = strdup(PQgetvalue(res, i, i_usename));
if (finfo[i].nargs < 0 || finfo[i].nargs > FUNC_MAX_ARGS)
parseArgTypes(finfo[i].argtypes, PQgetvalue(res, i, i_proargtypes)); {
fprintf(stderr, "failed sanity check: %s has %d args\n",
finfo[i].proname, finfo[i].nargs);
exit(2);
}
parseNumericArray(PQgetvalue(res, i, i_proargtypes),
finfo[i].argtypes,
finfo[i].nargs);
finfo[i].dumped = 0; finfo[i].dumped = 0;
} }
@ -2045,6 +2052,8 @@ getIndices(int *numIndices)
indinfo = (IndInfo *) malloc(ntups * sizeof(IndInfo)); indinfo = (IndInfo *) malloc(ntups * sizeof(IndInfo));
memset((char *) indinfo, 0, ntups * sizeof(IndInfo));
i_indexrelname = PQfnumber(res, "indexrelname"); i_indexrelname = PQfnumber(res, "indexrelname");
i_indrelname = PQfnumber(res, "indrelname"); i_indrelname = PQfnumber(res, "indrelname");
i_indamname = PQfnumber(res, "indamname"); i_indamname = PQfnumber(res, "indamname");
@ -2059,10 +2068,12 @@ getIndices(int *numIndices)
indinfo[i].indrelname = strdup(PQgetvalue(res, i, i_indrelname)); indinfo[i].indrelname = strdup(PQgetvalue(res, i, i_indrelname));
indinfo[i].indamname = strdup(PQgetvalue(res, i, i_indamname)); indinfo[i].indamname = strdup(PQgetvalue(res, i, i_indamname));
indinfo[i].indproc = strdup(PQgetvalue(res, i, i_indproc)); indinfo[i].indproc = strdup(PQgetvalue(res, i, i_indproc));
parseArgTypes((char **) indinfo[i].indkey, parseNumericArray(PQgetvalue(res, i, i_indkey),
(const char *) PQgetvalue(res, i, i_indkey)); indinfo[i].indkey,
parseArgTypes((char **) indinfo[i].indclass, INDEX_MAX_KEYS);
(const char *) PQgetvalue(res, i, i_indclass)); parseNumericArray(PQgetvalue(res, i, i_indclass),
indinfo[i].indclass,
INDEX_MAX_KEYS);
indinfo[i].indisunique = strdup(PQgetvalue(res, i, i_indisunique)); indinfo[i].indisunique = strdup(PQgetvalue(res, i, i_indisunique));
} }
PQclear(res); PQclear(res);

View File

@ -5,7 +5,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_dump.h,v 1.44 2000/01/10 17:14:40 momjian Exp $ * $Id: pg_dump.h,v 1.45 2000/01/16 03:54:58 tgl Exp $
* *
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2 * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
* *
@ -25,14 +25,7 @@
#include "pqexpbuffer.h" #include "pqexpbuffer.h"
#include "catalog/pg_index.h" #include "catalog/pg_index.h"
/* /* The data structures used to store system catalog information */
* Very temporary hack --- remove this when all pg_dump's uses of it are gone!
*/
#define MAX_QUERY_SIZE (BLCKSZ*2)
/* The *Info data structures run-time C structures used to store
system catalog information */
typedef struct _typeInfo typedef struct _typeInfo
{ {
@ -61,11 +54,9 @@ typedef struct _funcInfo
char *proowner; char *proowner;
int lang; int lang;
int nargs; int nargs;
char *argtypes[FUNC_MAX_ARGS]; /* should be derived from obj/fmgr.h char *argtypes[FUNC_MAX_ARGS];
* instead of hardwired */
char *prorettype; char *prorettype;
int retset; /* 1 if the function returns a set, 0 int retset; /* 1 if the function returns a set, else 0 */
* otherwise */
char *prosrc; char *prosrc;
char *probin; char *probin;
char *usename; char *usename;
@ -198,7 +189,7 @@ extern int findFuncByName(FuncInfo *finfo, int numFuncs, const char *name);
extern int findTableByName(TableInfo *tbinfo, int numTables, const char *relname); extern int findTableByName(TableInfo *tbinfo, int numTables, const char *relname);
extern void check_conn_and_db(void); extern void check_conn_and_db(void);
extern void parseArgTypes(char **argtypes, const char *str); extern void parseNumericArray(const char *str, char **array, int arraysize);
/* /*
* version specific routines * version specific routines