Skip to content

Commit 847f8b3

Browse files
committed
Fix printf() quote handling and improper exit(), per Tom.
1 parent 9a9825f commit 847f8b3

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

src/bin/psql/input.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.20 2002/09/05 22:05:50 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.21 2002/09/06 02:33:46 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "input.h"
@@ -30,7 +30,7 @@ static void finishInput(void);
3030
static void finishInput(int, void *);
3131
#endif
3232

33-
#define PSQLHISTORY "/.psql_history"
33+
#define PSQLHISTORY ".psql_history"
3434

3535

3636
/*
@@ -144,12 +144,12 @@ initializeInput(int flags)
144144
home = getenv("HOME");
145145
if (home)
146146
{
147-
char *psql_history = (char *) malloc(strlen(home) +
147+
char *psql_history = (char *) malloc(strlen(home) + 1 +
148148
strlen(PSQLHISTORY) + 1);
149149

150150
if (psql_history)
151151
{
152-
sprintf(psql_history, "%s" PSQLHISTORY, home);
152+
sprintf(psql_history, "%s/%s", home, PSQLHISTORY);
153153
read_history(psql_history);
154154
free(psql_history);
155155
}
@@ -204,15 +204,15 @@ finishInput(int exitstatus, void *arg)
204204
home = getenv("HOME");
205205
if (home)
206206
{
207-
psql_history = (char *) malloc(strlen(home) +
207+
psql_history = (char *) malloc(strlen(home) + 1 +
208208
strlen(PSQLHISTORY) + 1);
209209
if (psql_history)
210210
{
211211
const char *var = GetVariable(pset.vars, "HISTSIZE");
212212

213213
if (var)
214214
stifle_history(atoi(var));
215-
sprintf(psql_history, "%s" PSQLHISTORY, home);
215+
sprintf(psql_history, "%s/%s", home, PSQLHISTORY);
216216
write_history(psql_history);
217217
free(psql_history);
218218
}

src/bin/psql/startup.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.65 2002/09/05 22:05:50 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.66 2002/09/06 02:33:47 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99

@@ -42,7 +42,7 @@
4242
*/
4343
PsqlSettings pset;
4444

45-
#define PSQLRC "/.psqlrc"
45+
#define PSQLRC ".psqlrc"
4646

4747
/*
4848
* Structures to pass information between the option parsing routine
@@ -605,20 +605,20 @@ process_psqlrc(void)
605605

606606
if (home)
607607
{
608-
psqlrc = malloc(strlen(home) + strlen(PSQLRC) + 1 +
608+
psqlrc = malloc(strlen(home) + 1 + strlen(PSQLRC) + 1 +
609609
strlen(PG_VERSION) + 1);
610610
if (!psqlrc)
611611
{
612612
fprintf(stderr, gettext("%s: out of memory\n"), pset.progname);
613613
exit(EXIT_FAILURE);
614614
}
615615

616-
sprintf(psqlrc, "%s" PSQLRC "-" PG_VERSION, home);
616+
sprintf(psqlrc, "%s/%s-%s", home, PSQLRC, PG_VERSION);
617617
if (access(psqlrc, R_OK) == 0)
618618
process_file(psqlrc);
619619
else
620620
{
621-
sprintf(psqlrc, "%s" PSQLRC, home);
621+
sprintf(psqlrc, "%s/%s", home, PSQLRC);
622622
if (access(psqlrc, R_OK) == 0)
623623
process_file(psqlrc);
624624
}

src/interfaces/libpq/fe-connect.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.203 2002/09/05 22:24:23 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.204 2002/09/06 02:33:47 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -66,7 +66,7 @@ inet_aton(const char *cp, struct in_addr * inp)
6666
#define NOTIFYLIST_INITIAL_SIZE 10
6767
#define NOTIFYLIST_GROWBY 10
6868

69-
#define PGPASSFILE "/.pgpass"
69+
#define PGPASSFILE ".pgpass"
7070

7171
/* ----------
7272
* Definition of the conninfo parameters and their fallback resources.
@@ -2927,18 +2927,17 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
29272927
home = getenv("HOME");
29282928
if (home)
29292929
{
2930-
pgpassfile = malloc(strlen(home) + strlen(PGPASSFILE) + 1);
2930+
pgpassfile = malloc(strlen(home) + 1 + strlen(PGPASSFILE) + 1);
29312931
if (!pgpassfile)
29322932
{
2933-
29342933
fprintf(stderr, libpq_gettext("out of memory\n"));
2935-
exit(EXIT_FAILURE);
2934+
return NULL;
29362935
}
29372936
}
29382937
else
29392938
return NULL;
29402939

2941-
sprintf(pgpassfile, "%s" PGPASSFILE, home);
2940+
sprintf(pgpassfile, "%s/%s", home, PGPASSFILE);
29422941

29432942
/* If password file cannot be opened, ignore it. */
29442943
if (stat(pgpassfile, &stat_buf) == -1)

0 commit comments

Comments
 (0)