From 97e82dc72c0cabf72bcfe760073995b89d4a73d6 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 16 Jan 2000 03:54:58 +0000 Subject: [PATCH] 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??) --- src/bin/pg_dump/common.c | 48 +++++++++++++++++++++++---------------- src/bin/pg_dump/pg_dump.c | 29 +++++++++++++++-------- src/bin/pg_dump/pg_dump.h | 19 ++++------------ 3 files changed, 53 insertions(+), 43 deletions(-) diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c index 299943f485..9089062c58 100644 --- a/src/bin/pg_dump/common.c +++ b/src/bin/pg_dump/common.c @@ -7,7 +7,7 @@ * * * 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 * @@ -156,13 +156,12 @@ findParentsByOid(TableInfo *tblinfo, int numTables, } /* - * parseArgTypes - * parse a string of eight numbers delimited by spaces - * into a character array + * parseNumericArray + * parse a string of numbers delimited by spaces into a character array */ void -parseArgTypes(char **argtypes, const char *str) +parseNumericArray(const char *str, char **array, int arraysize) { int j, argNum; @@ -171,28 +170,37 @@ parseArgTypes(char **argtypes, const char *str) argNum = 0; j = 0; - while ((s = *str) != '\0') + for (;;) { - if (s == ' ') + s = *str++; + if (s == ' ' || s == '\0') { - temp[j] = '\0'; - argtypes[argNum] = strdup(temp); - argNum++; - j = 0; + if (j > 0) + { + if (argNum >= arraysize) + { + fprintf(stderr, "parseNumericArray: too many numbers\n"); + exit(2); + } + temp[j] = '\0'; + array[argNum++] = strdup(temp); + j = 0; + } + if (s == '\0') + break; } else { - temp[j] = s; - j++; + if (!isdigit(s) || j >= sizeof(temp)-1) + { + fprintf(stderr, "parseNumericArray: bogus number\n"); + exit(2); + } + temp[j++] = s; } - str++; } - if (j != 0) - { - temp[j] = '\0'; - argtypes[argNum] = strdup(temp); - } - + while (argNum < arraysize) + array[argNum++] = strdup("0"); } diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 60ed1e8704..c7bf1e3e94 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -21,7 +21,7 @@ * * * 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 * @@ -1387,6 +1387,8 @@ getFuncs(int *numFuncs) finfo = (FuncInfo *) malloc(ntups * sizeof(FuncInfo)); + memset((char *) finfo, 0, ntups * sizeof(FuncInfo)); + i_oid = PQfnumber(res, "oid"); i_proname = PQfnumber(res, "proname"); 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].nargs = atoi(PQgetvalue(res, i, i_pronargs)); finfo[i].lang = atoi(PQgetvalue(res, i, i_prolang)); - finfo[i].usename = strdup(PQgetvalue(res, i, i_usename)); - - parseArgTypes(finfo[i].argtypes, PQgetvalue(res, i, i_proargtypes)); - + if (finfo[i].nargs < 0 || finfo[i].nargs > FUNC_MAX_ARGS) + { + 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; } @@ -2045,6 +2052,8 @@ getIndices(int *numIndices) indinfo = (IndInfo *) malloc(ntups * sizeof(IndInfo)); + memset((char *) indinfo, 0, ntups * sizeof(IndInfo)); + i_indexrelname = PQfnumber(res, "indexrelname"); i_indrelname = PQfnumber(res, "indrelname"); i_indamname = PQfnumber(res, "indamname"); @@ -2059,10 +2068,12 @@ getIndices(int *numIndices) indinfo[i].indrelname = strdup(PQgetvalue(res, i, i_indrelname)); indinfo[i].indamname = strdup(PQgetvalue(res, i, i_indamname)); indinfo[i].indproc = strdup(PQgetvalue(res, i, i_indproc)); - parseArgTypes((char **) indinfo[i].indkey, - (const char *) PQgetvalue(res, i, i_indkey)); - parseArgTypes((char **) indinfo[i].indclass, - (const char *) PQgetvalue(res, i, i_indclass)); + parseNumericArray(PQgetvalue(res, i, i_indkey), + indinfo[i].indkey, + INDEX_MAX_KEYS); + parseNumericArray(PQgetvalue(res, i, i_indclass), + indinfo[i].indclass, + INDEX_MAX_KEYS); indinfo[i].indisunique = strdup(PQgetvalue(res, i, i_indisunique)); } PQclear(res); diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h index cd06288500..80c6e4928c 100644 --- a/src/bin/pg_dump/pg_dump.h +++ b/src/bin/pg_dump/pg_dump.h @@ -5,7 +5,7 @@ * * 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 * @@ -25,14 +25,7 @@ #include "pqexpbuffer.h" #include "catalog/pg_index.h" -/* - * 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 */ +/* The data structures used to store system catalog information */ typedef struct _typeInfo { @@ -61,11 +54,9 @@ typedef struct _funcInfo char *proowner; int lang; int nargs; - char *argtypes[FUNC_MAX_ARGS]; /* should be derived from obj/fmgr.h - * instead of hardwired */ + char *argtypes[FUNC_MAX_ARGS]; char *prorettype; - int retset; /* 1 if the function returns a set, 0 - * otherwise */ + int retset; /* 1 if the function returns a set, else 0 */ char *prosrc; char *probin; 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 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